* tests/tap-signal.test: Renamed ... * tests/tap-signal.tap: ... to this, converted to the use of the TAP protocol, and improved not to try to use/trap signals that are ignored by the parent shell (they will be forcibly ignored by all the child processes too). Extend the test a bit since we are at it. * tests/list-of-tests.mk: Update. --- ChangeLog | 11 ++++ tests/Makefile.in | 6 +- tests/list-of-tests.mk | 2 +- tests/tap-signal.tap | 123 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/tap-signal.test | 92 ------------------------------------ 5 files changed, 138 insertions(+), 96 deletions(-) create mode 100755 tests/tap-signal.tap delete mode 100755 tests/tap-signal.test
diff --git a/ChangeLog b/ChangeLog index 4ba81aa..79879ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2011-09-07 Stefano Lattarini <stefano.lattar...@gmail.com> + tests: fix another spurious failure due to ignored signals + * tests/tap-signal.test: Renamed ... + * tests/tap-signal.tap: ... to this, converted to the use of the + TAP protocol, and improved not to try to use/trap signals that + are ignored by the parent shell (they will be forcibly ignored + by all the child processes too). Extend the test a bit since we + are at it. + * tests/list-of-tests.mk: Update. + +2011-09-07 Stefano Lattarini <stefano.lattar...@gmail.com> + tests: fix a spurious failure due to lacking Fortran compilers * tests/silent-many-generic.test (configure.in): Cause the test to be skipped if `configure' fails to find working C++, Fortran diff --git a/tests/Makefile.in b/tests/Makefile.in index b2df0e7..fd93782 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -1377,7 +1377,7 @@ tap-empty.test \ tap-escape-directive.test \ tap-escape-directive-2.test \ tap-exit.test \ -tap-signal.test \ +tap-signal.tap \ tap-fancy.test \ tap-fancy2.test \ tap-global-log.test \ @@ -1512,7 +1512,7 @@ wrap_TESTS = check-concurrency-bug9245-w.test_pt \ tap-planskip-whitespace-w.test_pltap tap-planskip-w.test_pltap \ tap-realtime-w.test_pltap tap-recheck-logs-w.test_pltap \ tap-recheck-w.test_pltap tap-result-comment-w.test_pltap \ - tap-signal-w.test_pltap tap-test-number-0-w.test_pltap \ + tap-signal-w.tap_pltap tap-test-number-0-w.test_pltap \ tap-todo-skip-together-w.test_pltap \ tap-todo-skip-whitespace-w.test_pltap \ tap-todo-skip-w.test_pltap tap-unplanned-w.test_pltap \ @@ -2142,7 +2142,7 @@ tap-realtime-w.log: tap-realtime.test tap-recheck-logs-w.log: tap-recheck-logs.test tap-recheck-w.log: tap-recheck.test tap-result-comment-w.log: tap-result-comment.test -tap-signal-w.log: tap-signal.test +tap-signal-w.log: tap-signal.tap tap-test-number-0-w.log: tap-test-number-0.test tap-todo-skip-together-w.log: tap-todo-skip-together.test tap-todo-skip-whitespace-w.log: tap-todo-skip-whitespace.test diff --git a/tests/list-of-tests.mk b/tests/list-of-tests.mk index 988b4f0..5e3fae0 100644 --- a/tests/list-of-tests.mk +++ b/tests/list-of-tests.mk @@ -1051,7 +1051,7 @@ tap-empty.test \ tap-escape-directive.test \ tap-escape-directive-2.test \ tap-exit.test \ -tap-signal.test \ +tap-signal.tap \ tap-fancy.test \ tap-fancy2.test \ tap-global-log.test \ diff --git a/tests/tap-signal.tap b/tests/tap-signal.tap new file mode 100755 index 0000000..31793d4 --- /dev/null +++ b/tests/tap-signal.tap @@ -0,0 +1,123 @@ +#! /bin/sh +# Copyright (C) 2011 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# TAP support: +# - a test script terminated by a signal causes an hard error + +parallel_tests=yes +. ./defs || Exit 1 + +plan_ 10 + +echo TESTS = > Makefile.am + +all_signals='1 2 3 9 13 15' +blocked_signals='' +for sig in $all_signals; do + # Ignore blocked signals + if is_blocked_signal $sig; then + blocked_signals="$blocked_signals $sig" + continue + fi + unindent > signal-$sig.test <<END + #!/bin/sh + echo 1..1 + echo ok 1 + kill -$sig \$\$ + echo "Bail out! \$0 not killed?" +END + echo TESTS += signal-$sig.test >> Makefile.am +done +results_count=`ls *.test | wc -l | tr -d "$tab$sp"` + +chmod a+x *.test + +. "$testsrcdir"/tap-setup.sh || fatal_ "sourcing tap-setup.sh" + +# Solaris /bin/sh, when killed with a SIGTERM, SIGQUIT or SIGINT signal, +# can end up exiting with exit status 208, instead of leaving the correct +# wide exit status to the parent. See: +# <http://dbaspot.com/shell/396118-bourne-shell-exit-code-term.html> +# We need to detect and work around this incompatibility. + +have_solaris_bug=no +for sig in 2 3 15; do + if /bin/sh -c "kill -$sig \$\$"; then + warn_ "/bin/sh cannot kill itself with signal $sig" + elif test $? -eq 208; then + warn_ "/bin/sh exits with status 208 upon some signals (Solaris?)" + warn_ "we will try to work around this bug" + have_solaris_bug=yes + break + fi +done + +signal_caught () +{ + numeric=$1 + case $numeric in + 1) symbolic=HUP;; + 2) symbolic=INT;; + 3) symbolic=QUIT;; + 9) symbolic=KILL;; + 13) symbolic=PIPE;; + 15) symbolic=TERM;; + *) fatal_ "unexpected signal number '$numeric'" + esac + sig_re="((SIG)?$symbolic|$numeric)" + wbound_re="($|[^a-zA-Z0-9_-])" + pfx_re="^ERROR: signal-$numeric\\.test" + case $am_tap_implementation in + perl) rx="$pfx_re - terminated by signal $sig_re$";; + shell) rx="$pfx_re .*terminated by signal $sig_re$wbound_re";; + *) fatal_ "invalid \$am_tap_implementation '$am_tap_implementation'";; + esac + directive='' reason='' + case $have_solaris_bug,$symbolic in + yes,INT|yes,TERM|yes,QUIT) directive=TODO reason="Solaris /bin/sh bug";; + esac + case " $blocked_signals " in + *" $numeric "*) + reason="SIG$symbolic is blocked" directive=SKIP result=ok;; + *) + LC_ALL=C $EGREP "$rx" stdout && result='ok' || result='not ok';; + esac + result_ "$result" -D "$directive" -r "$reason" \ + "TAP driver catch test termination by signal SIG$symbolic" +} + +command_ok_ '"make check" fails' eval 'not $MAKE check >stdout' +cat stdout # For debugging. + +command_ok_ "count of test results" count_test_results \ + total=`expr $results_count '*' 2` \ + pass=$results_count error=$results_count \ + fail=0 xpass=0 xfail=0 skip=0 + +for sig in $all_signals; do + signal_caught $sig +done + +echo 'TEST_LOG_DRIVER_FLAGS = --ignore-exit' >> Makefile + +command_ok_ '"make check" passes [--ignore-exit]' eval '$MAKE check >stdout' +cat stdout # For debugging. + +command_ok_ "count of test results [--ignore-exit]" count_test_results \ + total=$results_count pass=$results_count \ + fail=0 xpass=0 xfail=0 skip=0 error=0 + +: diff --git a/tests/tap-signal.test b/tests/tap-signal.test deleted file mode 100755 index 7821a2a..0000000 --- a/tests/tap-signal.test +++ /dev/null @@ -1,92 +0,0 @@ -#! /bin/sh -# Copyright (C) 2011 Free Software Foundation, Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -# TAP support: -# - a test script terminated by a signal causes an hard error - -parallel_tests=yes -. ./defs || Exit 1 - -echo TESTS = > Makefile.am -for sig in 1 2 13 15; do - unindent > signal-$sig.test <<END - #!/bin/sh - echo 1..1 - echo ok 1 - kill -$sig \$\$ - echo "Bail out! \$0 not killed?" -END - echo TESTS += signal-$sig.test >> Makefile.am -done - -chmod a+x *.test - -. "$testsrcdir"/tap-setup.sh || fatal_ "sourcing tap-setup.sh" - -# Solaris /bin/sh, when killed with a SIGTERM or SIGINT signal, can end up -# exiting with exit status 208, instead of leaving the correct wide exit -# status to the parent. See: -# <http://dbaspot.com/shell/396118-bourne-shell-exit-code-term.html> -# We need to detect and work around this incompatibility. - -if /bin/sh -c 'kill -2 $$'; then - fatal_ "/bin/sh cannot kill itself" -elif test $? -eq 208; then - have_solaris_bug=yes -else - have_solaris_bug=no -fi - -signal_caught () -{ - numeric=$1 - symbolic=$2 - sig_re="((SIG)?$symbolic|$numeric)" - wbound_re="($|[^a-zA-Z0-9_-])" - pfx_re="^ERROR: signal-$numeric\\.test" - case $am_tap_implementation in - perl) rx="$pfx_re - terminated by signal $sig_re$";; - shell) rx="$pfx_re .*terminated by signal $sig_re$wbound_re";; - *) fatal_ "invalid \$am_tap_implementation '$am_tap_implementation'";; - esac - LC_ALL=C $EGREP "$rx" stdout && return 0 - case $have_solaris_bug,$symbolic in - yes,INT|yes,TERM) - $EGREP "$pfx_re - exited with status 208( |$)" stdout && return 0;; - esac - return 1 -} - -all_signals_caught () -{ - # These 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 - -: -- 1.7.2.3