MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / TEST_BEGIN

Function TEST_BEGIN

deps/jemalloc/test/unit/background_thread.c:71–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69 }
70}
71TEST_END
72
73TEST_BEGIN(test_background_thread_running) {
74 test_skip_if(!have_background_thread);
75 test_skip_if(!config_stats);
76
77#if defined(JEMALLOC_BACKGROUND_THREAD)
78 tsd_t *tsd = tsd_fetch();
79 background_thread_info_t *info = &background_thread_info[0];
80
81 test_repeat_background_thread_ctl(false);
82 test_switch_background_thread_ctl(true);
83 assert_b_eq(info->state, background_thread_started,
84 "Background_thread did not start.\n");
85
86 nstime_t start, now;
87 nstime_init(&start, 0);
88 nstime_update(&start);
89
90 bool ran = false;
91 while (true) {
92 malloc_mutex_lock(tsd_tsdn(tsd), &info->mtx);
93 if (info->tot_n_runs > 0) {
94 ran = true;
95 }
96 malloc_mutex_unlock(tsd_tsdn(tsd), &info->mtx);
97 if (ran) {
98 break;
99 }
100
101 nstime_init(&now, 0);
102 nstime_update(&now);
103 nstime_subtract(&now, &start);
104 assert_u64_lt(nstime_sec(&now), 1000,
105 "Background threads did not run for 1000 seconds.");
106 sleep(1);
107 }
108 test_switch_background_thread_ctl(false);
109#endif
110}
111TEST_END
112
113int

Callers

nothing calls this directly

Calls 9

tsd_fetchFunction · 0.50
nstime_initFunction · 0.50
malloc_mutex_lockFunction · 0.50
tsd_tsdnFunction · 0.50
malloc_mutex_unlockFunction · 0.50
nstime_subtractFunction · 0.50
nstime_secFunction · 0.50

Tested by

no test coverage detected