3 $description = "Test parallelism (-j) option.";
11 all : def_1 def_2 def_3
12 def_1 : ; @#HELPER# file ONE wait THREE out TWO
13 def_2 : ; @#HELPER# wait FOUR file THREE
14 def_3 : ; @#HELPER# wait ONE file FOUR!,
15 '-j4', "file ONE\nwait ONE\nfile FOUR\nwait FOUR\nfile THREE\nwait THREE\nTWO");
16 rmfiles(qw(ONE TWO THREE FOUR));
18 # Verify -j added to MAKEFLAGS in the makefile
21 all : def_1 def_2 def_3
22 def_1 : ; @#HELPER# file ONE wait THREE out TWO
23 def_2 : ; @#HELPER# wait FOUR file THREE
24 def_3 : ; @#HELPER# wait ONE file FOUR!,
25 '', "file ONE\nwait ONE\nfile FOUR\nwait FOUR\nfile THREE\nwait THREE\nTWO");
26 rmfiles(qw(ONE TWO THREE FOUR));
28 # Command line should take precedence
31 all : def_1 def_2 def_3
32 def_1 : ; @#HELPER# file ONE wait THREE out TWO
33 def_2 : ; @#HELPER# wait FOUR file THREE
34 def_3 : ; @#HELPER# wait ONE file FOUR!,
35 '-j4', "file ONE\nwait ONE\nfile FOUR\nwait FOUR\nfile THREE\nwait THREE\nTWO");
36 rmfiles(qw(ONE TWO THREE FOUR));
38 # Test parallelism with included files. Here we sleep/echo while
39 # building the included files, to test that they are being built in
42 all: 1 2; @#HELPER# out success
46 > @#HELPER# file ONE.inc wait THREE.inc file TWO.inc
47 > @echo '1: ; @#HELPER# file ONE wait THREE file TWO' > $@
49 > @#HELPER# wait ONE.inc file THREE.inc
50 > @echo '2: ; @#HELPER# wait ONE file THREE' > $@!,
52 "file ONE.inc\nwait ONE.inc\nfile THREE.inc\nwait THREE.inc\nfile TWO.inc\nfile ONE\nwait ONE\nfile THREE\nwait THREE\nfile TWO\nsuccess\n", 0, 7);
53 rmfiles(qw(ONE.inc TWO.inc THREE.inc ONE TWO THREE 1.inc 2.inc));
56 # Test parallelism with included files--this time recurse first and make
57 # sure the jobserver works.
59 recurse: ; @$(MAKE) --no-print-directory -f #MAKEFILE# INC=yes all
60 all: 1 2; @#HELPER# out success
67 1.inc: ; @#HELPER# file ONE.inc wait THREE.inc file TWO.inc; echo '1: ; @#HELPER# file ONE wait THREE file TWO' > $@
68 2.inc: ; @#HELPER# wait ONE.inc file THREE.inc; echo '2: ; @#HELPER# wait ONE file THREE' > $@!,
70 "file ONE.inc\nwait ONE.inc\nfile THREE.inc\nwait THREE.inc\nfile TWO.inc\nfile ONE\nwait ONE\nfile THREE\nwait THREE\nfile TWO\nsuccess\n", 0, 7);
71 rmfiles(qw(ONE.inc TWO.inc THREE.inc ONE TWO THREE 1.inc 2.inc));
73 # Grant Taylor reports a problem where tokens can be lost (not written back
74 # to the pipe when they should be): this happened when there is a $(shell ...)
75 # function in an exported recursive variable. I added some code to check
76 # for this situation and print a message if it occurred. This test used
77 # to trigger this code when I added it but no longer does after the fix.
80 export HI = $(shell $($@.CMD))
81 first.CMD = #HELPER# out hi
82 second.CMD = #HELPER# sleep 4
84 .PHONY: all first second
87 first second: ; @#HELPER# out $@ sleep 1 out $@!,
88 '-j2', "first\nsleep 1\nfirst\nsecond\nsleep 1\nsecond", 0);
90 # Michael Matz <matz@suse.de> reported a bug where if make is running in
91 # parallel without -k and two jobs die in a row, but not too close to each
92 # other, then make will quit without waiting for the rest of the jobs to die.
95 .PHONY: all fail.1 fail.2 fail.3 ok
96 all: fail.1 ok fail.2 fail.3
98 fail.1: ; @#HELPER# -q sleep 1 out $@ file fail.1 fail 1
99 fail.2: ; @#HELPER# -q sleep 2 out $@ wait fail.1 file fail.2 fail 1
100 fail.3: ; @#HELPER# -q sleep 3 out $@ wait fail.2 file fail.3 fail 1
102 ok: ; @#HELPER# -q sleep 4 wait fail.3 out OK!,
103 '-rR -j5', "fail.1\nfail 1
104 #MAKE#: *** [#MAKEFILE#:5: fail.1] Error 1
105 #MAKE#: *** Waiting for unfinished jobs....
107 #MAKE#: *** [#MAKEFILE#:6: fail.2] Error 1
109 #MAKE#: *** [#MAKEFILE#:7: fail.3] Error 1
113 rmfiles(qw(fail.1 fail.2 fail.3));
115 # Test for Savannah bug #15641.
123 foo.d: comp ; @#HELPER# out $@
125 comp: mod_a.o mod_b.o; @:
127 mod_a.o mod_b.o: ; @#HELPER# fail 1
128 ', '-j2', "fail 1\nfail 1\n");
131 # TEST #9 -- Savannah bugs 3330 and 15919
132 # In earlier versions of make this will either give the wrong answer, or hang.
134 utouch(-10, 'target');
135 run_make_test('target: intermed ; #HELPER# file $@
137 .INTERMEDIATE: intermed
138 intermed: | phony ; #HELPER# file $@
141 phony: ; : phony', '-rR -j', ': phony');
144 # TEST #11: Make sure -jN from MAKEFLAGS is processed even when we re-exec
145 # See Savannah bug #33873
147 $ENV{MAKEFLAGS} = '-j4';
150 things = thing1 thing2
152 thing1:; @#HELPER# wait thing2start file $@start wait thing2end out $@end
153 thing2:; @#HELPER# file $@start wait thing1start file $@end
157 '', "file thing2start\nwait thing2start\nfile thing1start\nwait thing1start\nfile thing2end\nwait thing2end\nthing1end\n");
159 rmfiles(qw(inc.mk thing1start thing1end thing2start thing2end));
161 # Ensure intermediate/secondary files are not pruned incorrectly.
162 # See Savannah bug #30653
164 utouch(-15, 'file2');
165 utouch(-10, 'file4');
170 file4: file3 ; @mv -f $< $@
171 file3: file2 ; touch $@
172 file2: file1 ; @touch $@
174 '--no-print-directory -j2', "touch file3");
176 rmfiles('file1', 'file2', 'file3', 'file4');
178 # Ensure that the jobserver is preserved across make re-exec.
182 one: ;@ #HELPER# wait TWO file ONE
183 two: ;@ #HELPER# file TWO
187 '-j2', "touch fff1.mk\nfile TWO\nwait TWO\nfile ONE\n");
189 rmfiles('fff1.mk', 'ONE', 'TWO');
191 # Test if a sub-make needs to re-exec and the makefile is built via
192 # sub-make. Reported by Masahiro Yamada <yamada.masahiro@socionext.com>
195 all: ; @$(MAKE) -f #MAKEFILE# recurse
197 recurse: one two ; @#HELPER# out $@
198 one: ;@ #HELPER# wait TWO file ONE
199 two: ;@ #HELPER# file TWO
201 mkinclude: ; touch fff1.mk
203 ifeq ($(MAKECMDGOALS),recurse)
205 fff1.mk: ; @$(MAKE) -f #MAKEFILE# mkinclude
208 '--no-print-directory -j2', "touch fff1.mk\nfile TWO\nwait TWO\nfile ONE\nrecurse\n");
210 rmfiles('fff1.mk', 'ONE', 'TWO');
213 # Make sure that all jobserver FDs are closed if we need to re-exec the
216 # First, find the "default" file descriptors we normally use
217 # Then make sure they're still used.
219 # Right now we don't have a way to run a makefile and capture the output
220 # without checking it, so we can't really write this test.
223 # submake: ; @$(MAKE) --no-print-directory -f #MAKEFILE# fdprint 5>output
225 # dependfile: ; @echo FOO=bar > $@
230 # ifeq ($(INCL),true)
231 # -include dependfile
234 # fdprint: ; @echo $(filter --jobserver%,$(MAKEFLAGS))
236 # recurse: ; @$(MAKE) --no-print-directory -f #MAKEFILE# submake INCL=true',
237 # '-j2 INCL=false fdprint',
240 # rmfiles(qw(dependfile output));
243 # # Do it again, this time where the include is done by the non-master make.
244 # run_make_test(undef, '-j2 recurse INCL=false', 'bar');
246 # rmfiles(qw(dependfile output));