slab.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "test/jemalloc_test.h"
  2. #define INVALID_ARENA_IND ((1U << MALLOCX_ARENA_BITS) - 1)
  3. TEST_BEGIN(test_arena_slab_regind) {
  4. szind_t binind;
  5. for (binind = 0; binind < SC_NBINS; binind++) {
  6. size_t regind;
  7. edata_t slab;
  8. const bin_info_t *bin_info = &bin_infos[binind];
  9. edata_init(&slab, INVALID_ARENA_IND,
  10. mallocx(bin_info->slab_size, MALLOCX_LG_ALIGN(LG_PAGE)),
  11. bin_info->slab_size, true,
  12. binind, 0, extent_state_active, false, true, EXTENT_PAI_PAC,
  13. EXTENT_NOT_HEAD);
  14. expect_ptr_not_null(edata_addr_get(&slab),
  15. "Unexpected malloc() failure");
  16. arena_dalloc_bin_locked_info_t dalloc_info;
  17. arena_dalloc_bin_locked_begin(&dalloc_info, binind);
  18. for (regind = 0; regind < bin_info->nregs; regind++) {
  19. void *reg = (void *)((uintptr_t)edata_addr_get(&slab) +
  20. (bin_info->reg_size * regind));
  21. expect_zu_eq(arena_slab_regind(&dalloc_info, binind,
  22. &slab, reg),
  23. regind,
  24. "Incorrect region index computed for size %zu",
  25. bin_info->reg_size);
  26. }
  27. free(edata_addr_get(&slab));
  28. }
  29. }
  30. TEST_END
  31. int
  32. main(void) {
  33. return test(
  34. test_arena_slab_regind);
  35. }