From ad5916c5e4d91fb4b31c91d34380db4cc90c3edc Mon Sep 17 00:00:00 2001 From: matt335672 <30179339+matt335672@users.noreply.github.com> Date: Mon, 9 Oct 2023 19:53:16 +0100 Subject: [PATCH] Check waitpid is not interrupted by a signal Checks that the waitpid() call isn't interrupted by a signal when the handler for the signal is set to not interrupt the call --- tests/common/test_os_calls_signals.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/common/test_os_calls_signals.c b/tests/common/test_os_calls_signals.c index 1f9745cb27..e917bfec16 100644 --- a/tests/common/test_os_calls_signals.c +++ b/tests/common/test_os_calls_signals.c @@ -231,6 +231,33 @@ START_TEST(test_g_signal_usr1) g_signal_usr1(NULL); } +/******************************************************************************/ +START_TEST(test_waitpid_not_interrupted_by_sig) +{ + /* Start a child which waits 3 seconds and exits */ + int child_pid = g_fork(); + if (child_pid == 0) + { + g_sleep(3000); + g_exit(42); + } + + /* Set an alarm for 1 second's time */ + g_reset_wait_obj(g_wobj1); + g_set_alarm(set_wobj1, 1); + + struct exit_status e = g_waitpid_status(child_pid); + // We should have had the alarm... + ck_assert_int_ne(g_is_wait_obj_set(g_wobj1), 0); + + // ..and got the status of the child + ck_assert_int_eq(e.reason, E_XR_STATUS_CODE); + ck_assert_int_eq(e.val, 42); + + // Clean up + g_set_alarm(NULL, 0); +} + /******************************************************************************/ TCase * make_tcase_test_os_calls_signals(void) @@ -246,6 +273,7 @@ make_tcase_test_os_calls_signals(void) tcase_add_test(tc, test_g_signal_terminate); tcase_add_test(tc, test_g_signal_pipe); tcase_add_test(tc, test_g_signal_usr1); + tcase_add_test(tc, test_waitpid_not_interrupted_by_sig); return tc; }