summaryrefslogtreecommitdiff
path: root/examples/redis-unstable/deps/jemalloc/test/unit/slab.c
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2026-01-21 22:40:55 +0100
committerMitja Felicijan <mitja.felicijan@gmail.com>2026-01-21 22:40:55 +0100
commit5d8dfe892a2ea89f706ee140c3bdcfd89fe03fda (patch)
tree1acdfa5220cd13b7be43a2a01368e80d306473ca /examples/redis-unstable/deps/jemalloc/test/unit/slab.c
parentc7ab12bba64d9c20ccd79b132dac475f7bc3923e (diff)
downloadcrep-5d8dfe892a2ea89f706ee140c3bdcfd89fe03fda.tar.gz
Add Redis source code for testing
Diffstat (limited to 'examples/redis-unstable/deps/jemalloc/test/unit/slab.c')
-rw-r--r--examples/redis-unstable/deps/jemalloc/test/unit/slab.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/examples/redis-unstable/deps/jemalloc/test/unit/slab.c b/examples/redis-unstable/deps/jemalloc/test/unit/slab.c
new file mode 100644
index 0000000..70fc5c7
--- /dev/null
+++ b/examples/redis-unstable/deps/jemalloc/test/unit/slab.c
@@ -0,0 +1,39 @@
+#include "test/jemalloc_test.h"
+
+#define INVALID_ARENA_IND ((1U << MALLOCX_ARENA_BITS) - 1)
+
+TEST_BEGIN(test_arena_slab_regind) {
+ szind_t binind;
+
+ for (binind = 0; binind < SC_NBINS; binind++) {
+ size_t regind;
+ edata_t slab;
+ const bin_info_t *bin_info = &bin_infos[binind];
+ edata_init(&slab, INVALID_ARENA_IND,
+ mallocx(bin_info->slab_size, MALLOCX_LG_ALIGN(LG_PAGE)),
+ bin_info->slab_size, true,
+ binind, 0, extent_state_active, false, true, EXTENT_PAI_PAC,
+ EXTENT_NOT_HEAD);
+ expect_ptr_not_null(edata_addr_get(&slab),
+ "Unexpected malloc() failure");
+ arena_dalloc_bin_locked_info_t dalloc_info;
+ arena_dalloc_bin_locked_begin(&dalloc_info, binind);
+ for (regind = 0; regind < bin_info->nregs; regind++) {
+ void *reg = (void *)((uintptr_t)edata_addr_get(&slab) +
+ (bin_info->reg_size * regind));
+ expect_zu_eq(arena_slab_regind(&dalloc_info, binind,
+ &slab, reg),
+ regind,
+ "Incorrect region index computed for size %zu",
+ bin_info->reg_size);
+ }
+ free(edata_addr_get(&slab));
+ }
+}
+TEST_END
+
+int
+main(void) {
+ return test(
+ test_arena_slab_regind);
+}