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 {
16 	unsigned thread_ind = (unsigned)(uintptr_t)arg;
17 	unsigned arena_ind;
18 	void *p;
19 	size_t sz;
20 
21 	sz = sizeof(arena_ind);
22 	assert_d_eq(mallctl("arenas.extend", (void *)&arena_ind, &sz, NULL, 0),
23 	    0, "Error in arenas.extend");
24 
25 	if (thread_ind % 4 != 3) {
26 		size_t mib[3];
27 		size_t miblen = sizeof(mib) / sizeof(size_t);
28 		const char *dss_precs[] = {"disabled", "primary", "secondary"};
29 		unsigned prec_ind = thread_ind %
30 		    (sizeof(dss_precs)/sizeof(char*));
31 		const char *dss = dss_precs[prec_ind];
32 		int expected_err = (have_dss || prec_ind == 0) ? 0 : EFAULT;
33 		assert_d_eq(mallctlnametomib("arena.0.dss", mib, &miblen), 0,
34 		    "Error in mallctlnametomib()");
35 		mib[1] = arena_ind;
36 		assert_d_eq(mallctlbymib(mib, miblen, NULL, NULL, (void *)&dss,
37 		    sizeof(const char *)), expected_err,
38 		    "Error in mallctlbymib()");
39 	}
40 
41 	p = mallocx(1, MALLOCX_ARENA(arena_ind));
42 	assert_ptr_not_null(p, "Unexpected mallocx() error");
43 	dallocx(p, 0);
44 
45 	return (NULL);
46 }
47 
TEST_BEGIN(test_MALLOCX_ARENA)48 TEST_BEGIN(test_MALLOCX_ARENA)
49 {
50 	thd_t thds[NTHREADS];
51 	unsigned i;
52 
53 	for (i = 0; i < NTHREADS; i++) {
54 		thd_create(&thds[i], thd_start,
55 		    (void *)(uintptr_t)i);
56 	}
57 
58 	for (i = 0; i < NTHREADS; i++)
59 		thd_join(thds[i], NULL);
60 }
61 TEST_END
62 
63 int
main(void)64 main(void)
65 {
66 
67 	return (test(
68 	    test_MALLOCX_ARENA));
69 }
70