}
#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; \
\
* 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));
* 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);
* 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);
* 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);
* 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);
* 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);
* 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));
* 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));
* 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));
* 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));
* 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));
* 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));
* 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));
* 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),
* 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);
}),
* 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);
}),
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 */);