make/tests/scripts/features/parallelism
Paul Smith 9d5b5bd2f5 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...
2005-05-03 13:57:20 +00:00

86 lines
2.8 KiB
Perl

# -*-perl-*-
$description = "Test parallelism (-j) option.";
$details = "This test creates a makefile with two double-colon default
rules. The first rule has a series of sleep and echo commands
intended to run in series. The second and third have just an
echo statement. When make is called in this test, it is given
the -j option with a value of 4. This tells make that it may
start up to four jobs simultaneously. In this case, since the
first command is a sleep command, the output of the second
and third commands will appear before the first if indeed
make is running all of these commands in parallel.";
if (!$parallel_jobs) {
return -1;
}
if ($vos) {
$delete_command = "delete_file -no_ask";
$sleep_command = "sleep -seconds";
}
else {
$delete_command = "rm -f";
$sleep_command = "sleep";
}
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",
'-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.
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' > \$\@",
"-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.
run_make_test("
recurse: ; \@\$(MAKE) --no-print-directory -f #MAKEFILE# INC=yes all
all: 1 2; \@echo success
INC = no
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' > \$\@",
"-j4",
"ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n");
unlink('1.inc', '2.inc');
# 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.
run_make_test("
export HI = \$(shell \$(\$\@.CMD))
first.CMD = echo hi
second.CMD = $sleep_command 4; echo hi
.PHONY: all first second
all: first second
first second: ; \@echo \$\@; $sleep_command 1; echo \$\@",
'-j2', "first\nfirst\nsecond\nsecond");
1;