3 $description = "Test parallelism (-j) option.";
6 $details = "This test creates a makefile with two double-colon default
7 rules. The first rule has a series of sleep and echo commands
8 intended to run in series. The second and third have just an
9 echo statement. When make is called in this test, it is given
10 the -j option with a value of 4. This tells make that it may
11 start up to four jobs simultaneously. In this case, since the
12 first command is a sleep command, the output of the second
13 and third commands will appear before the first if indeed
14 make is running all of these commands in parallel.";
16 if (!$parallel_jobs) {
21 $sleep_command = "sleep -seconds";
24 $sleep_command = "sleep";
29 all : def_1 def_2 def_3
30 def_1 : ; \@echo ONE; $sleep_command 12 ; echo TWO
31 def_2 : ; \@$sleep_command 8 ; echo THREE
32 def_3 : ; \@$sleep_command 4 ; echo FOUR",
33 '-j4', "ONE\nFOUR\nTHREE\nTWO");
35 # Test parallelism with included files. Here we sleep/echo while
36 # building the included files, to test that they are being built in
39 all: 1 2; \@echo success
41 1.inc: ; \@echo ONE.inc; $sleep_command 8; echo TWO.inc; echo '1: ; \@echo ONE; $sleep_command 8; echo TWO' > \$\@
42 2.inc: ; \@$sleep_command 4; echo THREE.inc; echo '2: ; \@$sleep_command 4; echo THREE' > \$\@",
44 "ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n", 0, 7);
46 rmfiles(qw(1.inc 2.inc));
49 # Test parallelism with included files--this time recurse first and make
50 # sure the jobserver works.
52 recurse: ; \@\$(MAKE) --no-print-directory -f #MAKEFILE# INC=yes all
53 all: 1 2; \@echo success
60 1.inc: ; \@echo ONE.inc; $sleep_command 8; echo TWO.inc; echo '1: ; \@echo ONE; $sleep_command 8; echo TWO' > \$\@
61 2.inc: ; \@$sleep_command 4; echo THREE.inc; echo '2: ; \@$sleep_command 4; echo THREE' > \$\@",
63 "ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n", 0, 7);
65 rmfiles(qw(1.inc 2.inc));
67 # Grant Taylor reports a problem where tokens can be lost (not written back
68 # to the pipe when they should be): this happened when there is a $(shell ...)
69 # function in an exported recursive variable. I added some code to check
70 # for this situation and print a message if it occurred. This test used
71 # to trigger this code when I added it but no longer does after the fix.
72 # We have to increase the timeout from the default (5s) on this test.
75 export HI = \$(shell \$(\$\@.CMD))
77 second.CMD = $sleep_command 16; echo hi
79 .PHONY: all first second
82 first second: ; \@echo \$\@; $sleep_command 4; echo \$\@",
83 '-j2', "first\nfirst\nsecond\nsecond", 0, 28);
85 # Michael Matz <matz@suse.de> reported a bug where if make is running in
86 # parallel without -k and two jobs die in a row, but not too close to each
87 # other, then make will quit without waiting for the rest of the jobs to die.
90 .PHONY: all fail.3 fail.6 fail.9 ok
91 all: fail.3 ok fail.6 fail.9
94 \@$sleep_command \$(patsubst fail.%,%,\$\@)
102 #MAKEFILE#:6: recipe for target 'fail.1' failed
103 #MAKE#: *** [fail.3] Error 1
104 #MAKE#: *** Waiting for unfinished jobs....
106 #MAKEFILE#:6: recipe for target 'fail.2' failed
107 #MAKE#: *** [fail.6] Error 1
109 #MAKEFILE#:6: recipe for target 'fail.3' failed
110 #MAKE#: *** [fail.9] Error 1
115 # Test for Savannah bug #15641.
126 comp: mod_a.o mod_b.o; @:
133 # TEST #9 -- Savannah bugs 3330 and 15919
134 # In earlier versions of make this will either give the wrong answer, or hang.
136 utouch(-10, 'target');
137 run_make_test('target: intermed ; touch $@
139 .INTERMEDIATE: intermed
140 intermed: | phony ; touch $@
143 phony: ; : phony', '-rR -j', ': phony');
146 # TEST #11: Make sure -jN from MAKEFLAGS is processed even when we re-exec
147 # See Savannah bug #33873
149 $extraENV{MAKEFLAGS} = '-j4';
152 things = thing1 thing2
154 thing1:; @sleep 1; echo '$@ start'; sleep 2; echo '$@ end'
155 thing2:; @echo '$@ start'; sleep 2; echo '$@ end'
159 '', "thing2 start\nthing1 start\nthing2 end\nthing1 end\n");
161 delete $extraENV{MAKEFLAGS};
164 # Ensure intermediate/secondary files are not pruned incorrectly.
165 # See Savannah bug #30653
167 utouch(-15, 'file2');
168 utouch(-10, 'file4');
173 file4: file3 ; @mv -f $< $@
174 file3: file2 ; touch $@
175 file2: file1 ; @touch $@
177 '--no-print-directory -j2', "touch file3");
179 rmfiles('file1', 'file2', 'file3', 'file4');
181 # Make sure that all jobserver FDs are closed if we need to re-exec the
184 # First, find the "default" file descriptors we normally use
185 # Then make sure they're still used.
187 # Right now we don't have a way to run a makefile and capture the output
188 # without checking it, so we can't really write this test.
191 # submake: ; @$(MAKE) --no-print-directory -f #MAKEFILE# fdprint 5>output
193 # dependfile: ; @echo FOO=bar > $@
198 # ifeq ($(INCL),true)
199 # -include dependfile
202 # fdprint: ; @echo $(filter --jobserver%,$(MAKEFLAGS))
204 # recurse: ; @$(MAKE) --no-print-directory -f #MAKEFILE# submake INCL=true',
205 # '-j2 INCL=false fdprint',
208 # rmfiles(qw(dependfile output));
211 # # Do it again, this time where the include is done by the non-master make.
212 # run_make_test(undef, '-j2 recurse INCL=false', 'bar');
214 # rmfiles(qw(dependfile output));