From 44d202536a5fd0ac670eef7f43326093c8c9bc5b Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Sat, 27 Oct 2012 15:38:46 +0200 Subject: [PATCH] tests: move coverage about BUILT_SOURCES Basically a backport of some tests from Automake-NG. * t/built-sources-check.sh: Sync it with the version in the ng/master branch. Accordingly, move part of the checks out ... * t/built-sources-install.sh: ... into this new test, synced from ng/master as well. * t/built-sources-subdir.sh: Minor tweaks and enhancements to sync it with the version in ng/master. * t/built-sources-cond.sh: New test, synced from ng/master. * t/built-sources.sh: Likewise, with minor edits to avoid a spurious failure. * t/built-sources-fork-bomb.sh: Likewise. * t/list-of-tests.mk: Update. Signed-off-by: Stefano Lattarini --- t/built-sources-check.sh | 16 +--- t/built-sources-cond.sh | 91 ++++++++++++++++++++++ t/built-sources-fork-bomb.sh | 70 +++++++++++++++++ ...t-sources-check.sh => built-sources-install.sh} | 61 ++++++--------- t/built-sources-subdir.sh | 21 ++--- t/built-sources.sh | 68 ++++++++++++++++ t/list-of-tests.mk | 4 + 7 files changed, 266 insertions(+), 65 deletions(-) create mode 100755 t/built-sources-cond.sh create mode 100755 t/built-sources-fork-bomb.sh copy t/{built-sources-check.sh => built-sources-install.sh} (52%) create mode 100755 t/built-sources.sh diff --git a/t/built-sources-check.sh b/t/built-sources-check.sh index 3e4ce96f8..d4d3c51e2 100755 --- a/t/built-sources-check.sh +++ b/t/built-sources-check.sh @@ -14,7 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# Make sure 'check:' and 'install:' honor $(BUILT_SOURCES). +# Make sure 'check:' honors $(BUILT_SOURCES). # PR/359. # For gen-testsuite-part: ==> try-with-serial-tests <== @@ -63,18 +63,6 @@ cat stdout grep '^PASS: subrun\.sh *$' stdout grep 'PASS.*echo\.sh' stdout && exit 1 -# check should depend directly on $(BUILT_SOURCES) (similar tests -# are in check.sh and check2.sh). -$EGREP '^check:.* \$\(BUILT_SOURCES\)( |$)' Makefile.in -$EGREP '^check:.* \$\(BUILT_SOURCES\)( |$)' dir/Makefile.in - -$MAKE clean -# Sanity checks -test ! -e command1.inc -test ! -e dir/command2.inc -# Now make sure these two files are rebuilt during make install. -$MAKE install -test -f command1.inc -test -f dir/command2.inc +$MAKE distcheck : diff --git a/t/built-sources-cond.sh b/t/built-sources-cond.sh new file mode 100755 index 000000000..ac78a9756 --- /dev/null +++ b/t/built-sources-cond.sh @@ -0,0 +1,91 @@ +#! /bin/sh +# Copyright (C) 2003-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 . + +# Interaction of BUILT_SOURCES with conditionals. + +. ./defs || exit 1 + +cat >> configure.ac <<'END' +AM_CONDITIONAL([COND1], [test $cond1 = yes]) +AM_CONDITIONAL([COND2], [test $cond2 = yes]) +AC_OUTPUT +END + +cat > Makefile.am << 'END' +if COND1 +BUILT_SOURCES = a +else +BUILT_SOURCES = b +endif +if COND2 +BUILT_SOURCES += c +endif + +a b c: + echo who cares > $@ +END + +$ACLOCAL +$AUTOMAKE +$AUTOCONF + +cleanup () +{ + # Files in $(BUILT_SOURCES) should be automatically removed + # upon maintainer-clean. + $MAKE maintainer-clean + test ! -f a + test ! -f b + test ! -f c +} + +./configure cond1=yes cond2=yes + +$MAKE +test -f a +test ! -f b +test -f c + +cleanup + +./configure cond1=no cond2=yes + +$MAKE +test ! -f a +test -f b +test -f c + +cleanup + +./configure cond1=yes cond2=no + +$MAKE +test -f a +test ! -f b +test ! -f c + +cleanup + +./configure cond1=no cond2=no + +$MAKE +test ! -f a +test -f b +test ! -f c + +cleanup + +: diff --git a/t/built-sources-fork-bomb.sh b/t/built-sources-fork-bomb.sh new file mode 100755 index 000000000..fac37505f --- /dev/null +++ b/t/built-sources-fork-bomb.sh @@ -0,0 +1,70 @@ +#! /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 . + +# Due to how the handling of $(BUILT_SOURCES) is implemented in Automake-NG, +# a recursive make call in the recipe of any $(BUILT_SOURCES) (or of any of +# its prerequisites) might cause an infinite recursion (complete with fork +# bomb, yuck) if not handled correctly. Verify that this doesn't happen. +# For more background, see: +# +# +# Backported to improve coverage of mainline Automake. + +required=GNUmake +. ./defs || exit 1 + +echo AC_OUTPUT >> configure.ac + +cat > Makefile.am << 'END' +BUILT_SOURCES = foo +.PHONY: build-foo +build-foo: + echo OK > foo +foo: + $(MAKE) build-foo + +# If the bug is still present, we want this test to fail, not to actually +# go fork bomb and potentially crash the user machine. Take care of that. + +is_too_deep := $(shell test $(MAKELEVEL) -lt 10 && echo no) + +## Extra indentation here required to avoid confusing Automake. + ifeq ($(is_too_deep),no) + # All is ok. + else + $(error ::OOPS:: Recursion too deep, $(MAKELEVEL) levels) + endif +END + +$ACLOCAL +$AUTOMAKE -Wno-portability +$AUTOCONF + +./configure + +$MAKE -n foo >output 2>&1 || { cat output; exit 1; } +cat output +test ! -f foo +# Guard against possible infinite recursion. +$FGREP '::OOPS::' output && exit 1 + +$MAKE foo >output 2>&1 || { cat output; exit 1; } +cat output +$MAKE foo +# Guard against possible infinite recursion. +$FGREP '::OOPS::' output && exit 1 + +: diff --git a/t/built-sources-check.sh b/t/built-sources-install.sh similarity index 52% copy from t/built-sources-check.sh copy to t/built-sources-install.sh index 3e4ce96f8..2f53bb51e 100755 --- a/t/built-sources-check.sh +++ b/t/built-sources-install.sh @@ -14,10 +14,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# Make sure 'check:' and 'install:' honor $(BUILT_SOURCES). +# Make sure 'install:' honors $(BUILT_SOURCES). # PR/359. -# For gen-testsuite-part: ==> try-with-serial-tests <== . ./defs || exit 1 cat >> configure.ac << 'END' @@ -28,53 +27,43 @@ END mkdir dir cat > Makefile.am << 'END' -BUILT_SOURCES = command1.inc +BUILT_SOURCES = built1 SUBDIRS = dir -TESTS = subrun.sh -subrun.sh: - (echo '#! /bin/sh'; cat command1.inc) > $@ - chmod +x $@ -command1.inc: - echo 'dir/echo.sh' > $@ -CLEANFILES = subrun.sh command1.inc +built1: + echo ok > $@ +CLEANFILES = built1 +install-data-hook: + $(MKDIR_P) $(DESTDIR)$(prefix)/dir2 + cp built1 $(DESTDIR)$(prefix)/built1 + cp dir/built2 $(DESTDIR)$(prefix)/dir2/built3 +uninstall-hook: + rm -f $(DESTDIR)$(prefix)/built1 + rm -f $(DESTDIR)$(prefix)/dir2/built3 + rmdir $(DESTDIR)$(prefix)/dir2 +installcheck-local: + test -f $(prefix)/built1 + test -f $(prefix)/dir2/built3 END cat > dir/Makefile.am << 'END' -BUILT_SOURCES = command2.inc -check_SCRIPTS = echo.sh -echo.sh: +BUILT_SOURCES = built2 +built2: ## The next line ensures that command1.inc has been built before ## recurring into the subdir. - test -f ../command1.inc - (echo '#! /bin/sh'; cat command2.inc) > $@ - chmod +x $@ -command2.inc: - echo 'echo Hello' > $@ -CLEANFILES = echo.sh command2.inc + cp ../built1 $@ +CLEANFILES = built2 END $ACLOCAL $AUTOCONF -$AUTOMAKE -a +$AUTOMAKE ./configure --prefix "$(pwd)/inst" -$MAKE check >stdout || { cat stdout; exit 1; } -cat stdout -grep '^PASS: subrun\.sh *$' stdout -grep 'PASS.*echo\.sh' stdout && exit 1 - -# check should depend directly on $(BUILT_SOURCES) (similar tests -# are in check.sh and check2.sh). -$EGREP '^check:.* \$\(BUILT_SOURCES\)( |$)' Makefile.in -$EGREP '^check:.* \$\(BUILT_SOURCES\)( |$)' dir/Makefile.in - -$MAKE clean -# Sanity checks -test ! -e command1.inc -test ! -e dir/command2.inc # Now make sure these two files are rebuilt during make install. $MAKE install -test -f command1.inc -test -f dir/command2.inc +test -f built1 +test -f dir/built2 +$MAKE installcheck +$MAKE distcheck : diff --git a/t/built-sources-subdir.sh b/t/built-sources-subdir.sh index 84f65a680..cc162bb99 100755 --- a/t/built-sources-subdir.sh +++ b/t/built-sources-subdir.sh @@ -14,7 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# Make sure when using SUBDIR that all BUILT_SOURCES are built. +# Make sure when using SUBDIRS that all BUILT_SOURCES are built. # A bug occurred where subdirs do not have all-recursive or # all-recursive-am which depended on BUILT_SOURCES. @@ -31,14 +31,6 @@ AM_PROG_AR AC_OUTPUT END -# Files required because we are using '--gnu'. -: > INSTALL -: > NEWS -: > README -: > COPYING -: > AUTHORS -: > ChangeLog - cat > Makefile.am << 'END' SUBDIRS = lib END @@ -47,25 +39,24 @@ cat > lib/Makefile.am << 'END' pkgdata_DATA = noinst_LIBRARIES = libfoo.a libfoo_a_SOURCES = foo.c -BUILT_SOURCES=foo.h +BUILT_SOURCES = foo.h foo.h: echo \#define FOO_DEFINE 1 >$@ +CLEANFILES = $(BUILT_SOURCES) END cat > lib/foo.c << 'END' #include -int foo () { return !FOO_DEFINE;} +int foo (void) { return !FOO_DEFINE; } END $ACLOCAL $AUTOCONF -$AUTOMAKE --include-deps --copy --force-missing --add-missing --gnu +$AUTOMAKE --copy --add-missing ./configure - -# Remove the comment to get a successful test. -# $MAKE -C lib foo.h $MAKE +$MAKE distcheck : diff --git a/t/built-sources.sh b/t/built-sources.sh new file mode 100755 index 000000000..517313660 --- /dev/null +++ b/t/built-sources.sh @@ -0,0 +1,68 @@ +#! /bin/sh +# Copyright (C) 2003-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 . + +# Basic test on BUILT_SOURCES. + +required=cc +. ./defs || exit 1 + +cat >> configure.ac <<'END' +AC_PROG_CC +AC_OUTPUT +END + +cat > Makefile.am << 'END' +BUILT_SOURCES = foo.c +noinst_PROGRAMS = bar baz +foo.c: + rm -f $@ $@-t +## Use printf, not echo, to avoid spurious interpretation of +## the "\n" as a newline (seen on NetBSD 5.1). + printf '%s\n' '#include ' > $@-t + printf '%s\n' 'int main (void)' >> $@-t + printf '%s\n' '{ ' >> $@-t + printf '%s\n' ' printf ("%s\n", FOOMSG);' >> $@-t + printf '%s\n' ' return 0;' >> $@-t + printf '%s\n' '}' >> $@-t + mv -f $@-t $@ +CLEANFILES = foo.c +END + +cat > bar.c <<'END' +#define FOOMSG "Howdy, World" +#include "foo.c" +END + +cat > baz.c <<'END' +#define FOOMSG "Hello, Earth" +#include "foo.c" +END + +$ACLOCAL +$AUTOMAKE +$AUTOCONF + +./configure +$MAKE +if cross_compiling; then :; else + ./bar + ./bar | grep 'Howdy, World' + ./baz + ./baz | grep 'Hello, Earth' +fi +$MAKE distcheck + +: diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk index 99612cf84..84788e0a6 100644 --- a/t/list-of-tests.mk +++ b/t/list-of-tests.mk @@ -186,7 +186,11 @@ t/badopt.sh \ t/badprog.sh \ t/block.sh \ t/built-sources-check.sh \ +t/built-sources-cond.sh \ +t/built-sources-fork-bomb.sh \ +t/built-sources-install.sh \ t/built-sources-subdir.sh \ +t/built-sources.sh \ t/candist.sh \ t/canon.sh \ t/canon2.sh \ -- 2.11.4.GIT