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