From: Stefano Lattarini Date: Sat, 6 Aug 2011 19:41:37 +0000 (+0200) Subject: tap driver: handle signals received by the tests being run X-Git-Tag: ng-0.5a~89^2~141^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7fa87264291f611fdc63bd4a49913f98ec5b944;p=thirdparty%2Fautomake.git tap driver: handle signals received by the tests being run * lib/tap-driver (get_test_exit_message): Also deal with signals, by using the `wait' method of the TAP::Parser object instead of the `exit' method. This required the use of the standard perl module `POSIX'. * doc/automake.texi (Use TAP with the Automake test harness): Document that `--ignore-exit' has effect also on terminating signals. Add a "synchronizing" comment that references the tests 'tap-exit.test' and 'tap-signal.test'. * tests/tap-signal.test: Extend and adjust. --- diff --git a/ChangeLog b/ChangeLog index 3ca507668..bd71052f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2011-08-06 Stefano Lattarini + + tap driver: handle signals received by the tests being run + * lib/tap-driver (get_test_exit_message): Also deal with signals, + by using the `wait' method of the TAP::Parser object instead of + the `exit' method. This required the use of the standard perl + module `POSIX'. + * doc/automake.texi (Use TAP with the Automake test harness): + Document that `--ignore-exit' has effect also on terminating + signals. Add a "synchronizing" comment that references the tests + 'tap-exit.test' and 'tap-signal.test'. + * tests/tap-signal.test: Extend and adjust. + 2011-08-06 Stefano Lattarini test driver: a preparatory refactoring (2) diff --git a/doc/automake.texi b/doc/automake.texi index c63742d3b..6be5c2d6c 100644 --- a/doc/automake.texi +++ b/doc/automake.texi @@ -9646,10 +9646,11 @@ supports the following options, whose names are chosen for enhanced compatibility with the @command{prove} utility. @table @option +@c Keep in sync with 'tap-exit.test' and 'tap-signal.test'. @item --ignore-exit Causes the test driver to ignore the exit status of the test scripts; by default, the driver will report an error if the script exit with a -non-zero status. +non-zero status. This option has effect also @item --comments Instruct the test driver to display TAP diagnostic (i.e., lines beginning with the @samp{#} character) in the testsuite progress output too; by diff --git a/lib/tap-driver b/lib/tap-driver index c9dbe19ac..1f5a271d1 100755 --- a/lib/tap-driver +++ b/lib/tap-driver @@ -236,11 +236,24 @@ sub get_test_exit_message () # Flush all the remaining TAP stream, so that we can obtain the # exit status of the TAP producer. do {} while defined get_tap_line (); - # TODO: we should probably use $parser->wait here, to catch signals too - if ($parser->exit != 0) - { - return sprintf "exited with status %d", $parser->exit; - } + my $wstatus = $parser->wait; + # Return an undefined value if the producer exited with success. + return unless $wstatus; + # Otherwise, determine whether it exited with error or was terminated + # by a signal. + use POSIX qw (WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG); + if (WIFEXITED ($wstatus)) + { + return sprintf "exited with status %d", WEXITSTATUS ($wstatus); + } + elsif (WIFSIGNALED ($wstatus)) + { + return sprintf "terminated by signal %d", WTERMSIG ($wstatus); + } + else + { + return "terminated abnormally"; + } } sub finish () diff --git a/tests/tap-signal.test b/tests/tap-signal.test index fb75c83e4..ce75dddbf 100755 --- a/tests/tap-signal.test +++ b/tests/tap-signal.test @@ -36,14 +36,32 @@ chmod a+x *.test . "$testsrcdir"/tap-setup.sh || fatal_ "sourcing tap-setup.sh" -for append in '' 'TEST_LOG_DRIVER_FLAGS = --ignore-exit'; do - echo "$append" >> Makefile - $MAKE check >stdout && { cat stdout; Exit 1; } - cat stdout - count_test_results total=8 pass=4 fail=0 xpass=0 xfail=0 skip=0 error=4 - for sig in 1 2 13 15; do - grep "^ERROR: signal-$sig\\.test - terminated by signal.*" stdout - done -done +signal_caught () +{ + numeric=$1 + symbolic=$2 + sig_re="((SIG)?$symbolic|$numeric)" + tst_re="signal-$numeric\\.test" + $EGREP "^ERROR: $tst_re - terminated by signal $sig_re$" stdout +} + +all_signals_caught () +{ + # This are the only signals that are portably trappable. + signal_caught 1 HUP + signal_caught 2 INT + signal_caught 13 PIPE + signal_caught 15 TERM +} + +$MAKE check >stdout && { cat stdout; Exit 1; } +cat stdout +count_test_results total=8 pass=4 fail=0 xpass=0 xfail=0 skip=0 error=4 +all_signals_caught + +echo 'TEST_LOG_DRIVER_FLAGS = --ignore-exit' >> Makefile +$MAKE check >stdout || { cat stdout; Exit 1; } +cat stdout +count_test_results total=4 pass=4 fail=0 xpass=0 xfail=0 skip=0 error=0 :