Merge branch 'simplify-exit-trap-workaround' into maint
[platform/upstream/automake.git] / t / parallel-tests-many.sh
1 #! /bin/sh
2 # Copyright (C) 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 harness does not hit errors due to
18 # an exceeded command line length when there are many tests.
19 # For automake bug#7868.  This test is currently expected to fail.
20
21 . ./defs || exit 1
22
23 cat >> configure.ac << 'END'
24 AC_OUTPUT
25 END
26
27 cat > Makefile.am <<'END'
28 # Sanity check that the $(TESTS) is going to exceed the system
29 # command line length.
30 # Extra quoting and indirections below are required to ensure the
31 # various make implementations (e.g, GNU make or Sun Distributed Make)
32 # will truly spawn a shell to execute this command, instead of relying
33 # on optimizations that might mask the "Argument list too long" error
34 # we expect.
35 this-will-fail:
36         @":" && ":" $(TEST_LOGS)
37 TEST_LOG_COMPILER = true
38 include list-of-tests.am
39 # So that we won't have to create a ton of dummy test cases.
40 $(TESTS):
41 END
42
43 # The real instance will be dynamically created later.
44 echo TESTS = foo.test > list-of-tests.am
45
46 $ACLOCAL && $AUTOCONF && $AUTOMAKE -a \
47   || framework_failure_ "unexpected autotools failure"
48 ./configure \
49   || framework_failure_ "unexpected configure failure"
50
51 # We want to hit the system command-line length limit without hitting
52 # the filename length limit or the PATHMAX limit; so we use longish
53 # (but not too long) names for the testcase, and place them in a nested
54 # (but not too deeply) directory.
55 # We also prefer to use the minimal(ish) number of test cases that can
56 # make us hit the command-line length limit, since the more the test
57 # cases are, the more time "automake" and "make check" will take to run
58 # (especially on Cygwin and MinGW/MSYS).
59
60 tname="wow-this-is-a-very-long-name-for-a-simple-dummy-test-case"
61 dname="and-this-too-is-a-very-long-name-for-a-dummy-directory"
62
63 deepdir=.
64 depth=0
65 for i in 1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 29 21 22 23 24; do
66   new_deepdir=$deepdir/$dname.d$i
67   mkdir $new_deepdir || break
68   tmpfile=$new_deepdir/$tname-some-more-chars-for-good-measure
69   if touch $tmpfile; then
70     rm -f $tmpfile || exit 99
71   else
72     rmdir $new_deepdir || exit 99
73   fi
74   deepdir=$new_deepdir
75   unset tmpfile new_deepdir
76   depth=$i
77 done
78
79 cat <<END
80 *********************************************************************
81 Our tests will be in the following directory (depth = $depth)
82 *********************************************************************
83 $deepdir
84 *********************************************************************
85 END
86
87 setup_data ()
88 {
89   # Use perl, not awk, to avoid errors like "awk: string too long"
90   # (seen e.g. with Solaris 10 /usr/bin/awk).
91   count=$count deepdir=$deepdir tname=$tname $PERL -e '
92     use warnings FATAL => "all";
93     use strict;
94     print "TESTS = \\\n";
95     my $i = 0;
96     while (++$i)
97       {
98         print "  $ENV{deepdir}/$ENV{tname}-$i.test";
99         if ($i >= $ENV{count})
100           {
101             print "\n";
102             last;
103           }
104         else
105           {
106             print " \\\n";
107           }
108       }
109   ' > list-of-tests.am || exit 99
110   sed 20q list-of-tests.am || exit 99 # For debugging.
111   $AUTOMAKE Makefile \
112     || framework_failure_ "unexpected automake failure"
113   ./config.status Makefile \
114     || framework_failure_ "unexpected config.status failure"
115 }
116
117 for count in 1 2 4 8 12 16 20 24 28 32 48 64 96 128 E_HUGE; do
118   test $count = E_HUGE && break
119   count=$(($count * 100))
120   setup_data
121   if $MAKE this-will-fail; then
122     continue
123   else
124     # We have managed to find a number of test cases large enough to
125     # hit the system command-line limits; we can stop.  But first, for
126     # good measure, increase the number of tests of some 20%, to be
127     # "even more sure" of really tickling command line length limits.
128     count=$(($count * 12))
129     count=$(($count / 10))
130     setup_data
131     break
132   fi
133 done
134
135 if test $count = E_HUGE; then
136   framework_failure_ "system has a too-high limit on command line length"
137 else
138   cat <<END
139 *********************************************************************
140                Number of tests we will use: $count
141 *********************************************************************
142 END
143 fi
144
145 env TESTS=$deepdir/$tname-1.test $MAKE -e check \
146   && test -f $deepdir/$tname-1.log \
147   || framework_failure_ "\"make check\" with one single tests"
148
149 rm -f $deepdir/* || exit 99
150
151 $MAKE check > stdout || { cat stdout; exit 1; }
152 cat stdout
153
154 grep "^# TOTAL: $count$" stdout
155 grep "^# PASS:  $count$" stdout
156
157 grep "^PASS: .*$tname-[0-9][0-9]*\.test" stdout > grp
158 ls -1 $deepdir | grep '\.log$' > lst
159
160 sed 20q lst # For debugging.
161 sed 20q grp # Likewise.
162
163 test $(cat <grp | wc -l) -eq $count
164 test $(cat <lst | wc -l) -eq $count
165
166 # We need to simulate a failure of two tests.
167 st=0
168 env TESTS="$deepdir/$tname-1.test $deepdir/$tname-2.test" \
169     TEST_LOG_COMPILER=false $MAKE -e check > stdout && st=1
170 cat stdout
171 test $(grep -c '^FAIL:' stdout) -eq 2 || st=1
172 test $st -eq 0 || fatal_ "couldn't simulate failure of two tests"
173 unset st
174
175 $MAKE recheck > stdout || { cat stdout; exit 1; }
176 cat stdout
177 grep "^PASS: .*$tname-1\.test" stdout
178 grep "^PASS: .*$tname-2\.test" stdout
179 test $(LC_ALL=C grep -c "^[A-Z][A-Z]*:" stdout) -eq 2
180 grep "^# TOTAL: 2$" stdout
181 grep "^# PASS:  2$" stdout
182
183 # "make clean" might ignore some failures, so we prefer to also grep its
184 # output to ensure that no "Argument list too long" error was encountered.
185 $MAKE clean >output 2>&1 || { cat output; exit 1; }
186 cat output
187 grep -i 'list.* too long' output && exit 1
188 ls $deepdir | grep '\.log$' && exit 1
189
190 :