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