From cb0688c850ea95d5f57136cf5209f0a2bb5213ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Nogueira?= Date: Fri, 20 Sep 2024 10:26:23 -0300 Subject: [PATCH] Check if test was killed by signal in makeTestFile. Tests killed by a signal should cause the .t script to exit with an error code, otherwise its exit code will be 0, and the test harness won't be aware of the unsuccessful exit. This change also makes the test runner more robust, so attaching to a running test (e.g. with gdb or strace) won't cause the .t script to exit. --- src/tools/makeTestfile.pl | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/tools/makeTestfile.pl b/src/tools/makeTestfile.pl index 31c64bd66..22d4fad10 100644 --- a/src/tools/makeTestfile.pl +++ b/src/tools/makeTestfile.pl @@ -140,6 +140,8 @@ else { ######################################## Code for Unix run-hosts print $OUT <<__UNIX__; +use POSIX qw(WIFEXITED WIFSIGNALED WEXITSTATUS); + my \$pid = fork(); die "\$tool: Can't fork for '$error': \$!\\n" unless defined \$pid; @@ -154,9 +156,19 @@ if (\$pid) { }; alarm \$timeout; - waitpid \$pid, 0; - alarm 0; - exit \$? >> 8; + while (1) { + waitpid \$pid, 0; + if (WIFEXITED(\$?)) { + # normal exit + alarm 0; + exit WEXITSTATUS(\$?); + } elsif (WIFSIGNALED(\$?)) { + # terminated by signal + alarm 0; + die "\$tool: Test was terminated by signal '\$?'\\n"; + } + # non-terminal change of status, continue waiting + } } else { # Child process