From 6df6465884e5192d8512b952fb412f2ea80439b0 Mon Sep 17 00:00:00 2001 From: Alice Frosi Date: Thu, 16 Feb 2023 08:53:15 +0100 Subject: test: interrupt test on target process exit Catch if the target process has exited due to an error and interrupt the tests. Signed-off-by: Alice Frosi --- tests/unit/test_actions.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests') diff --git a/tests/unit/test_actions.c b/tests/unit/test_actions.c index 08799ef..756c4cd 100644 --- a/tests/unit/test_actions.c +++ b/tests/unit/test_actions.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -125,10 +126,22 @@ static void check_target_result(long ret, int err) ck_assert_int_eq(close(pipefd[0]), 0); } +void target_exit() +{ + int status; + + waitpid(-1, &status, WUNTRACED | WNOHANG); + if (WEXITSTATUS(status) != 0) { + fprintf(stderr, "target process exited with an error\n"); + exit(-1); + } +} + void setup() { int ret; + signal (SIGCHLD, target_exit); ck_assert_int_ne(pipe(pipefd), -1); at = mmap(NULL, sizeof(struct args_target), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); -- cgit v1.2.3