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