Implement new "load" directive.
[make.git] / tests / scripts / features / parallelism
blob08c822e37664c1c5106cde4dfeb731696a27c487
1 #                                                                    -*-perl-*-
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) {
17   return -1;
20 if ($vos) {
21   $sleep_command = "sleep -seconds";
23 else {
24   $sleep_command = "sleep";
28 run_make_test("
29 all : def_1 def_2 def_3
30 def_1 : ; \@echo ONE; $sleep_command 3 ; echo TWO
31 def_2 : ; \@$sleep_command 2 ; echo THREE
32 def_3 : ; \@$sleep_command 1 ; 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
37 # parallel.
38 run_make_test("
39 all: 1 2; \@echo success
40 -include 1.inc 2.inc
41 1.inc: ; \@echo ONE.inc; $sleep_command 2; echo TWO.inc; echo '1: ; \@echo ONE; $sleep_command 2; echo TWO' > \$\@
42 2.inc: ; \@$sleep_command 1; echo THREE.inc; echo '2: ; \@$sleep_command 1; echo THREE' > \$\@",
43               "-j4",
44               "ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n");
46 rmfiles(qw(1.inc 2.inc));
49 # Test parallelism with included files--this time recurse first and make
50 # sure the jobserver works.
51 run_make_test("
52 recurse: ; \@\$(MAKE) --no-print-directory -f #MAKEFILE# INC=yes all
53 all: 1 2; \@echo success
55 INC = no
56 ifeq (\$(INC),yes)
57 -include 1.inc 2.inc
58 endif
60 1.inc: ; \@echo ONE.inc; $sleep_command 2; echo TWO.inc; echo '1: ; \@echo ONE; $sleep_command 2; echo TWO' > \$\@
61 2.inc: ; \@$sleep_command 1; echo THREE.inc; echo '2: ; \@$sleep_command 1; echo THREE' > \$\@",
62               "-j4",
63               "ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n");
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.
74 run_make_test("
75 export HI = \$(shell \$(\$\@.CMD))
76 first.CMD = echo hi
77 second.CMD = $sleep_command 4; echo hi
79 .PHONY: all first second
80 all: first second
82 first second: ; \@echo \$\@; $sleep_command 1; echo \$\@",
83               '-j2', "first\nfirst\nsecond\nsecond", 0, 7);
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.
89 run_make_test("
90 .PHONY: all fail.1 fail.2 fail.3 ok
91 all: fail.1 ok fail.2 fail.3
93 fail.1 fail.2 fail.3:
94         \@sleep \$(patsubst fail.%,%,\$\@)
95         \@echo Fail
96         \@exit 1
98 ok:
99         \@sleep 4
100         \@echo Ok done",
101               '-rR -j5', "Fail
102 #MAKEFILE#:6: recipe for target 'fail.1' failed
103 #MAKE#: *** [fail.1] Error 1
104 #MAKE#: *** Waiting for unfinished jobs....
105 Fail
106 #MAKEFILE#:6: recipe for target 'fail.2' failed
107 #MAKE#: *** [fail.2] Error 1
108 Fail
109 #MAKEFILE#:6: recipe for target 'fail.3' failed
110 #MAKE#: *** [fail.3] Error 1
111 Ok done",
112              512);
115 # Test for Savannah bug #15641.
117 run_make_test('
118 .PHONY: all
119 all:; @:
121 -include foo.d
123 foo.d: comp
124         @echo building $@
126 comp: mod_a.o mod_b.o; @:
128 mod_a.o mod_b.o:
129         @exit 1
130 ', '-j2', '');
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 $@
142 .PHONY: phony
143 phony: ; : phony', '-rR -j', ': phony');
144 rmfiles('target');
146 # TEST #10: Don't put --jobserver-fds into a re-exec'd MAKEFLAGS.
147 # We can't test this directly because there's no way a makefile can
148 # show the value of MAKEFLAGS we were re-exec'd with.  We can intuit it
149 # by looking for "disabling jobserver mode" warnings; we should only
150 # get one from the original invocation and none from the re-exec.
151 # See Savannah bug #18124
153 run_make_test(q!
154 -include inc.mk
155 recur:
156 #       @echo 'MAKEFLAGS = $(MAKEFLAGS)'
157         @rm -f inc.mk
158         @$(MAKE) -j2 -f #MAKEFILE# all
159 all:
160 #       @echo 'MAKEFLAGS = $(MAKEFLAGS)'
161         @echo $@
162 inc.mk:
163 #       @echo 'MAKEFLAGS = $(MAKEFLAGS)'
164         @echo 'FOO = bar' > $@
166               '--no-print-directory -j2', "#MAKE#[1]: warning: -jN forced in submake: disabling jobserver mode.\nall\n");
168 rmfiles('inc.mk');
170 # TEST #11: Make sure -jN from MAKEFLAGS is processed even when we re-exec
171 # See Savannah bug #33873
173 $extraENV{MAKEFLAGS} = '-j4';
175 run_make_test(q!
176 things = thing1 thing2
177 all: $(things)
178 $(things):; @echo '$@ start'; sleep 1; echo '$@ end'
179 -include inc.mk
180 inc.mk: ; @touch $@
182               '', "thing1 start\nthing2 start\nthing1 end\nthing2 end\n");
184 delete $extraENV{MAKEFLAGS};
185 rmfiles('inc.mk');
187 if ($all_tests) {
188     # Implicit files aren't properly recreated during parallel builds
189     # Savannah bug #26864
191     # The first run works fine
192     run_make_test(q!
193 %.bar: %.x foo.y ; cat $^ > $@
194 %.x: ; touch $@
195 foo.y: foo.y.in ; cp $< $@
196 foo.y.in: ; touch $@
198                   '-j2 main.bar',
199                   "touch foo.y.in
200 touch main.x
201 cp foo.y.in foo.y
202 cat main.x foo.y > main.bar
203 rm main.x");
205     # Now we touch the .in file and make sure it still works
206     touch('foo.y.in');
208     run_make_test(undef, '-j2 main.bar', "cp foo.y.in foo.y
209 touch main.x
210 cat main.x foo.y > main.bar
211 rm main.x");
213     # Clean up
214     rmfiles(qw(foo.y foo.y.in main.bar));
217 # Ensure intermediate/secondary files are not pruned incorrectly.
218 # See Savannah bug #30653
220 utouch(-15, 'file2');
221 utouch(-10, 'file4');
222 utouch(-5,  'file1');
224 run_make_test(q!
225 .INTERMEDIATE: file3
226 file4: file3 ; @mv -f $< $@
227 file3: file2 ; touch $@
228 file2: file1 ; @touch $@
230               '--no-print-directory -j2', "touch file3");
232 rmfiles('file1', 'file2', 'file3', 'file4');
234 if ($all_tests) {
235     # Jobserver FD handling is messed up in some way.
236     # Savannah bug #28189
237     # It doesn't look like that bug anymore but this is the code it runs
239     run_make_test(q!
240 ifdef EXTRA
241 vpath %.dst /
242 xxx.dst: ; true
243 yyy.dst: ; true
244 endif
246 M := $(MAKE)
247 xx: ; $M --no-print-directory -j2 -f $(MAKEFILE_LIST) xxx.dst yyy.dst EXTRA=1
249                   '-j2',
250                   '#MAKE#[1]: warning: -jN forced in submake: disabling jobserver mode.
251 true
252 true
256 # Make sure that all jobserver FDs are closed if we need to re-exec the
257 # master copy.
259 # First, find the "default" file descriptors we normally use
260 # Then make sure they're still used.
262 # Right now we don't have a way to run a makefile and capture the output
263 # without checking it, so we can't really write this test.
265 # run_make_test('
266 # submake: ; @$(MAKE) --no-print-directory -f #MAKEFILE# fdprint 5>output
268 # dependfile: ; @echo FOO=bar > $@
270 # INCL := true
272 # FOO=foo
273 # ifeq ($(INCL),true)
274 # -include dependfile
275 # endif
277 # fdprint: ; @echo $(filter --jobserver%,$(MAKEFLAGS))
279 # recurse: ; @$(MAKE) --no-print-directory -f #MAKEFILE# submake INCL=true',
280 #               '-j2 INCL=false fdprint',
281 #               'bar');
283 # rmfiles(qw(dependfile output));
286 # # Do it again, this time where the include is done by the non-master make.
287 # run_make_test(undef, '-j2 recurse INCL=false', 'bar');
289 # rmfiles(qw(dependfile output));