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