parallel-tests-interrupt.tap 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. # Check that the parallel testsuite harness removes incomplete log files
  17. # when interrupt upon some signal. This test is definitely too hacky,
  18. # but we couldn't find a better way to deal with inter-processes
  19. # signals and the whole process-synchronization mess.
  20. . test-init.sh
  21. plan_ 16
  22. cat >> configure.ac << 'END'
  23. AC_OUTPUT
  24. END
  25. cat > Makefile.am << 'END'
  26. TESTS = foo.test
  27. ## Provide more debugging info.
  28. TEST_LOG_COMPILER = $(SHELL) -ex
  29. ## Required by foo.test; see below.
  30. AM_TESTS_FD_REDIRECT = 9>&1
  31. END
  32. # This is hacky and ugly, but has the great advantage of avoiding us a lot
  33. # of pain with background processes and related synchronization issues.
  34. cat - "$am_scriptdir"/test-driver > test-driver <<'END'
  35. #!/bin/sh
  36. echo $$ > pid
  37. END
  38. cat > foo.test << 'END'
  39. #!/bin/sh -e
  40. # We expect the test driver to be terminated by a signal, and so
  41. # to exit with non-zero status, thus causing "make check" to fail.
  42. # Exiting with status 0 from this test script is thus a good way to
  43. # make unexpected behaviours more evident, since this will likely
  44. # cause and unexpected success in "make check".
  45. trap 'exit 0' 0;
  46. stop_test () { exit 0; }
  47. # We need the "foo is starting to run" string flushed to standard output
  48. # ASAP, because we are soon going to grep for that string in the log file
  49. # where the test driver is redirecting this script's stdout. The safest
  50. # way force this flushing portably is to rely on perl I/O capabilities.
  51. $PERL -e 'BEGIN { $| = 1 }; print "foo is starting to run\n"' || stop_test
  52. ls -l >&9 || stop_test
  53. bailout ()
  54. {
  55. # Print this to the original stdout (saved in the fd 9), so that the
  56. # emitted "Bail out!" directive will be interpreted by the test driver
  57. # running the Automake testsuite.
  58. echo "Bail out! $*" >&9
  59. stop_test
  60. }
  61. test $sig -gt 0 || bailout "\$sig not exported to test script"
  62. res=ok; cat foo.log >&9 || res="not ok"
  63. echo "$res - logfile created and readable [SIG $sig]" >&9
  64. res=ok; grep '^foo is starting to run$' foo.log >&9 || res='not ok'
  65. echo "$res - logfile contains output from test script [SIG $sig]" >&9
  66. cat pid >&9 || bailout "cannot get PID of test driver"
  67. kill -$sig `cat pid` || bailout "cannot send signal $sig to test driver"
  68. stop_test
  69. END
  70. chmod a+x foo.test
  71. $ACLOCAL || fatal_ "aclocal failed"
  72. $AUTOCONF || fatal_ "autoconf failed"
  73. $AUTOMAKE || fatal_ "automake failed"
  74. ./configure || fatal_ "./configure failed"
  75. # The only signals that can be trapped portable are 1 "SIGHUP",
  76. # 2 "SIGINT", 13 "SIGPIPE" and 15 "SIGTERM".
  77. trapped_signals='1 2 13 15'
  78. for sig in $trapped_signals; do
  79. if is_blocked_signal $sig; then
  80. for i in 1 2 3 4; do echo "ok # SKIP signal $sig is blocked"; done
  81. continue
  82. fi
  83. rm -f pid fail *.log
  84. r=ok; env PERL="$PERL" sig="$sig" $MAKE check && r='not ok'
  85. echo "$r - signal $sig to test driver causes \"make check\" to fail"
  86. ls -l
  87. # These files shouldn't exist, but in case they do, their content might
  88. # provide helpful information about the causes of the failure(s).
  89. cat foo.log || :
  90. cat test-suite.log || :
  91. r=ok; ls | $EGREP 'foo.*\.(log|tmp)' && r='not ok'
  92. echo "$r - test driver clean up log and tmp files after signal $sig"
  93. done
  94. :