1
2 #include "test/jemalloc_test.h"
3
4 static void *
thd_start(void * arg)5 thd_start(void *arg) {
6 bool e0, e1;
7 size_t sz = sizeof(bool);
8 assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz, NULL,
9 0), 0, "Unexpected mallctl failure");
10
11 if (e0) {
12 e1 = false;
13 assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
14 (void *)&e1, sz), 0, "Unexpected mallctl() error");
15 assert_true(e0, "tcache should be enabled");
16 }
17
18 e1 = true;
19 assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
20 (void *)&e1, sz), 0, "Unexpected mallctl() error");
21 assert_false(e0, "tcache should be disabled");
22
23 e1 = true;
24 assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
25 (void *)&e1, sz), 0, "Unexpected mallctl() error");
26 assert_true(e0, "tcache should be enabled");
27
28 e1 = false;
29 assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
30 (void *)&e1, sz), 0, "Unexpected mallctl() error");
31 assert_true(e0, "tcache should be enabled");
32
33 e1 = false;
34 assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
35 (void *)&e1, sz), 0, "Unexpected mallctl() error");
36 assert_false(e0, "tcache should be disabled");
37
38 free(malloc(1));
39 e1 = true;
40 assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
41 (void *)&e1, sz), 0, "Unexpected mallctl() error");
42 assert_false(e0, "tcache should be disabled");
43
44 free(malloc(1));
45 e1 = true;
46 assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
47 (void *)&e1, sz), 0, "Unexpected mallctl() error");
48 assert_true(e0, "tcache should be enabled");
49
50 free(malloc(1));
51 e1 = false;
52 assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
53 (void *)&e1, sz), 0, "Unexpected mallctl() error");
54 assert_true(e0, "tcache should be enabled");
55
56 free(malloc(1));
57 e1 = false;
58 assert_d_eq(mallctl("thread.tcache.enabled", (void *)&e0, &sz,
59 (void *)&e1, sz), 0, "Unexpected mallctl() error");
60 assert_false(e0, "tcache should be disabled");
61
62 free(malloc(1));
63 return NULL;
64 }
65
TEST_BEGIN(test_main_thread)66 TEST_BEGIN(test_main_thread) {
67 thd_start(NULL);
68 }
69 TEST_END
70
TEST_BEGIN(test_subthread)71 TEST_BEGIN(test_subthread) {
72 thd_t thd;
73
74 thd_create(&thd, thd_start, NULL);
75 thd_join(thd, NULL);
76 }
77 TEST_END
78
79 int
main(void)80 main(void) {
81 /* Run tests multiple times to check for bad interactions. */
82 return test(
83 test_main_thread,
84 test_subthread,
85 test_main_thread,
86 test_subthread,
87 test_main_thread);
88 }
89