tap-signal.tap 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #! /bin/sh
  2. # Copyright (C) 2011-2017 Free Software Foundation, Inc.
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2, or (at your option)
  7. # any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. # TAP support:
  17. # - a test script terminated by a signal causes an hard error
  18. . test-init.sh
  19. fetch_tap_driver
  20. plan_ 10
  21. cat >> configure.ac <<END
  22. AC_OUTPUT
  23. END
  24. cat > Makefile.am << END
  25. TEST_LOG_DRIVER = \$(srcdir)/tap-driver
  26. TEST_LOG_COMPILER = $PERL -w
  27. ## Will be updated later.
  28. TESTS =
  29. END
  30. all_signals='1 2 3 9 13 15'
  31. blocked_signals=''
  32. for sig in $all_signals; do
  33. # Ignore blocked signals
  34. if is_blocked_signal $sig; then
  35. blocked_signals="$blocked_signals $sig"
  36. continue
  37. fi
  38. # Write the dummy test scripts in perl, not as shell scripts, to work
  39. # around unportabilities in the handling of signals (in fact, even
  40. # with bash, the older script were unable to properly deliver a SIGQUIT
  41. # to themselves consistently). The shebang is dummy here, as we prefer
  42. # to rely on the definition of TEST_LOG_COMPILER instead.
  43. unindent > signal-$sig.test <<END
  44. #! /usr/bin/env perl
  45. # We need autoflush to avoid losing output, which could cause spurious
  46. # "no test plan seen" in the TAP driver.
  47. BEGIN { $| = 1 }
  48. use warnings FATAL => "all";
  49. print "1..1\\n";
  50. print "ok 1\\n";
  51. kill $sig, \$\$;
  52. print "Bail out! \$0 not killed?\\n";
  53. END
  54. echo TESTS += signal-$sig.test >> Makefile.am
  55. done
  56. results_count=$(ls *.test | wc -l | tr -d "$tab$sp")
  57. chmod a+x *.test
  58. $ACLOCAL
  59. $AUTOCONF
  60. $AUTOMAKE
  61. ./configure
  62. system=$(uname -s -r || echo unknown) # Needed later.
  63. signal_caught ()
  64. {
  65. numeric=$1
  66. case $numeric in
  67. 1) symbolic=HUP;;
  68. 2) symbolic=INT;;
  69. 3) symbolic=QUIT;;
  70. 9) symbolic=KILL;;
  71. 13) symbolic=PIPE;;
  72. 15) symbolic=TERM;;
  73. *) fatal_ "unexpected signal number '$numeric'"
  74. esac
  75. # Sending a SIGQUIT on Cygwin 1.5 can cause a segmentation fault
  76. # instead (sometimes). Don't let this older bug pollute the results
  77. # of our testsuite.
  78. case $numeric,$system in
  79. 3,CYGWIN*\ 1.5.*) sig_re="((SIG)?($symbolic|SEGV)|$numeric|11)";;
  80. *) sig_re="((SIG)?$symbolic|$numeric)";;
  81. esac
  82. wbound_re="($|[^a-zA-Z0-9_-])"
  83. pfx_re="^ERROR: signal-$numeric\\.test"
  84. rx="${pfx_re} .*terminated by signal ${sig_re}${wbound_re}"
  85. desc="TAP driver catch test termination by signal SIG${symbolic}"
  86. case " $blocked_signals " in
  87. *" $numeric "*) skip_ -r "SIG$symbolic is blocked" "$desc" ;;
  88. *) command_ok_ "$desc" env LC_ALL=C $EGREP "$rx" stdout ;;
  89. esac
  90. }
  91. command_ok_ '"make check" fails' eval '
  92. (
  93. run_make -e IGNORE -O check
  94. # Extra "echo" and silencing of xtraces required to avoid possible
  95. # garbled output with NetBSD make, which would miss some final
  96. # newlines in the expected places and thus mess up our TAP output.
  97. set +x; echo
  98. test $am_make_rc -gt 0
  99. )
  100. '
  101. cat stdout # For debugging.
  102. command_ok_ "count of test results" count_test_results \
  103. total=$(($results_count * 2)) \
  104. pass=$results_count error=$results_count \
  105. fail=0 xpass=0 xfail=0 skip=0
  106. for sig in $all_signals; do
  107. signal_caught $sig
  108. done
  109. echo 'TEST_LOG_DRIVER_FLAGS = --ignore-exit' >> Makefile
  110. command_ok_ '"make check" passes [--ignore-exit]' run_make -O check
  111. command_ok_ "count of test results [--ignore-exit]" count_test_results \
  112. total=$results_count pass=$results_count \
  113. fail=0 xpass=0 xfail=0 skip=0 error=0
  114. :