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