2016-12-22 04:33:17 +08:00
|
|
|
#include "test/jemalloc_test.h"
|
|
|
|
|
2019-09-21 09:20:22 +08:00
|
|
|
#define INVALID_ARENA_IND ((1U << MALLOCX_ARENA_BITS) - 1)
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_arena_slab_regind) {
|
2016-12-22 04:33:17 +08:00
|
|
|
szind_t binind;
|
|
|
|
|
2017-12-15 04:46:39 +08:00
|
|
|
for (binind = 0; binind < SC_NBINS; binind++) {
|
2016-12-22 04:33:17 +08:00
|
|
|
size_t regind;
|
2019-12-10 06:36:45 +08:00
|
|
|
edata_t slab;
|
2017-10-02 08:22:06 +08:00
|
|
|
const bin_info_t *bin_info = &bin_infos[binind];
|
2019-12-10 06:36:45 +08:00
|
|
|
edata_init(&slab, INVALID_ARENA_IND,
|
2019-09-21 09:20:22 +08:00
|
|
|
mallocx(bin_info->slab_size, MALLOCX_LG_ALIGN(LG_PAGE)),
|
|
|
|
bin_info->slab_size, true,
|
2020-07-10 09:07:17 +08:00
|
|
|
binind, 0, extent_state_active, false, true, EXTENT_PAI_PAC,
|
2019-07-13 07:20:23 +08:00
|
|
|
EXTENT_NOT_HEAD);
|
2020-02-19 06:39:06 +08:00
|
|
|
expect_ptr_not_null(edata_addr_get(&slab),
|
2016-12-22 04:33:17 +08:00
|
|
|
"Unexpected malloc() failure");
|
2021-01-30 08:06:28 +08:00
|
|
|
arena_dalloc_bin_locked_info_t dalloc_info;
|
|
|
|
arena_dalloc_bin_locked_begin(&dalloc_info, binind);
|
2016-12-22 04:33:17 +08:00
|
|
|
for (regind = 0; regind < bin_info->nregs; regind++) {
|
2019-12-10 06:36:45 +08:00
|
|
|
void *reg = (void *)((uintptr_t)edata_addr_get(&slab) +
|
2016-12-22 04:33:17 +08:00
|
|
|
(bin_info->reg_size * regind));
|
2021-01-30 08:06:28 +08:00
|
|
|
expect_zu_eq(arena_slab_regind(&dalloc_info, binind,
|
|
|
|
&slab, reg),
|
2016-12-22 04:33:17 +08:00
|
|
|
regind,
|
|
|
|
"Incorrect region index computed for size %zu",
|
|
|
|
bin_info->reg_size);
|
|
|
|
}
|
2019-12-10 06:36:45 +08:00
|
|
|
free(edata_addr_get(&slab));
|
2016-12-22 04:33:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
|
|
|
int
|
2017-01-16 08:56:30 +08:00
|
|
|
main(void) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return test(
|
|
|
|
test_arena_slab_regind);
|
2016-12-22 04:33:17 +08:00
|
|
|
}
|