Merge branch 'maint'
[platform/upstream/automake.git] / lib / am / check.am
1 ## automake - create Makefile.in from Makefile.am
2 ## Copyright (C) 2001-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 am__tty_colors_dummy = \
18   mgn= red= grn= lgn= blu= brg= std=; \
19   am__color_tests=no
20 if %?COLOR%
21 # If stdout is a non-dumb tty, use colors.  If test -t is not supported,
22 # then this fails; a conservative approach.  Of course do not redirect
23 # stdout here, just stderr.
24 am__tty_colors = \
25 $(am__tty_colors_dummy); \
26 test "X$(AM_COLOR_TESTS)" != Xno \
27 && test "X$$TERM" != Xdumb \
28 && { test "X$(AM_COLOR_TESTS)" = Xalways || test -t 1 2>/dev/null; } \
29 && { \
30   am__color_tests=yes; \
31   red='\e[0;31m'; \
32   grn='\e[0;32m'; \
33   lgn='\e[1;32m'; \
34   blu='\e[1;34m'; \
35   mgn='\e[0;35m'; \
36   brg='\e[1m'; \
37   std='\e[m'; \
38 }
39 else !%?COLOR%
40 am__tty_colors = $(am__tty_colors_dummy)
41 endif !%?COLOR%
42
43 .PHONY: check-TESTS
44
45 if %?PARALLEL_TESTS%
46
47 include inst-vars.am
48
49 ## New parallel test driver.
50 ##
51 ## The first version of the code here was adapted from check.mk, which was
52 ## originally written at EPITA/LRDE, further developed at Gostai, then made
53 ## its way from GNU coreutils to end up, largely rewritten, in Automake.
54 ## The current version is an heavy rewrite of that, to allow for support
55 ## of more test metadata, and the use of custom test derivers and protocols
56 ## (among them, TAP).
57
58 # Restructured Text title and section.
59 am__rst_title = { sed 's/.*/   &   /;h;s/./=/g;p;x;s/ *$$//;p;g' && echo; }
60 am__rst_section = { sed 'p;s/./=/g;' && echo; }
61
62 # Solaris 10 'make', and several other traditional 'make' implementations,
63 # pass "-e" to $(SHELL), and POSIX 2008 even requires this.  Work around it
64 # by disabling -e (using the XSI extension "set +e") if it's set.
65 am__sh_e_setup = case $$- in *e*) set +e;; esac
66
67 # Default flags passed to test drivers.
68 am__common_driver_flags = \
69   --color-tests "$$am__color_tests" \
70   --enable-hard-errors "$$am__enable_hard_errors" \
71   --expect-failure "$$am__expect_failure"
72
73 # To be inserted before the command running the test.  Creates the
74 # directory for the log if needed.  Stores in $dir the directory
75 # containing $f, in $tst the test, in $log the log.  Executes the
76 # developer- defined test setup AM_TESTS_ENVIRONMENT (if any), and
77 # passes TESTS_ENVIRONMENT.  Set up options for the wrapper that
78 # will run the test scripts (or their associated LOG_COMPILER, if
79 # thy have one).
80 am__check_pre =                                         \
81 $(am__sh_e_setup);                                      \
82 $(am__vpath_adj_setup) $(am__vpath_adj)                 \
83 $(am__tty_colors);                                      \
84 srcdir=$(srcdir); export srcdir;                        \
85 am__odir=`echo "./$@" | sed 's|/[^/]*$$||'`;            \
86 test "x$$am__odir" = x. || $(MKDIR_P) "$$am__odir" || exit $$?; \
87 if test -f "./$$f"; then dir=./;                        \
88 elif test -f "$$f"; then dir=;                          \
89 else dir="$(srcdir)/"; fi;                              \
90 tst=$$dir$$f; log='$@';                                 \
91 if test -n '$(DISABLE_HARD_ERRORS)'; then               \
92   am__enable_hard_errors=no;                            \
93 else                                                    \
94   am__enable_hard_errors=yes;                           \
95 fi;                                                     \
96 ## The use of $dir below is required to account for VPATH
97 ## rewriting done by Sun make.
98 case " $(XFAIL_TESTS) " in                              \
99   *[\ \ ]$$f[\ \        ]* | *[\ \      ]$$dir$$f[\ \   ]*) \
100     am__expect_failure=yes;;                            \
101   *)                                                    \
102     am__expect_failure=no;;                             \
103 esac;                                                   \
104 $(AM_TESTS_ENVIRONMENT) $(TESTS_ENVIRONMENT)
105
106 # A shell command to get the names of the tests scripts with any registered
107 # extension removed (i.e., equivalently, the names of the test logs, with
108 # the '.log' extension removed).  The result is saved in the shell variable
109 # '$bases'.  This honors runtime overriding of TESTS and TEST_LOGS.  Sadly,
110 # we cannot use something simpler, involving e.g., "$(TEST_LOGS:.log=)",
111 # since that might cause problem with VPATH rewrites for suffix-less tests.
112 # See also 'test-harness-vpath-rewrite.test' and 'test-trs-basic.test'.
113 am__set_TESTS_bases = \
114   bases='$(TEST_LOGS)'; \
115   bases=`for i in $$bases; do echo $$i; done | sed 's/\.log$$//'`; \
116 ## Trim away any extra whitespace.  This has already proved useful
117 ## in avoiding weird bug on lesser make implementations.  It also
118 ## works around the GNU make 3.80 bug where trailing whitespace in
119 ## "TESTS = foo.test $(empty)" causes $(TESTS_LOGS)  to erroneously
120 ## expand to "foo.log .log".
121   bases=`echo $$bases`
122
123 # Recover from deleted '.trs' file; this should ensure that
124 # "rm -f foo.log; make foo.trs" re-run 'foo.test', and re-create
125 # both 'foo.log' and 'foo.trs'.  Break the recipe in two subshells
126 # to avoid problems with "make -n".
127 .log.trs:
128         rm -f $< $@
129         $(MAKE) $(AM_MAKEFLAGS) $<
130
131 $(TEST_SUITE_LOG): $(TEST_LOGS)
132         @$(am__set_TESTS_bases); \
133 ## Helper shell function, tells whether a path refers to an existing,
134 ## regular, readable file.
135         am__f_ok () { test -f "$$1" && test -r "$$1"; }; \
136 ## We need to ensures that all the required '.trs' and '.log' files will
137 ## be present and readable.  The direct dependencies of $(TEST_SUITE_LOG)
138 ## only ensure that all the '.log' files exists; they don't ensure that
139 ## the '.log' files are readable, and worse, they don't ensure that the
140 ## '.trs' files even exist.
141         redo_bases=`for i in $$bases; do \
142                       am__f_ok $$i.trs && am__f_ok $$i.log || echo $$i; \
143                     done`; \
144         if test -n "$$redo_bases"; then \
145 ## Uh-oh, either some '.log' files were unreadable, or some '.trs' files
146 ## were missing (or unreadable).  We need to re-run the corresponding
147 ## tests in order to re-create them.
148           redo_logs=`for i in $$redo_bases; do echo $$i.log; done`; \
149           redo_results=`for i in $$redo_bases; do echo $$i.trs; done`; \
150           if $(am__make_dryrun); then :; else \
151 ## Break "rm -f" into two calls to minimize the possibility of exceeding
152 ## command line length limits.
153             rm -f $$redo_logs && rm -f $$redo_results || exit 1; \
154           fi; \
155         fi; \
156 ## Use a trick to to ensure that we don't go into an infinite recursion
157 ## in case a test log in $(TEST_LOGS) is the same as $(TEST_SUITE_LOG).
158 ## Yes, this has already happened in practice.  Sigh!
159         if test -n "$$am__remaking_logs"; then \
160           echo "fatal: making $(TEST_SUITE_LOG): possible infinite" \
161                "recursion detected" >&2; \
162         else \
163           am__remaking_logs=yes $(MAKE) $(AM_MAKEFLAGS) $$redo_logs; \
164         fi; \
165         if $(am__make_dryrun); then :; else \
166 ## Sanity check: each unreadable or non-existent test result file should
167 ## has been properly remade at this point, as should the corresponding log
168 ## file.
169           st=0;  \
170           errmsg="fatal: making $(TEST_SUITE_LOG): failed to create"; \
171           for i in $$redo_bases; do \
172             test -f $$i.trs && test -r $$i.trs \
173               || { echo "$$errmsg $$i.trs"; st=1; }; \
174             test -f $$i.log && test -r $$i.log \
175               || { echo "$$errmsg $$i.log"; st=1; }; \
176           done; \
177           test $$st -eq 0 || exit 1; \
178         fi
179 ## We need a new subshell to work portably with "make -n", since the
180 ## previous part of the recipe contained a $(MAKE) invocation.
181         @$(am__sh_e_setup); $(am__tty_colors); $(am__set_TESTS_bases); \
182         ws='[   ]'; \
183 ## List of test result files.
184         results=`for b in $$bases; do echo $$b.trs; done`; \
185         test -n "$$results" || results=/dev/null; \
186 ## Prepare data for the test suite summary.  These do not take into account
187 ## unreadable test results, but they'll be appropriately updated later if
188 ## needed.
189         all=`  grep "^$$ws*:test-result:"           $$results | wc -l`; \
190         pass=` grep "^$$ws*:test-result:$$ws*PASS"  $$results | wc -l`; \
191         fail=` grep "^$$ws*:test-result:$$ws*FAIL"  $$results | wc -l`; \
192         skip=` grep "^$$ws*:test-result:$$ws*SKIP"  $$results | wc -l`; \
193         xfail=`grep "^$$ws*:test-result:$$ws*XFAIL" $$results | wc -l`; \
194         xpass=`grep "^$$ws*:test-result:$$ws*XPASS" $$results | wc -l`; \
195         error=`grep "^$$ws*:test-result:$$ws*ERROR" $$results | wc -l`; \
196 ## Whether the testsuite was successful or not.
197         if test `expr $$fail + $$xpass + $$error` -eq 0; then \
198           success=true; \
199         else \
200           success=false; \
201         fi; \
202 ## Make $br a line of exactly 76 '=' characters, that will be used to
203 ## enclose the testsuite summary report when displayed on the console.
204         br='==================='; br=$$br$$br$$br$$br; \
205 ## When writing the test summary to the console, we want to color a line
206 ## reporting the count of some result *only* if at least one test
207 ## experienced such a result.  This function is handy in this regard.
208         result_count () \
209         { \
210             if test x"$$1" = x"--maybe-color"; then \
211               maybe_colorize=yes; \
212             elif test x"$$1" = x"--no-color"; then \
213               maybe_colorize=no; \
214             else \
215               echo "$@: invalid 'result_count' usage" >&2; exit 4; \
216             fi; \
217             shift; \
218             desc=$$1 count=$$2; \
219             if test $$maybe_colorize = yes && test $$count -gt 0; then \
220               color_start=$$3 color_end=$$std; \
221             else \
222               color_start= color_end=; \
223             fi; \
224             echo "$${color_start}# $$desc $$count$${color_end}"; \
225         }; \
226 ## A shell function that creates the testsuite summary.  We need it
227 ## because we have to create *two* summaries, one for test-suite.log,
228 ## and a possibly-colorized one for console output.
229         create_testsuite_report () \
230         { \
231           result_count $$1 "TOTAL:" $$all   "$$brg"; \
232           result_count $$1 "PASS: " $$pass  "$$grn"; \
233           result_count $$1 "SKIP: " $$skip  "$$blu"; \
234           result_count $$1 "XFAIL:" $$xfail "$$lgn"; \
235           result_count $$1 "FAIL: " $$fail  "$$red"; \
236           result_count $$1 "XPASS:" $$xpass "$$red"; \
237           result_count $$1 "ERROR:" $$error "$$mgn"; \
238         }; \
239 ## Write "global" testsuite log.
240         {                                                               \
241           echo "$(PACKAGE_STRING): $(subdir)/$(TEST_SUITE_LOG)" |       \
242             $(am__rst_title);                                           \
243           create_testsuite_report --no-color;                           \
244           echo;                                                         \
245           echo ".. contents:: :depth: 2";                               \
246           echo;                                                         \
247           for i in $$bases; do                                          \
248 ## FIXME: one fork per test -- this is horrendously inefficient!
249             if grep "^$$ws*:copy-in-global-log:$$ws*no$$ws*$$" $$i.trs \
250                  >/dev/null; then continue; \
251             fi; \
252 ## Get the declared "global result" of the test.
253 ## FIXME: yet another one fork per test here!
254             glob_res=`sed -n -e "s/$$ws*$$//" \
255                              -e "s/^$$ws*:global-test-result:$$ws*//p" \
256                         $$i.trs`; \
257 ## If no global result is explicitly declared, we'll merely mark the
258 ## test as "RUN" in the global test log.
259             test -n "$$glob_res" || glob_res=RUN; \
260 ## Write the name and result of the test as an RST section title.
261             echo "$$glob_res: $$i" | $(am__rst_section); \
262 ## If we should have remade any unreadable '.log', above.
263             if test ! -r $$i.log; then \
264               echo "fatal: making $@: $$i.log is unreadable" >&2; \
265               exit 1; \
266             fi; \
267             cat $$i.log; echo; \
268           done; \
269         } >$(TEST_SUITE_LOG).tmp;                                       \
270         mv $(TEST_SUITE_LOG).tmp $(TEST_SUITE_LOG);                     \
271 ## Emit the test summary on the console.
272         if $$success; then                                              \
273           col="$$grn";                                                  \
274          else                                                           \
275           col="$$red";                                                  \
276           test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG);               \
277         fi;                                                             \
278 ## Multi line coloring is problematic with "less -R", so we really need
279 ## to color each line individually.
280         echo "$${col}$$br$${std}";                                      \
281         echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}";   \
282         echo "$${col}$$br$${std}";                                      \
283 ## This is expected to go to the console, so it might have to be colorized.
284         create_testsuite_report --maybe-color;                          \
285         echo "$$col$$br$$std";                                          \
286         if $$success; then :; else                                      \
287           echo "$${col}See $(subdir)/$(TEST_SUITE_LOG)$${std}";         \
288           if test -n "$(PACKAGE_BUGREPORT)"; then                       \
289             echo "$${col}Please report to $(PACKAGE_BUGREPORT)$${std}"; \
290           fi;                                                           \
291           echo "$$col$$br$$std";                                        \
292         fi;                                                             \
293 ## Be sure to exit with the proper exit status.  The use of "exit 1" below
294 ## is required to work around a FreeBSD make bug (present only when running
295 ## in concurrent mode).  See automake bug#9245:
296 ##  <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9245>
297 ## and FreeBSD PR bin/159730:
298 ##  <http://www.freebsd.org/cgi/query-pr.cgi?pr=159730>.
299         $$success || exit 1
300
301 RECHECK_LOGS = $(TEST_LOGS)
302
303 ## ------------------------------------------ ##
304 ## Running all tests, or rechecking failures. ##
305 ## ------------------------------------------ ##
306
307 check-TESTS recheck:
308 ## If we are running "make recheck", it's not the user which can decide
309 ## which tests to consider for re-execution, so we must ignore the value
310 ## of $(RECHECK_LOGS).
311 ## Here and below, we expand $(RECHECK_LOGS) only once, to avoid exceeding
312 ## line length limits.
313         @if test $@ != recheck; then \
314            list='$(RECHECK_LOGS)'; \
315            test -z "$$list" || rm -f $$list; \
316          fi
317         @if test $@ != recheck; then \
318            list='$(RECHECK_LOGS:.log=.trs)'; \
319            test -z "$$list" || rm -f $$list; \
320          fi
321 ## We always have to remove TEST_SUITE_LOG, to ensure its rule is run
322 ## in any case even in lazy mode: otherwise, if no test needs rerunning,
323 ## or a prior run plus reruns all happen within the same timestamp (can
324 ## happen with a prior "make TESTS=<subset>"), then we get no log output.
325 ## OTOH, this means that, in the rule for '$(TEST_SUITE_LOG)', we
326 ## cannot use '$?' to compute the set of lazily rerun tests, lest
327 ## we rely on .PHONY to work portably.
328         @test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG)
329         @ws='[  ]'; \
330         log_list='' trs_list=''; $(am__set_TESTS_bases); \
331         for i in $$bases; do \
332 ## If running a "make recheck", we must only consider tests that had an
333 ## unexpected outcome (FAIL or XPASS) in the earlier run.  In particular,
334 ## skip tests that haven't been run.  But recover gracefully from deleted
335 ## '.trs' files.
336           if test $@ = recheck; then \
337             test -f $$i.trs || test -f $$i.log || continue; \
338 ## FIXME: one fork per test -- this is horrendously inefficient!
339             grep "^$$ws*:recheck:$$ws*no$$ws*$$" $$i.trs \
340               >/dev/null 2>&1 && continue; \
341           else :; fi; \
342 ## Be careful to avoid extra whitespace in the definition of $list, since
343 ## its value will be passed to the recursive make invocation below through
344 ## the TEST_LOGS macro, and leading/trailing white space in a make macro
345 ## definition can be problematic.  In this particular case, trailing white
346 ## space was known to cause a segmentation fault on Solaris 10 XPG4 make:
347 ## <http://lists.gnu.org/archive/html/bug-automake/2010-08/msg00004.html>
348           if test -z "$$log_list"; then \
349             log_list="$$i.log"; \
350           else \
351             log_list="$$log_list $$i.log"; \
352           fi; \
353           if test -z "$$trs_list"; then \
354             trs_list="$$i.trs"; \
355           else \
356             trs_list="$$trs_list $$i.trs"; \
357           fi; \
358         done; \
359 ## Under "make recheck", remove the .log and .trs files associated
360 ## with the files to recheck, so that those will be rerun by the
361 ## "make test-suite.log" recursive invocation below.  But use a proper
362 ## hack to avoid extra files removal when running under "make -n".
363         if test $@ != recheck || $(am__make_dryrun); then :; else \
364           test -z "$$log_list" || rm -f $$log_list; \
365           test -z "$$trs_list" || rm -f $$trs_list; \
366         fi; \
367         $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) TEST_LOGS="$$log_list"
368
369 ## Recheck must depend on $(check_SCRIPTS), $(check_PROGRAMS), etc.
370 recheck: %CHECK_DEPS%
371
372 AM_RECURSIVE_TARGETS += check recheck
373
374 .PHONY: recheck
375
376 else !%?PARALLEL_TESTS%
377
378 check-TESTS: $(TESTS)
379         @failed=0; all=0; xfail=0; xpass=0; skip=0; \
380         srcdir=$(srcdir); export srcdir; \
381 ## Make sure Solaris VPATH-expands all members of this list, even
382 ## the first and the last one; thus the spaces around $(TESTS)
383         list=' $(TESTS) '; \
384         $(am__tty_colors); \
385         if test -n "$$list"; then \
386           for tst in $$list; do \
387             if test -f ./$$tst; then dir=./; \
388 ## Note: Solaris 2.7 seems to expand TESTS using VPATH.  That's
389 ## why we also try 'dir='.
390             elif test -f $$tst; then dir=; \
391             else dir="$(srcdir)/"; fi; \
392             if $(TESTS_ENVIRONMENT) $${dir}$$tst $(AM_TESTS_FD_REDIRECT); then \
393 ## Success
394               all=`expr $$all + 1`; \
395               case " $(XFAIL_TESTS) " in \
396               *[\ \     ]$$tst[\ \      ]*) \
397                 xpass=`expr $$xpass + 1`; \
398                 failed=`expr $$failed + 1`; \
399                 col=$$red; res=XPASS; \
400               ;; \
401               *) \
402                 col=$$grn; res=PASS; \
403               ;; \
404               esac; \
405             elif test $$? -ne 77; then \
406 ## Failure
407               all=`expr $$all + 1`; \
408               case " $(XFAIL_TESTS) " in \
409               *[\ \     ]$$tst[\ \      ]*) \
410                 xfail=`expr $$xfail + 1`; \
411                 col=$$lgn; res=XFAIL; \
412               ;; \
413               *) \
414                 failed=`expr $$failed + 1`; \
415                 col=$$red; res=FAIL; \
416               ;; \
417               esac; \
418             else \
419 ## Skipped
420               skip=`expr $$skip + 1`; \
421               col=$$blu; res=SKIP; \
422             fi; \
423             echo "$${col}$$res$${std}: $$tst"; \
424           done; \
425 ## Prepare the banner
426           if test "$$all" -eq 1; then \
427             tests="test"; \
428             All=""; \
429           else \
430             tests="tests"; \
431             All="All "; \
432           fi; \
433           if test "$$failed" -eq 0; then \
434             if test "$$xfail" -eq 0; then \
435               banner="$$All$$all $$tests passed"; \
436             else \
437               if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \
438               banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \
439             fi; \
440           else \
441             if test "$$xpass" -eq 0; then \
442               banner="$$failed of $$all $$tests failed"; \
443             else \
444               if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \
445               banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \
446             fi; \
447           fi; \
448 ## DASHES should contain the largest line of the banner.
449           dashes="$$banner"; \
450           skipped=""; \
451           if test "$$skip" -ne 0; then \
452             if test "$$skip" -eq 1; then \
453               skipped="($$skip test was not run)"; \
454             else \
455               skipped="($$skip tests were not run)"; \
456             fi; \
457             test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
458               dashes="$$skipped"; \
459           fi; \
460           report=""; \
461           if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \
462             report="Please report to $(PACKAGE_BUGREPORT)"; \
463             test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \
464               dashes="$$report"; \
465           fi; \
466           dashes=`echo "$$dashes" | sed s/./=/g`; \
467           if test "$$failed" -eq 0; then \
468             col="$$grn"; \
469           else \
470             col="$$red"; \
471           fi; \
472 ## Multi line coloring is problematic with "less -R", so we really need
473 ## to color each line individually.
474           echo "$${col}$$dashes$${std}"; \
475           echo "$${col}$$banner$${std}"; \
476           test -z "$$skipped" || echo "$${col}$$skipped$${std}"; \
477           test -z "$$report" || echo "$${col}$$report$${std}"; \
478           echo "$${col}$$dashes$${std}"; \
479           test "$$failed" -eq 0; \
480         else :; fi
481
482 endif !%?PARALLEL_TESTS%