ylwrap: preserve subdirectories in "#line" munging
[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 am_parallel_tests=yes
22 . ./defs || Exit 1
23
24 cat >> configure.ac << 'END'
25 AC_OUTPUT
26 END
27
28 cat > Makefile.am <<'END'
29 # Sanity check that the $(TESTS) is going to exceed the system
30 # command line length.
31 # Extra quoting and indirections below are required to ensure the
32 # various make implementations (e.g, GNU make or Sun Distributed Make)
33 # will truly spawn a shell to execute this command, instead of relying
34 # on optimizations that might mask the "Argument list too long" error
35 # we expect.
36 this-will-fail:
37         @":" && ":" $(TEST_LOGS)
38 TEST_LOG_COMPILER = true
39 include list-of-tests.am
40 # So that we won't have to create a ton of dummy test cases.
41 $(TESTS):
42 END
43
44 # The real instance will be dynamically created later.
45 echo TESTS = foo.test > list-of-tests.am
46
47 $ACLOCAL && $AUTOCONF && $AUTOMAKE -a \
48   || framework_failure_ "unexpected autotools failure"
49 ./configure \
50   || framework_failure_ "unexpected configure failure"
51
52 # We want to hit the system command-line length limit without hitting
53 # the filename length limit or the PATHMAX limit; so we use longish
54 # (but not too long) names for the testcase, and place them in a nested
55 # (but not too deeply) directory.
56 # We also prefer to use the minimal(ish) number of test cases that can
57 # make us hit the command-line length limit, since the more the test
58 # cases are, the more time "automake" and "make check" will take to run
59 # (especially on Cygwin and MinGW/MSYS).
60
61 tname="wow-this-is-a-very-long-name-for-a-simple-dummy-test-case"
62 dname="and-this-too-is-a-very-long-name-for-a-dummy-directory"
63
64 deepdir=.
65 depth=0
66 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
67   new_deepdir=$deepdir/$dname.d$i
68   mkdir $new_deepdir || break
69   tmpfile=$new_deepdir/$tname-some-more-chars-for-good-measure
70   if touch $tmpfile; then
71     rm -f $tmpfile || Exit 99
72   else
73     rmdir $new_deepdir || Exit 99
74   fi
75   deepdir=$new_deepdir
76   unset tmpfile new_deepdir
77   depth=$i
78 done
79
80 cat <<END
81 *********************************************************************
82 Our tests will be in the following directory (depth = $depth)
83 *********************************************************************
84 $deepdir
85 *********************************************************************
86 END
87
88 setup_data ()
89 {
90   # Use perl, not awk, to avoid errors like "awk: string too long"
91   # (seen e.g. with Solaris 10 /usr/bin/awk).
92   count=$count deepdir=$deepdir tname=$tname $PERL -e '
93     use warnings FATAL => "all";
94     use strict;
95     print "TESTS = \\\n";
96     my $i = 0;
97     while (++$i)
98       {
99         print "  $ENV{deepdir}/$ENV{tname}-$i.test";
100         if ($i >= $ENV{count})
101           {
102             print "\n";
103             last;
104           }
105         else
106           {
107             print " \\\n";
108           }
109       }
110   ' > list-of-tests.am || Exit 99
111   sed 20q list-of-tests.am || Exit 99 # For debugging.
112   $AUTOMAKE Makefile \
113     || framework_failure_ "unexpected automake failure"
114   ./config.status Makefile \
115     || framework_failure_ "unexpected config.status failure"
116 }
117
118 for count in 1 2 4 8 12 16 20 24 28 32 48 64 96 128 E_HUGE; do
119   test $count = E_HUGE && break
120   count=`expr $count '*' 100` || Exit 99
121   setup_data
122   if $MAKE this-will-fail; then
123     continue
124   else
125     # We have managed to find a number of test cases large enough to
126     # hit the system command-line limits; we can stop.  But first, for
127     # good measure, increase the number of tests of some 20%, to be
128     # "even more sure" of really tickling command line length limits.
129     count=`expr '(' $count '*' 12 ')' / 10` || Exit 99
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 :