• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 *
thd_start(void * arg)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 	assert_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 		assert_d_eq(mallctlnametomib("arena.0.dss", mib, &miblen), 0,
33 		    "Error in mallctlnametomib()");
34 		mib[1] = arena_ind;
35 		assert_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 	assert_ptr_not_null(p, "Unexpected mallocx() error");
42 	dallocx(p, 0);
43 
44 	return NULL;
45 }
46 
TEST_BEGIN(test_MALLOCX_ARENA)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
main(void)63 main(void) {
64 	return test(
65 	    test_MALLOCX_ARENA);
66 }
67