* tests/parallel-tests-extra-programs.test: New test. * tests/Makefile.am (TESTS): Update. * doc/automake.texi (Parallel Test Harness): Add a comment pointing to the new test. --- ChangeLog | 8 ++ doc/automake.texi | 1 + tests/Makefile.am | 1 + tests/Makefile.in | 1 + tests/parallel-tests-extra-programs.test | 174 ++++++++++++++++++++++++++++++ 5 files changed, 185 insertions(+), 0 deletions(-) create mode 100755 tests/parallel-tests-extra-programs.test
diff --git a/ChangeLog b/ChangeLog index 15a223d..c61c20f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2011-08-02 Stefano Lattarini <stefano.lattar...@gmail.com> + coverage: parallel-tests and lazy dependencies on EXTRA_PROGRAMS + * tests/parallel-tests-extra-programs.test: New test. + * tests/Makefile.am (TESTS): Update. + * doc/automake.texi (Parallel Test Harness): Add a comment + pointing to the new test. + +2011-08-02 Stefano Lattarini <stefano.lattar...@gmail.com> + docs: improve, extend and fix documentation on TAP support * doc/automake.texi ("Using the TAP test protocol"): Divide this section into ... diff --git a/doc/automake.texi b/doc/automake.texi index c1ee0a5..65a692d 100644 --- a/doc/automake.texi +++ b/doc/automake.texi @@ -9186,6 +9186,7 @@ parallel @command{make -j@var{N}}, so be sure they are prepared for concurrent execution. @cindex Unit tests +@c Keep in sync with 'parallel-tests-extra-programs.test'. The combination of lazy test execution and correct dependencies between tests and their sources may be exploited for efficient unit testing during development. To further speed up the edit-compile-test cycle, it diff --git a/tests/Makefile.am b/tests/Makefile.am index 6a45fcf..d7aed68 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -727,6 +727,7 @@ parallel-tests10.test \ parallel-tests-make-n.test \ parallel-tests-fd-redirect.test \ parallel-tests-am_tests_environment.test \ +parallel-tests-extra-programs.test \ parallel-tests-unreadable.test \ parallel-tests-subdir.test \ parallel-tests-interrupt.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index a085762..bd907b0 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -978,6 +978,7 @@ parallel-tests10.test \ parallel-tests-make-n.test \ parallel-tests-fd-redirect.test \ parallel-tests-am_tests_environment.test \ +parallel-tests-extra-programs.test \ parallel-tests-unreadable.test \ parallel-tests-subdir.test \ parallel-tests-interrupt.test \ diff --git a/tests/parallel-tests-extra-programs.test b/tests/parallel-tests-extra-programs.test new file mode 100755 index 0000000..f309b4c --- /dev/null +++ b/tests/parallel-tests-extra-programs.test @@ -0,0 +1,174 @@ +#! /bin/sh +# Copyright (C) 2011 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 <http://www.gnu.org/licenses/>. + +# Parallel test harness: check that $(TESTS) can lazily depend on +# (or even be) $(EXTRA_PROGRAMS). + +required='cc native' +parallel_tests=yes +. ./defs || Exit 1 + +cat >> configure.in << 'END' +AC_PROG_CC +AC_OUTPUT +END + +# Will be extended later. +cat > Makefile.am << 'END' +TEST_EXTENSIONS = .bin .test +EXTRA_PROGRAMS = +TESTS = +END + +# +# Now try various kinds of test dependencies ... +# + +# 1. A program that is also a test, and whose source files +# already exist. + +cat >> Makefile.am <<'END' +EXTRA_PROGRAMS += foo.bin +TESTS += foo.bin +foo_bin_SOURCES = foo.c +END + +cat > foo.c <<'END' +#include <stdio.h> +int main (void) +{ + printf ("foofoofoo\n"); + return 0; +} +END + +# 2. A program that is also a test, and whose source files +# are buildable by make. +cat >> Makefile.am <<'END' +EXTRA_PROGRAMS += bar.bin +TESTS += bar.bin +bar_bin_SOURCES = bar.c +bar.c: foo.c + sed -e 's/foofoofoo/barbarbar/' foo.c > $@ +END + +# 3. A test script that already exists, whose execution depends +# on a program whose source files already exist and which is +# not itself a test. +cat >> Makefile.am <<'END' +EXTRA_PROGRAMS += y +TESTS += baz.test +baz.log: y$(EXEEXT) +END + +cat > baz.test <<'END' +#!/bin/sh +$srcdir/y "$@" | sed 's/.*/&ep&ep&ep/' +END +chmod a+x baz.test + +cat > y.c <<'END' +#include <stdio.h> +int main (void) +{ + printf ("y\n"); + return 0; +} +END + +# 4. A program that is also a test, but whose source files +# do not exit and are not buildable by make. + +cat >> Makefile.am <<'END' +EXTRA_PROGRAMS += none.bin +TESTS += none.bin +none_bin_SOURCES = none.c +END + +# +# Setup done, go with the tests. +# + +$ACLOCAL +$AUTOCONF +$AUTOMAKE -a + +./configure + +# What we check now: +# 1. even if we cannot build the `none.bin' program, all the other +# test programs should be built, and all the other tests should +# be run; +# 2. still, since we cannot create the `none.log' file, the +# `test-suite.log' file shouldn't be created (as it depends +# on *all* the test logs). + +st=0 +$MAKE check >stdout 2>stderr || st=$? +cat stdout +cat stderr >&2 +ls -l +test $st -gt 0 || Exit 1 + +# Files that should have been created, with the expected content. +cat bar.c +grep foofoofoo foo.log +grep barbarbar bar.log +grep yepyepyep baz.log +# Files that shouldn't have been created. +test ! -f none.log +test ! -f test-suite.log +# Expected testsuite progress output. +grep '^PASS: baz\.test$' stdout +# Don't anchor the end of the next two patterns, to allow for non-empty +# $(EXEEXT). +grep '^PASS: foo\.bin' stdout +grep '^PASS: bar\.bin' stdout +# Expected error messages from make. +$EGREP 'none\.(bin|o|c)' stderr + +# What we check now: +# 1. if we make the last EXTRA_PROGRAM buildable, the failed tests +# pass; +# 2. on a lazy re-run, the passed tests are not re-run, and +# 3. their log files are not updated or touched. + +: > stamp +$sleep + +echo 'int main (void) { return 0; }' > none.c + +st=0 +RECHECK_LOGS= $MAKE -e check >stdout || st=$? +cat stdout +ls -l +test $st -eq 0 || Exit 1 + +# For debugging. +stat stamp foo.log bar.log baz.log || : + +# Files that shouldn't have been updated or otherwise touched. +is_newest stamp foo.log bar.log baz.log +# Files that should have been created now. +test -f none.log +test -f test-suite.log +# Tests that shouldn't have been re-run. +$EGREP '(foo|bar)\.bin|baz\.test$' stdout && Exit 1 +# Tests that should have been run. Again, we don't anchor the end +# of the next pattern, to allow for non-empty $(EXEEXT). +grep '^PASS: none\.bin' stdout + +: -- 1.7.2.3