diff options
Diffstat (limited to 'examples/redis-unstable/deps/jemalloc/test/integration/MALLOCX_ARENA.c')
| -rw-r--r-- | examples/redis-unstable/deps/jemalloc/test/integration/MALLOCX_ARENA.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/examples/redis-unstable/deps/jemalloc/test/integration/MALLOCX_ARENA.c b/examples/redis-unstable/deps/jemalloc/test/integration/MALLOCX_ARENA.c new file mode 100644 index 0000000..7e61df0 --- /dev/null +++ b/examples/redis-unstable/deps/jemalloc/test/integration/MALLOCX_ARENA.c | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | #include "test/jemalloc_test.h" | ||
| 2 | |||
| 3 | #define NTHREADS 10 | ||
| 4 | |||
| 5 | static bool have_dss = | ||
| 6 | #ifdef JEMALLOC_DSS | ||
| 7 | true | ||
| 8 | #else | ||
| 9 | false | ||
| 10 | #endif | ||
| 11 | ; | ||
| 12 | |||
| 13 | void * | ||
| 14 | thd_start(void *arg) { | ||
| 15 | unsigned thread_ind = (unsigned)(uintptr_t)arg; | ||
| 16 | unsigned arena_ind; | ||
| 17 | void *p; | ||
| 18 | size_t sz; | ||
| 19 | |||
| 20 | sz = sizeof(arena_ind); | ||
| 21 | expect_d_eq(mallctl("arenas.create", (void *)&arena_ind, &sz, NULL, 0), | ||
| 22 | 0, "Error in arenas.create"); | ||
| 23 | |||
| 24 | if (thread_ind % 4 != 3) { | ||
| 25 | size_t mib[3]; | ||
| 26 | size_t miblen = sizeof(mib) / sizeof(size_t); | ||
| 27 | const char *dss_precs[] = {"disabled", "primary", "secondary"}; | ||
| 28 | unsigned prec_ind = thread_ind % | ||
| 29 | (sizeof(dss_precs)/sizeof(char*)); | ||
| 30 | const char *dss = dss_precs[prec_ind]; | ||
| 31 | int expected_err = (have_dss || prec_ind == 0) ? 0 : EFAULT; | ||
| 32 | expect_d_eq(mallctlnametomib("arena.0.dss", mib, &miblen), 0, | ||
| 33 | "Error in mallctlnametomib()"); | ||
| 34 | mib[1] = arena_ind; | ||
| 35 | expect_d_eq(mallctlbymib(mib, miblen, NULL, NULL, (void *)&dss, | ||
| 36 | sizeof(const char *)), expected_err, | ||
| 37 | "Error in mallctlbymib()"); | ||
| 38 | } | ||
| 39 | |||
| 40 | p = mallocx(1, MALLOCX_ARENA(arena_ind)); | ||
| 41 | expect_ptr_not_null(p, "Unexpected mallocx() error"); | ||
| 42 | dallocx(p, 0); | ||
| 43 | |||
| 44 | return NULL; | ||
| 45 | } | ||
| 46 | |||
| 47 | TEST_BEGIN(test_MALLOCX_ARENA) { | ||
| 48 | thd_t thds[NTHREADS]; | ||
| 49 | unsigned i; | ||
| 50 | |||
| 51 | for (i = 0; i < NTHREADS; i++) { | ||
| 52 | thd_create(&thds[i], thd_start, | ||
| 53 | (void *)(uintptr_t)i); | ||
| 54 | } | ||
| 55 | |||
| 56 | for (i = 0; i < NTHREADS; i++) { | ||
| 57 | thd_join(thds[i], NULL); | ||
| 58 | } | ||
| 59 | } | ||
| 60 | TEST_END | ||
| 61 | |||
| 62 | int | ||
| 63 | main(void) { | ||
| 64 | return test( | ||
| 65 | test_MALLOCX_ARENA); | ||
| 66 | } | ||
