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;
|
|
|
|
extent_t slab;
|
2017-10-02 08:22:06 +08:00
|
|
|
const bin_info_t *bin_info = &bin_infos[binind];
|
2019-09-21 09:20:22 +08:00
|
|
|
extent_init(&slab, INVALID_ARENA_IND,
|
|
|
|
mallocx(bin_info->slab_size, MALLOCX_LG_ALIGN(LG_PAGE)),
|
|
|
|
bin_info->slab_size, true,
|
2019-07-13 07:20:23 +08:00
|
|
|
binind, 0, extent_state_active, false, true, true,
|
|
|
|
EXTENT_NOT_HEAD);
|
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
|
|
|
}
|