2
0

slab.c 901 B

1234567891011121314151617181920212223242526272829303132
  1. #include "test/jemalloc_test.h"
  2. TEST_BEGIN(test_arena_slab_regind) {
  3. szind_t binind;
  4. for (binind = 0; binind < NBINS; binind++) {
  5. size_t regind;
  6. extent_t slab;
  7. const bin_info_t *bin_info = &bin_infos[binind];
  8. extent_init(&slab, NULL, mallocx(bin_info->slab_size,
  9. MALLOCX_LG_ALIGN(LG_PAGE)), bin_info->slab_size, true,
  10. binind, 0, extent_state_active, false, true, true);
  11. assert_ptr_not_null(extent_addr_get(&slab),
  12. "Unexpected malloc() failure");
  13. for (regind = 0; regind < bin_info->nregs; regind++) {
  14. void *reg = (void *)((uintptr_t)extent_addr_get(&slab) +
  15. (bin_info->reg_size * regind));
  16. assert_zu_eq(arena_slab_regind(&slab, binind, reg),
  17. regind,
  18. "Incorrect region index computed for size %zu",
  19. bin_info->reg_size);
  20. }
  21. free(extent_addr_get(&slab));
  22. }
  23. }
  24. TEST_END
  25. int
  26. main(void) {
  27. return test(
  28. test_arena_slab_regind);
  29. }