2 # Copyright (C) 2011-2012 Free Software Foundation, Inc.
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)
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.
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/>.
17 # Check that the parallel-tests driver removed incomplete log files
18 # when interrupt upon some signal. This test is definitely too hacky,
19 # but we couldn't find a better way to deal with inter-processes
20 # signals and the whole process-synchronization mess.
26 cat >> configure.ac << 'END'
30 cat > Makefile.am << 'END'
32 ## Provide more debugging info.
33 TEST_LOG_COMPILER = $(SHELL) -ex
34 ## Required by foo.test; see below.
35 AM_TESTS_FD_REDIRECT = 9>&1
38 # This is hacky and ugly, but has the great advantage of avoiding us a lot
39 # of pain with background processes and related synchronization issues.
41 cat - "$am_scriptdir"/test-driver > test-driver <<'END'
46 cat > foo.test << 'END'
49 # We expect the test driver to be terminated by a signal, and so
50 # to exit with non-zero status, thus causing "make check" to fail.
51 # Exiting with status 0 from this test script is thus a good way to
52 # make unexpected behaviours more evident, since this will likely
53 # cause and unexpected success in "make check".
55 stop_test () { exit 0; }
57 # We need the "foo is starting to run" string flushed to standard output
58 # ASAP, because we are soon going to grep for that string in the log file
59 # where the test driver is redirecting this script's stdout. The safest
60 # way force this flushing portably is to rely on perl I/O capabilities.
61 $PERL -e 'BEGIN { $| = 1 }; print "foo is starting to run\n"' || stop_test
63 ls -l >&9 || stop_test
67 # Print this to the original stdout (saved in the fd 9), so that the
68 # emitted "Bail out!" directive will be interpreted by the test driver
69 # running the Automake testsuite.
70 echo "Bail out! $*" >&9
74 test $sig -gt 0 || bailout "\$sig not exported to test script"
76 res=ok; cat foo.log >&9 || res="not ok"
77 echo "$res - logfile created and readable [SIG $sig]" >&9
79 res=ok; grep '^foo is starting to run$' foo.log >&9 || res='not ok'
80 echo "$res - logfile contains output from test script [SIG $sig]" >&9
82 cat pid >&9 || bailout "cannot get PID of test driver"
83 kill -$sig `cat pid` || bailout "cannot send signal $sig to test driver"
89 $ACLOCAL || fatal_ "aclocal failed"
90 $AUTOCONF || fatal_ "autoconf failed"
91 $AUTOMAKE || fatal_ "automake failed"
93 ./configure || fatal_ "./configure failed"
95 # The only signals that can be trapped portable are 1 "SIGHUP",
96 # 2 "SIGINT", 13 "SIGPIPE" and 15 "SIGTERM".
97 trapped_signals='1 2 13 15'
99 for sig in $trapped_signals; do
100 if is_blocked_signal $sig; then
101 for i in 1 2 3 4; do echo "ok # SKIP signal $sig is blocked"; done
105 r=ok; env PERL="$PERL" sig="$sig" $MAKE check && r='not ok'
106 echo "$r - signal $sig to test driver causes \"make check\" to fail"
108 # These files shouldn't exist, but in case they do, their content might
109 # provide helpful information about the causes of the failure(s).
111 cat test-suite.log || :
112 r=ok; ls | $EGREP 'foo.*\.(log|tmp)' && r='not ok'
113 echo "$r - test driver clean up log and tmp files after signal $sig"