tests: fix a failure in Lex/C++ tests on Mac OS X
[platform/upstream/automake.git] / t / parallel-tests3.sh
1 #! /bin/sh
2 # Copyright (C) 2009-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 parallel-tests features:
18 # - concurrent parallel execution
19
20 am_parallel_tests=yes
21 . ./defs || Exit 1
22
23 case $MAKE in
24   *\ -j*) skip_ "\$MAKE contains '-j'";;
25 esac
26
27 if using_gmake; then
28   j=-j
29 else
30   unindent > Makefile <<END
31     all: one two
32     one:
33         $sleep && test -f two
34     two:
35         echo ok > \$@
36 END
37   for j in "-j" "-j " NONE; do
38     if test x"$j" = xNONE; then
39       skip_ "can't run make in parallel mode"
40     fi
41     $MAKE ${j}2 all >output 2>&1 || continue
42     $EGREP -i "(warning|error):|-j[\"\'\` ]" output && continue
43     break
44   done
45   rm -f one output Makefile
46 fi
47
48 cat >> configure.ac << 'END'
49 AC_OUTPUT
50 END
51
52 cat > Makefile.am << 'END'
53 TESTS =
54 END
55
56 cat > x <<'END'
57 #! /bin/sh
58 echo "this is $0"
59 # Creative quoting below to please maintainer-check.
60 sleep '1'
61 exit 0
62 END
63 chmod a+x ./x
64
65 mkdir sub
66 for i in 1 2 3; do
67   echo "TESTS += foo$i.test" >> Makefile.am
68   cp x foo$i.test
69   echo "TESTS += zap$i" >> Makefile.am
70   cp x zap$i
71   echo "TESTS += sub/bar$i.test" >> Makefile.am
72   cp x sub/bar$i.test
73   echo "TESTS += sub/mu$i" >> Makefile.am
74   cp x sub/mu$i
75 done
76
77 $ACLOCAL
78 $AUTOCONF
79 $AUTOMAKE -a
80
81 for build in serial parallel; do
82   mkdir $build
83   cd $build
84   ../configure
85   $MAKE
86   cd ..
87 done
88
89 cd serial
90 $MAKE ${j}1 check &
91 cd ../parallel
92 $sleep
93 # Use append mode here to avoid dropping output.
94 # Yes, this actually happens.
95 : >stdout
96 $MAKE ${j}4 check >> stdout
97 cd ..
98 # Ensure the tests are really being run in parallel mode: if this is
99 # the case, the serial run of the dummy testsuite started above should
100 # still be ongoing when the parallel one has terminated.
101 kill -0 $!
102 cat parallel/stdout
103 test `grep -c '^PASS:' parallel/stdout` -eq 12
104
105 # Wait long enough so that there are no open files any more when the
106 # post-test cleanup runs.  But exit after we've waited for two minutes
107 # or more, to avoid testsuite hangs in unusual situations (this has
108 # already happened).
109 i=1
110 while test ! -f serial/test-suite.log && test $i -le 120; do
111   i=`expr $i + 1`
112   sleep '1' # Extra quoting to please maintainer-check.
113 done
114 $sleep
115
116 :