tests: avoid a spurious failure on MSYS
[platform/upstream/automake.git] / t / parallel-tests-interrupt.tap
1 #! /bin/sh
2 # Copyright (C) 2011-2013 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 testsuite harness removes 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 . test-init.sh
23
24 plan_ 16
25
26 cat >> configure.ac << 'END'
27 AC_OUTPUT
28 END
29
30 cat > Makefile.am << 'END'
31 TESTS = foo.test
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
36 END
37
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.
40
41 cat - "$am_scriptdir"/test-driver > test-driver <<'END'
42 #!/bin/sh
43 echo $$ > pid
44 END
45
46 cat > foo.test << 'END'
47 #!/bin/sh -e
48
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".
54 trap 'exit 0' 0;
55 stop_test () { exit 0; }
56
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
62
63 ls -l >&9 || stop_test
64
65 bailout ()
66 {
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
71   stop_test
72 }
73
74 test $sig -gt 0 || bailout "\$sig not exported to test script"
75
76 res=ok; cat foo.log >&9 || res="not ok"
77 echo "$res - logfile created and readable [SIG $sig]" >&9
78
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
81
82 cat pid >&9 || bailout "cannot get PID of test driver"
83 kill -$sig `cat pid` || bailout "cannot send signal $sig to test driver"
84
85 stop_test
86 END
87 chmod a+x foo.test
88
89 $ACLOCAL  || fatal_ "aclocal failed"
90 $AUTOCONF || fatal_ "autoconf failed"
91 $AUTOMAKE || fatal_ "automake failed"
92
93 ./configure || fatal_ "./configure failed"
94
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'
98
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
102     continue
103   fi
104   rm -f pid fail *.log
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"
107   ls -l
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).
110   cat foo.log || :
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"
114 done
115
116 :