From: Jan Janssen Date: Thu, 25 Nov 2021 11:27:42 +0000 (+0100) Subject: test-barrier: Convert to TEST macro X-Git-Tag: v250-rc1~105^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=353b98020420946549569bd3c6876bf8f0773c2b;p=thirdparty%2Fsystemd.git test-barrier: Convert to TEST macro --- diff --git a/src/test/test-barrier.c b/src/test/test-barrier.c index 6ef2998a565..8998282afb0 100644 --- a/src/test/test-barrier.c +++ b/src/test/test-barrier.c @@ -40,7 +40,7 @@ static void sleep_for(usec_t usecs) { } #define TEST_BARRIER(_FUNCTION, _CHILD_CODE, _WAIT_CHILD, _PARENT_CODE, _WAIT_PARENT) \ - static void _FUNCTION(void) { \ + TEST(_FUNCTION) { \ Barrier b = BARRIER_NULL; \ pid_t pid1, pid2; \ \ @@ -100,7 +100,7 @@ static void sleep_for(usec_t usecs) { * pending HUP on the pipe. However, the barrier_sync() prefers reads on the * eventfd, thus we can safely wait on the barrier. */ -TEST_BARRIER(test_barrier_sync, +TEST_BARRIER(barrier_sync, ({ set_alarm(BASE_TIME * 10); assert_se(barrier_place(&b)); @@ -122,7 +122,7 @@ TEST_BARRIER(test_barrier_sync, * succeed as the child hasn't read the parent's barrier, yet. The following * barrier and sync synchronize the exit. */ -TEST_BARRIER(test_barrier_wait_next, +TEST_BARRIER(barrier_wait_next, ({ sleep_for(BASE_TIME); set_alarm(BASE_TIME * 10); @@ -148,7 +148,7 @@ TEST_BARRIER(test_barrier_wait_next, * not look at barrier-links so this stall is expected. Thus this test times * out. */ -TEST_BARRIER(test_barrier_wait_next_twice, +TEST_BARRIER(barrier_wait_next_twice, ({ sleep_for(BASE_TIME); set_alarm(BASE_TIME); @@ -171,7 +171,7 @@ TEST_BARRIER(test_barrier_wait_next_twice, * between both waits. This does not have any effect on the wait so it times out * like the other test. */ -TEST_BARRIER(test_barrier_wait_next_twice_local, +TEST_BARRIER(barrier_wait_next_twice_local, ({ sleep_for(BASE_TIME); set_alarm(BASE_TIME); @@ -196,7 +196,7 @@ TEST_BARRIER(test_barrier_wait_next_twice_local, * synced wait as the second wait. This works just fine because the local state * has no barriers placed, therefore, the remote is always in sync. */ -TEST_BARRIER(test_barrier_wait_next_twice_sync, +TEST_BARRIER(barrier_wait_next_twice_sync, ({ sleep_for(BASE_TIME); set_alarm(BASE_TIME); @@ -217,7 +217,7 @@ TEST_BARRIER(test_barrier_wait_next_twice_sync, * synced wait as the second wait. This works just fine because the local state * is in sync with the remote. */ -TEST_BARRIER(test_barrier_wait_next_twice_local_sync, +TEST_BARRIER(barrier_wait_next_twice_local_sync, ({ sleep_for(BASE_TIME); set_alarm(BASE_TIME); @@ -239,7 +239,7 @@ TEST_BARRIER(test_barrier_wait_next_twice_local_sync, * This tests sync_*() synchronizations and makes sure they work fine if the * local state is behind the remote state. */ -TEST_BARRIER(test_barrier_sync_next, +TEST_BARRIER(barrier_sync_next, ({ set_alarm(BASE_TIME * 10); assert_se(barrier_sync_next(&b)); @@ -265,7 +265,7 @@ TEST_BARRIER(test_barrier_sync_next, * This tests timeouts if sync_*() is used if local barriers are placed but the * remote didn't place any. */ -TEST_BARRIER(test_barrier_sync_next_local, +TEST_BARRIER(barrier_sync_next_local, ({ set_alarm(BASE_TIME); assert_se(barrier_place(&b)); @@ -283,7 +283,7 @@ TEST_BARRIER(test_barrier_sync_next_local, * This is the same as test_barrier_sync_next_local but aborts the sync in the * parent. Therefore, the sync_next() succeeds just fine due to the abortion. */ -TEST_BARRIER(test_barrier_sync_next_local_abort, +TEST_BARRIER(barrier_sync_next_local_abort, ({ set_alarm(BASE_TIME * 10); assert_se(barrier_place(&b)); @@ -299,7 +299,7 @@ TEST_BARRIER(test_barrier_sync_next_local_abort, * Test matched wait_abortion() * This runs wait_abortion() with remote abortion. */ -TEST_BARRIER(test_barrier_wait_abortion, +TEST_BARRIER(barrier_wait_abortion, ({ set_alarm(BASE_TIME * 10); assert_se(barrier_wait_abortion(&b)); @@ -315,7 +315,7 @@ TEST_BARRIER(test_barrier_wait_abortion, * This runs wait_abortion() without any remote abortion going on. It thus must * timeout. */ -TEST_BARRIER(test_barrier_wait_abortion_unmatched, +TEST_BARRIER(barrier_wait_abortion_unmatched, ({ set_alarm(BASE_TIME); assert_se(barrier_wait_abortion(&b)); @@ -331,7 +331,7 @@ TEST_BARRIER(test_barrier_wait_abortion_unmatched, * Test matched wait_abortion() with local abortion * This runs wait_abortion() with local and remote abortion. */ -TEST_BARRIER(test_barrier_wait_abortion_local, +TEST_BARRIER(barrier_wait_abortion_local, ({ set_alarm(BASE_TIME * 10); assert_se(barrier_abort(&b)); @@ -347,7 +347,7 @@ TEST_BARRIER(test_barrier_wait_abortion_local, * Test unmatched wait_abortion() with local abortion * This runs wait_abortion() with only local abortion. This must time out. */ -TEST_BARRIER(test_barrier_wait_abortion_local_unmatched, +TEST_BARRIER(barrier_wait_abortion_local_unmatched, ({ set_alarm(BASE_TIME); assert_se(barrier_abort(&b)); @@ -365,7 +365,7 @@ TEST_BARRIER(test_barrier_wait_abortion_local_unmatched, * Place barrier and sync with the child. The child only exits()s, which should * cause an implicit abortion and wake the parent. */ -TEST_BARRIER(test_barrier_exit, +TEST_BARRIER(barrier_exit, ({ }), TEST_BARRIER_WAIT_SUCCESS(pid1), @@ -382,7 +382,7 @@ TEST_BARRIER(test_barrier_exit, * child-exit. We add a usleep() which triggers the alarm in the parent and * causes the test to time out. */ -TEST_BARRIER(test_barrier_no_exit, +TEST_BARRIER(barrier_no_exit, ({ sleep_for(BASE_TIME * 2); }), @@ -404,7 +404,7 @@ TEST_BARRIER(test_barrier_no_exit, * succeeds. Only if we place one more barrier, we're ahead of the remote, thus * we will fail due to HUP on the pipe. */ -TEST_BARRIER(test_barrier_pending_exit, +TEST_BARRIER(barrier_pending_exit, ({ set_alarm(BASE_TIME * 4); sleep_for(BASE_TIME * 2); @@ -421,44 +421,25 @@ TEST_BARRIER(test_barrier_pending_exit, }), TEST_BARRIER_WAIT_SUCCESS(pid2)); -int main(int argc, char *argv[]) { - int v; - test_setup_logging(LOG_INFO); - - if (!slow_tests_enabled()) - return log_tests_skipped("slow tests are disabled"); - - /* - * This test uses real-time alarms and sleeps to test for CPU races - * explicitly. This is highly fragile if your system is under load. We - * already increased the BASE_TIME value to make the tests more robust, - * but that just makes the test take significantly longer. Given the recent - * issues when running the test in a virtualized environments, limit it - * to bare metal machines only, to minimize false-positives in CIs. - */ - v = detect_virtualization(); - if (IN_SET(v, -EPERM, -EACCES)) - return log_tests_skipped("Cannot detect virtualization"); - - if (v != VIRTUALIZATION_NONE) - return log_tests_skipped("This test requires a baremetal machine"); +DEFINE_CUSTOM_TEST_MAIN( + LOG_INFO, + ({ + if (!slow_tests_enabled()) + return log_tests_skipped("slow tests are disabled"); - test_barrier_sync(); - test_barrier_wait_next(); - test_barrier_wait_next_twice(); - test_barrier_wait_next_twice_sync(); - test_barrier_wait_next_twice_local(); - test_barrier_wait_next_twice_local_sync(); - test_barrier_sync_next(); - test_barrier_sync_next_local(); - test_barrier_sync_next_local_abort(); - test_barrier_wait_abortion(); - test_barrier_wait_abortion_unmatched(); - test_barrier_wait_abortion_local(); - test_barrier_wait_abortion_local_unmatched(); - test_barrier_exit(); - test_barrier_no_exit(); - test_barrier_pending_exit(); + /* + * This test uses real-time alarms and sleeps to test for CPU races + * explicitly. This is highly fragile if your system is under load. We + * already increased the BASE_TIME value to make the tests more robust, + * but that just makes the test take significantly longer. Given the recent + * issues when running the test in a virtualized environments, limit it + * to bare metal machines only, to minimize false-positives in CIs. + */ + int v = detect_virtualization(); + if (IN_SET(v, -EPERM, -EACCES)) + return log_tests_skipped("Cannot detect virtualization"); - return 0; -} + if (v != VIRTUALIZATION_NONE) + return log_tests_skipped("This test requires a baremetal machine"); + }), + /* no outro */);