From 9d5b5bd2f57cad88b2ea689bdce4f3d8662e73a4 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Tue, 3 May 2005 13:57:20 +0000 Subject: Fix problems with losing tokens in the jobserver, reported by Grant Taylor. There are two forms of this: first, it was possible to lose tokens when using -j and -l at the same time, because waiting jobs were not checked when determining whether any jobs were outstanding. Second, if you had an exported recursive variable that contained a $(shell ...) function there is a possibility to lose tokens, since a token was taken but the child list was not updated until after the shell function was complete. To resolve this I introduced a new variable that counted the number of tokens we have obtained, rather than checking whether there were any children on the list. I also added some sanity checks to make sure we weren't writing back too many or not enough tokens. And, the master make will drain the token pipe before exiting and compare the count of tokens at the end to what was written there at the beginning. Also: * Ensure a bug in the environment (missing "=") doesn't cause make to core. * Rename the .DEFAULT_TARGET variable to .DEFAULT_GOAL, to match the terminology in the documentation and other variables like MAKECMDGOALS. * Add documentation of the .DEFAULT_GOAL special variable. Still need to document the secondary expansion stuff... --- tests/ChangeLog | 11 +++++ tests/scripts/features/parallelism | 77 ++++++++++++--------------------- tests/scripts/variables/DEFAULT_GOAL | 78 ++++++++++++++++++++++++++++++++++ tests/scripts/variables/DEFAULT_TARGET | 78 ---------------------------------- 4 files changed, 117 insertions(+), 127 deletions(-) create mode 100644 tests/scripts/variables/DEFAULT_GOAL delete mode 100644 tests/scripts/variables/DEFAULT_TARGET (limited to 'tests') diff --git a/tests/ChangeLog b/tests/ChangeLog index 698cffb..2a19918 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,14 @@ +2005-05-03 Paul D. Smith + + * scripts/variables/DEFAULT_GOAL: Rename DEFAULT_TARGET to + DEFAULT_GOAL. + +2005-05-02 Paul D. Smith + + * scripts/features/parallelism: Add a test for exporting recursive + variables containing $(shell ) calls. Rewrite this script to use + run_make_test() everywhere. + 2005-04-07 Paul D. Smith * scripts/targets/SECONDARY: Add a test for Savannah bug #12331. diff --git a/tests/scripts/features/parallelism b/tests/scripts/features/parallelism index f500352..4768539 100644 --- a/tests/scripts/features/parallelism +++ b/tests/scripts/features/parallelism @@ -26,58 +26,32 @@ else { $sleep_command = "sleep"; } -open(MAKEFILE,"> $makefile"); -print MAKEFILE <<"EOF"; +run_make_test(" all : def_1 def_2 def_3 def_1 : ; \@echo ONE; $sleep_command 3 ; echo TWO def_2 : ; \@$sleep_command 2 ; echo THREE -def_3 : ; \@$sleep_command 1 ; echo FOUR -EOF - -close(MAKEFILE); - -&run_make_with_options($makefile, "-j 4", &get_logfile); -$answer = "ONE\nFOUR\nTHREE\nTWO\n"; -&compare_output($answer, &get_logfile(1)); - +def_3 : ; \@$sleep_command 1 ; echo FOUR", + '-j4', "ONE\nFOUR\nTHREE\nTWO"); # Test parallelism with included files. Here we sleep/echo while # building the included files, to test that they are being built in # parallel. - -$makefile2 = &get_tmpfile; - -open(MAKEFILE,"> $makefile2"); - -print MAKEFILE <<"EOF"; +run_make_test(" all: 1 2; \@echo success - -include 1.inc 2.inc - -1.inc: ; \@echo ONE.inc; $sleep_command 2; echo TWO.inc; echo "1: ; \@echo ONE; $sleep_command 2; echo TWO" > \$\@ -2.inc: ; \@$sleep_command 1; echo THREE.inc; echo "2: ; \@$sleep_command 1; echo THREE" > \$\@ -EOF - -close(MAKEFILE); - -&run_make_with_options("$makefile2", "-j 4", &get_logfile); -$answer = "ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n"; -&compare_output($answer, &get_logfile(1)); +1.inc: ; \@echo ONE.inc; $sleep_command 2; echo TWO.inc; echo '1: ; \@echo ONE; $sleep_command 2; echo TWO' > \$\@ +2.inc: ; \@$sleep_command 1; echo THREE.inc; echo '2: ; \@$sleep_command 1; echo THREE' > \$\@", + "-j4", + "ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n"); unlink('1.inc', '2.inc'); # Test parallelism with included files--this time recurse first and make # sure the jobserver works. - -$makefile3 = &get_tmpfile; - -open(MAKEFILE,"> $makefile3"); - -print MAKEFILE <<"EOF"; -recurse: ; \@\$(MAKE) --no-print-directory -f $makefile3 INC=yes all - +run_make_test(" +recurse: ; \@\$(MAKE) --no-print-directory -f #MAKEFILE# INC=yes all all: 1 2; \@echo success INC = no @@ -85,23 +59,28 @@ ifeq (\$(INC),yes) -include 1.inc 2.inc endif -1.inc: ; \@echo ONE.inc; $sleep_command 2; echo TWO.inc; echo "1: ; \@echo ONE; $sleep_command 2; echo TWO" > \$\@ -2.inc: ; \@$sleep_command 1; echo THREE.inc; echo "2: ; \@$sleep_command 1; echo THREE" > \$\@ -EOF +1.inc: ; \@echo ONE.inc; $sleep_command 2; echo TWO.inc; echo '1: ; \@echo ONE; $sleep_command 2; echo TWO' > \$\@ +2.inc: ; \@$sleep_command 1; echo THREE.inc; echo '2: ; \@$sleep_command 1; echo THREE' > \$\@", + "-j4", + "ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n"); -close(MAKEFILE); +unlink('1.inc', '2.inc'); -&run_make_with_options("$makefile3", "-j 4", &get_logfile); -$answer = "ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n"; -&compare_output($answer, &get_logfile(1)); +# Grant Taylor reports a problem where tokens can be lost (not written back +# to the pipe when they should be): this happened when there is a $(shell ...) +# function in an exported recursive variable. I added some code to check +# for this situation and print a message if it occurred. This test used +# to trigger this code when I added it but no longer does after the fix. -unlink('1.inc', '2.inc'); +run_make_test(" +export HI = \$(shell \$(\$\@.CMD)) +first.CMD = echo hi +second.CMD = $sleep_command 4; echo hi -# Test shell functions within commands: make sure they're not reducing our -# parallelism. +.PHONY: all first second +all: first second -run_make_test('.PHONY: all -all: ; @echo $(shell echo hi) -','','hi'); +first second: ; \@echo \$\@; $sleep_command 1; echo \$\@", + '-j2', "first\nfirst\nsecond\nsecond"); 1; diff --git a/tests/scripts/variables/DEFAULT_GOAL b/tests/scripts/variables/DEFAULT_GOAL new file mode 100644 index 0000000..897bd4a --- /dev/null +++ b/tests/scripts/variables/DEFAULT_GOAL @@ -0,0 +1,78 @@ +# -*-perl-*- +$description = "Test the .DEFAULT_GOAL special variable."; + +$details = ""; + + +# Test #1: basic logic. +# +run_make_test(' +# Basics. +# +foo: ; @: + +ifneq ($(.DEFAULT_GOAL),foo) +$(error ) +endif + +# Reset to empty. +# +.DEFAULT_GOAL := + +bar: ; @: + +ifneq ($(.DEFAULT_GOAL),bar) +$(error ) +endif + +# Change to a different goal. +# + +.DEFAULT_GOAL := baz + +baz: ; @echo $@ +', +'', +'baz'); + + +# Test #2: unknown goal. +# +run_make_test(' +.DEFAULT_GOAL = foo +', +'', +'#MAKE#: *** No rule to make target `foo\'. Stop.', +512); + + +# Test #3: more than one goal. +# +run_make_test(' +.DEFAULT_GOAL := foo bar +', +'', +'#MAKE#: *** .DEFAULT_GOAL contains more than one target. Stop.', +512); + + +# Test #4: Savannah bug #12226. +# +run_make_test(' +define rule +foo: ; @echo $$@ +endef + +define make-rule +$(eval $(rule)) +endef + +$(call make-rule) + +', +'', +'foo'); + + +# This tells the test driver that the perl test script executed properly. +1; diff --git a/tests/scripts/variables/DEFAULT_TARGET b/tests/scripts/variables/DEFAULT_TARGET deleted file mode 100644 index d8f1173..0000000 --- a/tests/scripts/variables/DEFAULT_TARGET +++ /dev/null @@ -1,78 +0,0 @@ -# -*-perl-*- -$description = "Test the .DEFAULT_TARGET special variable."; - -$details = ""; - - -# Test #1: basic logic. -# -run_make_test(' -# Basics. -# -foo: ; @: - -ifneq ($(.DEFAULT_TARGET),foo) -$(error ) -endif - -# Reset to empty. -# -.DEFAULT_TARGET := - -bar: ; @: - -ifneq ($(.DEFAULT_TARGET),bar) -$(error ) -endif - -# Change to a different target. -# - -.DEFAULT_TARGET := baz - -baz: ; @echo $@ -', -'', -'baz'); - - -# Test #2: unknown target. -# -run_make_test(' -.DEFAULT_TARGET := foo -', -'', -'make: *** No rule to make target `foo\'. Stop.', -512); - - -# Test #3: more than one target. -# -run_make_test(' -.DEFAULT_TARGET := foo bar -', -'', -'make: *** .DEFAULT_TARGET contains more than one target. Stop.', -512); - - -# Test #4: Savannah bug #12226. -# -run_make_test(' -define rule -foo: ; @echo $$@ -endef - -define make-rule -$(eval $(rule)) -endef - -$(call make-rule) - -', -'', -'foo'); - - -# This tells the test driver that the perl test script executed properly. -1; -- cgit v1.2.3