Merge branch 'maint'
[platform/upstream/automake.git] / t / parallel-tests-extra-programs.sh
1 #! /bin/sh
2 # Copyright (C) 2011-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 # Parallel test harness: check that $(TESTS) can lazily depend on
18 # (or even be) $(EXTRA_PROGRAMS).
19
20 required='cc native'
21 am_parallel_tests=yes
22 . ./defs || Exit 1
23
24 cat >> configure.ac << 'END'
25 AC_PROG_CC
26 AC_OUTPUT
27 END
28
29 # Will be extended later.
30 cat > Makefile.am << 'END'
31 TEST_EXTENSIONS = .bin .test
32 EXTRA_PROGRAMS =
33 TESTS =
34 END
35
36 #
37 # Now try various kinds of test dependencies ...
38 #
39
40 # 1. A program that is also a test, and whose source files
41 #    already exist.
42
43 cat >> Makefile.am <<'END'
44 EXTRA_PROGRAMS += foo.bin
45 TESTS += foo.bin
46 foo_bin_SOURCES = foo.c
47 END
48
49 cat > foo.c <<'END'
50 #include <stdio.h>
51 int main (void)
52 {
53   printf ("foofoofoo\n");
54   return 0;
55 }
56 END
57
58 # 2. A program that is also a test, and whose source files
59 #    are buildable by make.
60 cat >> Makefile.am <<'END'
61 EXTRA_PROGRAMS += bar.bin
62 TESTS += bar.bin
63 bar_bin_SOURCES = bar.c
64 bar.c: foo.c
65         sed -e 's/foofoofoo/barbarbar/' foo.c > $@
66 END
67
68 # 3. A test script that already exists, whose execution depends
69 #    on a program whose source files already exist and which is
70 #    not itself a test.
71 cat >> Makefile.am <<'END'
72 EXTRA_PROGRAMS += y
73 TESTS += baz.test
74 baz.log: y$(EXEEXT)
75 END
76
77 cat > baz.test <<'END'
78 #!/bin/sh
79 $srcdir/y "$@" | sed 's/.*/&ep&ep&ep/'
80 END
81 chmod a+x baz.test
82
83 cat > y.c <<'END'
84 #include <stdio.h>
85 int main (void)
86 {
87   printf ("y\n");
88   return 0;
89 }
90 END
91
92 # 4. A program that is also a test, but whose source files
93 #    do not exit and are not buildable by make.
94
95 cat >> Makefile.am <<'END'
96 EXTRA_PROGRAMS += none.bin
97 TESTS += none.bin
98 none_bin_SOURCES = none.c
99 END
100
101 #
102 # Setup done, go with the tests.
103 #
104
105 $ACLOCAL
106 $AUTOCONF
107 $AUTOMAKE -a
108
109 ./configure
110
111 # What we check now:
112 #  1. even if we cannot build the 'none.bin' program, all the other
113 #     test programs should be built, and all the other tests should
114 #     be run;
115 #  2. still, since we cannot create the 'none.log' file, the
116 #    'test-suite.log' file shouldn't be created (as it depends
117 #     on *all* the test logs).
118
119 st=0
120 $MAKE -k check >stdout 2>stderr || st=$?
121 cat stdout
122 cat stderr >&2
123 ls -l
124 if using_gmake; then
125   test $st -gt 0 || Exit 1
126 else
127   # Don't trust exit status of "make -k" for non-GNU make.
128   $MAKE check && Exit 1
129   : For shells with busted 'set -e'.
130 fi
131
132 # Files that should have been created, with the expected content.
133 cat bar.c
134 grep foofoofoo foo.log
135 grep barbarbar bar.log
136 grep yepyepyep baz.log
137 # Files that shouldn't have been created.
138 test ! -f none.log
139 test ! -f test-suite.log
140 # Expected testsuite progress output.
141 grep '^PASS: baz\.test$' stdout
142 # Don't anchor the end of the next two patterns, to allow for non-empty
143 # $(EXEEXT).
144 grep '^PASS: foo\.bin' stdout
145 grep '^PASS: bar\.bin' stdout
146 # Expected error messages from make.  Some make implementations (e.g.,
147 # FreeBSD make) seem to print the error on stdout instead, so check for
148 # it there as well.
149 $EGREP 'none\.(bin|o|c)' stderr stdout
150
151 # What we check now:
152 #  1. if we make the last EXTRA_PROGRAM buildable, the failed tests
153 #     pass;
154 #  2. on a lazy re-run, the passed tests are not re-run, and
155 #  3. their log files are not updated or touched.
156
157 : > stamp
158 $sleep
159
160 echo 'int main (void) { return 0; }' > none.c
161
162 st=0
163 RECHECK_LOGS= $MAKE -e check >stdout || st=$?
164 cat stdout
165 ls -l
166 test $st -eq 0 || Exit 1
167
168 # For debugging.
169 stat stamp foo.log bar.log baz.log || :
170
171 # Files that shouldn't have been updated or otherwise touched.
172 is_newest stamp foo.log bar.log baz.log
173 # Files that should have been created now.
174 test -f none.log
175 test -f test-suite.log
176 # Tests that shouldn't have been re-run.
177 $EGREP '(foo|bar)\.bin|baz\.test$' stdout && Exit 1
178 # Tests that should have been run.  Again, we don't anchor the end
179 # of the next pattern, to allow for non-empty $(EXEEXT).
180 grep '^PASS: none\.bin' stdout
181
182 :