]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
tap driver: handle signals received by the tests being run
authorStefano Lattarini <stefano.lattarini@gmail.com>
Sat, 6 Aug 2011 19:41:37 +0000 (21:41 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Sat, 6 Aug 2011 19:41:37 +0000 (21:41 +0200)
* 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.

ChangeLog
doc/automake.texi
lib/tap-driver
tests/tap-signal.test

index 3ca507668d41917cf91c46044f195d98cdd37776..bd71052f879ca8ae9bbee99bca6f10e5cfbe8baf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2011-08-06  Stefano Lattarini  <stefano.lattarini@gmail.com>
+
+       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  <stefano.lattarini@gmail.com>
 
        test driver: a preparatory refactoring (2)
index c63742d3be1d32ce9b524f459cd25905552bc344..6be5c2d6c58cacab41db499f0d61eceee15338a0 100644 (file)
@@ -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
index c9dbe19ac960dc42e72299e4dfab33c40098fd68..1f5a271d1b475849bf6b2f5c466167942ffded99 100755 (executable)
@@ -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 ()
index fb75c83e4d4bca8b37005ce8d19b68a5dfa3dd13..ce75dddbf52c5fb5f8de5b3754eb313d4745f427 100755 (executable)
@@ -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
 
 :