2016-12-22 04:33:17 +08:00
|
|
|
#include "test/jemalloc_test.h"
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
for (binind = 0; binind < NBINS; binind++) {
|
|
|
|
size_t regind;
|
|
|
|
extent_t slab;
|
2017-10-02 08:22:06 +08:00
|
|
|
const bin_info_t *bin_info = &bin_infos[binind];
|
2016-12-22 04:33:17 +08:00
|
|
|
extent_init(&slab, NULL, mallocx(bin_info->slab_size,
|
2017-03-14 08:36:57 +08:00
|
|
|
MALLOCX_LG_ALIGN(LG_PAGE)), bin_info->slab_size, true,
|
2017-09-19 08:25:57 +08:00
|
|
|
binind, 0, extent_state_active, false, true, true);
|
2016-12-22 04:33:17 +08:00
|
|
|
assert_ptr_not_null(extent_addr_get(&slab),
|
|
|
|
"Unexpected malloc() failure");
|
|
|
|
for (regind = 0; regind < bin_info->nregs; regind++) {
|
|
|
|
void *reg = (void *)((uintptr_t)extent_addr_get(&slab) +
|
|
|
|
(bin_info->reg_size * regind));
|
|
|
|
assert_zu_eq(arena_slab_regind(&slab, binind, reg),
|
|
|
|
regind,
|
|
|
|
"Incorrect region index computed for size %zu",
|
|
|
|
bin_info->reg_size);
|
|
|
|
}
|
|
|
|
free(extent_addr_get(&slab));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|