From: Stefano Lattarini Date: Wed, 9 May 2012 08:31:46 +0000 (+0200) Subject: [ng] check: per-suffix dependencies for test cases X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8df5284d9b3abf09df2251ffe344fc535b017379;p=thirdparty%2Fautomake.git [ng] check: per-suffix dependencies for test cases Akim Demaille asked (in automake bug#11287) for a way to specify extra dependencies for the test cases, depending on their extension (or lack thereof). Now that Automake-NG uses pattern rules instead of old-fashion suffix rules to generate '.log' and '.trs' files from test cases, doing that is trivial. * NG-NEWS: Update. * doc/automake.texi: Document the new feature. * automake.in (handle_per_suffix_test): Mark the contents of the '${pfx}LOG_DEPENDENCIES' variable as processed (required to avoid spurious errors). * lib/am/check2.am (%.log, %.trs): Depend on '$(%PFX%LOG_DEPENDENCIES)'. * t/parallel-tests-per-suffix-deps.sh: New test. * t/parallel-tests-log-compiler-example.sh: Renamed ... * t/parallel-tests-logvars-example.sh: ... to this, and adjusted to be more faithful to the updated documentation. Signed-off-by: Stefano Lattarini --- diff --git a/NG-NEWS b/NG-NEWS index b28fcccd6..4eab9489c 100644 --- a/NG-NEWS +++ b/NG-NEWS @@ -123,6 +123,10 @@ Parallel testsuite harness make check RECHECK_LOGS="" # Old API, won't work anymore. +* Per-suffix dependencies for test cases can be specified through + variables "_LOG_DEPENDENCIES" (this being simply "LOG_DEPENDENCIES" + for suffix-less tests). + Pattern rules and suffix rules ============================== diff --git a/automake.in b/automake.in index 01fb18597..7cf488d58 100644 --- a/automake.in +++ b/automake.in @@ -4667,6 +4667,10 @@ sub handle_per_suffix_test($) "\$(SHELL) $am_config_aux_dir/test-driver", INTERNAL); } + # Required to avoid spurious errors like: + # ``variable 'LOG_DEPENDENCIES' is defined but no program or + # library has 'LOG' as canonical name (possible typo)'' + set_seen ("${pfx}LOG_DEPENDENCIES"); $output_rules .= file_contents ('check2', new Automake::Location, PFX => $pfx, EXT => $test_suffix); diff --git a/doc/automake.texi b/doc/automake.texi index 046ab5f89..e83b56be9 100644 --- a/doc/automake.texi +++ b/doc/automake.texi @@ -9018,33 +9018,52 @@ while @samp{.x-y}, @samp{.6c} and @samp{.t.1} are not. @vindex @var{ext}_LOG_FLAGS @vindex AM_@var{ext}_LOG_FLAGS @vindex AM_LOG_FLAGS +@noindent For tests that match an extension @code{.@var{ext}} listed in -@code{TEST_EXTENSIONS}, you can provide a custom ``test runner'' using -the variable @code{@var{ext}_LOG_COMPILER} (note the upper-case -extension) and pass options in @code{AM_@var{ext}_LOG_FLAGS} and allow -the user to pass options in @code{@var{ext}_LOG_FLAGS}. It will cause -all tests with this extension to be called with this runner. For all -tests without a registered extension, the variables @code{LOG_COMPILER}, -@code{AM_LOG_FLAGS}, and @code{LOG_FLAGS} may be used. For example, +@code{TEST_EXTENSIONS}, you can: + +@itemize +@item +declare extra dependencies through @code{@var{ext}_LOG_DEPENDENCIES}; +@item +provide a custom ``test runner'' using @code{@var{ext}_LOG_COMPILER}, +(it will be used to run all the tests with this extension); +@item +pass options to that runner through @code{AM_@var{ext}_LOG_FLAGS}; +@item +allow the user to pass further options through @code{@var{ext}_LOG_FLAGS}. +@end itemize + +@noindent +Similarly, for tests without a registered extension, the variables +@code{LOG_DEPENDENCIES}, @code{LOG_COMPILER}, @code{AM_LOG_FLAGS} and +@code{LOG_FLAGS} may be used for those same purposes. + +Let's see an example. -@c Keep in sync with parallel-tests-log-compiler-example.sh +@c Keep in sync with parallel-tests-logvars-example.sh @example TESTS = foo.pl bar.py baz TEST_EXTENSIONS = .pl .py + PL_LOG_COMPILER = $(PERL) AM_PL_LOG_FLAGS = -w + PY_LOG_COMPILER = $(PYTHON) AM_PY_LOG_FLAGS = -v +PY_LOG_DEPENDENCIES = mymod.py + LOG_COMPILER = ./wrapper-script AM_LOG_FLAGS = -d @end example @noindent -will invoke @samp{$(PERL) -w foo.pl}, @samp{$(PYTHON) -v bar.py}, +The above will invoke @samp{$(PERL) -w foo.pl}, @samp{$(PYTHON) -v bar.py}, and @samp{./wrapper-script -d baz} to produce @file{foo.log}, -@file{bar.log}, and @file{baz.log}, respectively. The @file{foo.trs}, -@file{bar.trs} and @file{baz.trs} files will be automatically produced -as a side-effect. +@file{bar.log}, and @file{baz.log}, respectively, and will ensure +the python module @file{mymod.py} is built before the @file{bar.py} +test is run. The @file{foo.trs}, @file{bar.trs} and @file{baz.trs} +files will be automatically produced as a side-effect. It's important to note that, differently from what we've seen for the serial test harness (@pxref{Parallel Test Harness}), the diff --git a/lib/am/check2.am b/lib/am/check2.am index 34fdd5827..486944cfe 100644 --- a/lib/am/check2.am +++ b/lib/am/check2.am @@ -53,7 +53,7 @@ am__runtest = \ endif %?FIRST% ## From a test file to a .log and .trs file. -%.log %.trs: %%EXT% +%.log %.trs: %%EXT% $(%PFX%LOG_DEPENDENCIES) @$(call am__runtest,%PFX%) ## If no programs are built in this package, then this rule is removed @@ -62,7 +62,7 @@ if %HANDLE-EXEEXT% ## FIXME: spurious indentnation to avoid Automake thinking this is an ## automake conditional. ifdef EXEEXT -%.log %.trs: %%EXT%$(EXEEXT) +%.log %.trs: %%EXT%$(EXEEXT) $(%PFX%LOG_DEPENDENCIES) @$(call am__runtest,%PFX%) endif endif %HANDLE-EXEEXT% diff --git a/t/parallel-tests-log-compiler-example.sh b/t/parallel-tests-logvars-example.sh similarity index 87% rename from t/parallel-tests-log-compiler-example.sh rename to t/parallel-tests-logvars-example.sh index 8b4575861..fc922a519 100755 --- a/t/parallel-tests-log-compiler-example.sh +++ b/t/parallel-tests-logvars-example.sh @@ -15,7 +15,7 @@ # along with this program. If not, see . # Test the example of usage of generic and extension-specific -# LOG_COMPILER and LOG_FLAGS given in the manual. +# LOG_COMPILER, LOG_FLAGS and LOG_DEPENDNECIES given in the manual. am_parallel_tests=yes required=python @@ -30,16 +30,22 @@ END cat > Makefile.am << 'END' TESTS = foo.pl bar.py baz TEST_EXTENSIONS = .pl .py + PL_LOG_COMPILER = $(PERL) AM_PL_LOG_FLAGS = -w -PY_LOG_COMPILER = $(PYTHON) -AM_PY_LOG_FLAGS = -v + LOG_COMPILER = ./wrapper-script AM_LOG_FLAGS = -d + +PY_LOG_COMPILER = $(PYTHON) +AM_PY_LOG_FLAGS = -v +PY_LOG_DEPENDENCIES = mymod.py +mymod.py: + echo "import sys" >$@ END echo 'my $a =+ 2; exit (0);' > foo.pl -echo 'import sys; sys.exit(0);' > bar.py +echo 'import mymod; mymod.sys.exit(0);' > bar.py : > baz cat > wrapper-script <<'END' @@ -59,6 +65,9 @@ $MAKE check || st=$? cat foo.log cat bar.log cat baz.log +cat foo.trs +cat bar.trs +cat baz.trs test $st -eq 0 || Exit $st # Check that the wrappers have been run with the expected flags. diff --git a/t/parallel-tests-per-suffix-deps.sh b/t/parallel-tests-per-suffix-deps.sh new file mode 100755 index 000000000..496c9f6ef --- /dev/null +++ b/t/parallel-tests-per-suffix-deps.sh @@ -0,0 +1,163 @@ +#! /bin/sh +# Copyright (C) 2012 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# The user should be able to easily specify extra dependencies for +# the test cases, depending on their extension (or lack thereof). +# We do so with the help of "${prefix}LOG_DEPENDENCIES" variables. +# See the last wishlist in automake bug#11287. + +am_parallel_tests=yes +. ./defs || Exit 1 + +cat >> configure.ac <<'END' +AC_SUBST([EXEEXT], [.bin]) +AC_OUTPUT +END + +cat > Makefile.am << 'END' +TEST_EXTENSIONS = .test .sh +TESTS = foo.test foo2.test bar.sh baz zard.oz quux.bin mu.test.bin + +TEST_LOG_DEPENDENCIES = test-dep +SH_LOG_DEPENDENCIES = sh-dep1 sh-dep2 +LOG_DEPENDENCIES = dep + +DEPS = test-dep sh-dep1 sh-dep2 dep new-test-dep +$(DEPS): + echo dummy > $@ +CLEANFILES = $(DEPS) + +.PHONY: setup +setup: + chmod a+x $(TESTS) +EXTRA_DIST = $(TESTS) +END + +cat > foo.test <<'END' +#! /bin/sh +test -f test-dep || test -f new-test-dep +END + +cat > foo2.test <<'END' +#! /bin/sh +test -f test-dep +END + +cp foo2.test mu.test.bin + +cat > bar.sh <<'END' +#! /bin/sh +test -f sh-dep1 && test -f sh-dep2 +END + +cat > baz <<'END' +#! /bin/sh +test -f dep +END + +cp baz quux.bin + +cat > zard.oz <<'END' +#! /bin/sh +test -f dep +END + +$ACLOCAL +$AUTOCONF +$AUTOMAKE -a + +./configure + +$MAKE setup + +cleanup () { rm -f test-dep sh-dep1 sh-dep2 dep; } + +$MAKE check -j4 +test ! -f new-test-dep +test -f test-dep +test -f sh-dep1 +test -f sh-dep2 +test -f dep +test -f quux.log # Sanity check. +test -f mu.log # Likewise. + +cleanup + +$MAKE check TESTS=foo.test +test -f test-dep +test ! -f sh-dep1 +test ! -f sh-dep2 +test ! -f dep + +cleanup +rm -f bar.log +$MAKE check TESTS=bar.sh AM_LAZY_CHECK=yes +test ! -f test-dep +test -f sh-dep1 +test -f sh-dep2 +test ! -f dep + +cleanup +$MAKE check TESTS=baz +test ! -f test-dep +test ! -f sh-dep1 +test ! -f sh-dep2 +test -f dep + +cleanup +$MAKE check TESTS='foo bar' +test -f test-dep +test -f sh-dep1 +test -f sh-dep2 +test ! -f dep + +cleanup +$MAKE check TESTS=zard.oz +test ! -f test-dep +test ! -f sh-dep1 +test ! -f sh-dep2 +test -f dep + +cleanup +$MAKE check TESTS=mu.test.bin +test -f test-dep +test ! -f sh-dep1 +test ! -f sh-dep2 +test ! -f dep + +cleanup +$MAKE check TESTS='quux.bin bar.sh' +test ! -f test-dep +test -f sh-dep1 +test -f sh-dep2 +test -f dep + +cleanup +$MAKE check TESTS=foo TEST_LOG_DEPENDENCIES=new-test-dep +test -f new-test-dep +test ! -f test-dep +test ! -f sh-dep1 +test ! -f sh-dep2 +test ! -f dep + +cleanup +$MAKE check TESTS=baz XFAIL_TESTS=baz LOG_DEPENDENCIES= +test ! -f dep +grep ':test-result: XFAIL' baz.trs + +$MAKE distcheck + +: