diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 22:40:55 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 22:40:55 +0100 |
| commit | 5d8dfe892a2ea89f706ee140c3bdcfd89fe03fda (patch) | |
| tree | 1acdfa5220cd13b7be43a2a01368e80d306473ca /examples/redis-unstable/deps/jemalloc/test/unit/sz.c | |
| parent | c7ab12bba64d9c20ccd79b132dac475f7bc3923e (diff) | |
| download | crep-5d8dfe892a2ea89f706ee140c3bdcfd89fe03fda.tar.gz | |
Add Redis source code for testing
Diffstat (limited to 'examples/redis-unstable/deps/jemalloc/test/unit/sz.c')
| -rw-r--r-- | examples/redis-unstable/deps/jemalloc/test/unit/sz.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/examples/redis-unstable/deps/jemalloc/test/unit/sz.c b/examples/redis-unstable/deps/jemalloc/test/unit/sz.c new file mode 100644 index 0000000..8ae04b9 --- /dev/null +++ b/examples/redis-unstable/deps/jemalloc/test/unit/sz.c | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | #include "test/jemalloc_test.h" | ||
| 2 | |||
| 3 | TEST_BEGIN(test_sz_psz2ind) { | ||
| 4 | /* | ||
| 5 | * Testing page size classes which reside prior to the regular group | ||
| 6 | * with all size classes divisible by page size. | ||
| 7 | * For x86_64 Linux, it's 4096, 8192, 12288, 16384, with corresponding | ||
| 8 | * pszind 0, 1, 2 and 3. | ||
| 9 | */ | ||
| 10 | for (size_t i = 0; i < SC_NGROUP; i++) { | ||
| 11 | for (size_t psz = i * PAGE + 1; psz <= (i + 1) * PAGE; psz++) { | ||
| 12 | pszind_t ind = sz_psz2ind(psz); | ||
| 13 | expect_zu_eq(ind, i, "Got %u as sz_psz2ind of %zu", ind, | ||
| 14 | psz); | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | sc_data_t data; | ||
| 19 | memset(&data, 0, sizeof(data)); | ||
| 20 | sc_data_init(&data); | ||
| 21 | /* | ||
| 22 | * 'base' is the base of the first regular group with all size classes | ||
| 23 | * divisible by page size. | ||
| 24 | * For x86_64 Linux, it's 16384, and base_ind is 36. | ||
| 25 | */ | ||
| 26 | size_t base_psz = 1 << (SC_LG_NGROUP + LG_PAGE); | ||
| 27 | size_t base_ind = 0; | ||
| 28 | while (base_ind < SC_NSIZES && | ||
| 29 | reg_size_compute(data.sc[base_ind].lg_base, | ||
| 30 | data.sc[base_ind].lg_delta, | ||
| 31 | data.sc[base_ind].ndelta) < base_psz) { | ||
| 32 | base_ind++; | ||
| 33 | } | ||
| 34 | expect_zu_eq( | ||
| 35 | reg_size_compute(data.sc[base_ind].lg_base, | ||
| 36 | data.sc[base_ind].lg_delta, data.sc[base_ind].ndelta), | ||
| 37 | base_psz, "Size class equal to %zu not found", base_psz); | ||
| 38 | /* | ||
| 39 | * Test different sizes falling into groups after the 'base'. The | ||
| 40 | * increment is PAGE / 3 for the execution speed purpose. | ||
| 41 | */ | ||
| 42 | base_ind -= SC_NGROUP; | ||
| 43 | for (size_t psz = base_psz; psz <= 64 * 1024 * 1024; psz += PAGE / 3) { | ||
| 44 | pszind_t ind = sz_psz2ind(psz); | ||
| 45 | sc_t gt_sc = data.sc[ind + base_ind]; | ||
| 46 | expect_zu_gt(psz, | ||
| 47 | reg_size_compute(gt_sc.lg_base, gt_sc.lg_delta, | ||
| 48 | gt_sc.ndelta), | ||
| 49 | "Got %u as sz_psz2ind of %zu", ind, psz); | ||
| 50 | sc_t le_sc = data.sc[ind + base_ind + 1]; | ||
| 51 | expect_zu_le(psz, | ||
| 52 | reg_size_compute(le_sc.lg_base, le_sc.lg_delta, | ||
| 53 | le_sc.ndelta), | ||
| 54 | "Got %u as sz_psz2ind of %zu", ind, psz); | ||
| 55 | } | ||
| 56 | |||
| 57 | pszind_t max_ind = sz_psz2ind(SC_LARGE_MAXCLASS + 1); | ||
| 58 | expect_lu_eq(max_ind, SC_NPSIZES, | ||
| 59 | "Got %u as sz_psz2ind of %llu", max_ind, SC_LARGE_MAXCLASS); | ||
| 60 | } | ||
| 61 | TEST_END | ||
| 62 | |||
| 63 | int | ||
| 64 | main(void) { | ||
| 65 | return test(test_sz_psz2ind); | ||
| 66 | } | ||
