| 1 |
# -*-perl-*- |
| 2 |
|
| 3 |
$description = "Test parallelism (-j) option."; |
| 4 |
$details = ""; |
| 5 |
|
| 6 |
if (!$parallel_jobs) { |
| 7 |
return -1; |
| 8 |
} |
| 9 |
|
| 10 |
run_make_test(q! |
| 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)); |
| 17 |
|
| 18 |
# Verify -j added to MAKEFLAGS in the makefile |
| 19 |
run_make_test(q! |
| 20 |
MAKEFLAGS += -j4 |
| 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)); |
| 27 |
|
| 28 |
# Command line should take precedence |
| 29 |
run_make_test(q! |
| 30 |
MAKEFLAGS += -j2 |
| 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)); |
| 37 |
|
| 38 |
# Test parallelism with included files. Here we sleep/echo while |
| 39 |
# building the included files, to test that they are being built in |
| 40 |
# parallel. |
| 41 |
run_make_test(q! |
| 42 |
all: 1 2; @#HELPER# out success |
| 43 |
-include 1.inc 2.inc |
| 44 |
.RECIPEPREFIX := > |
| 45 |
1.inc: |
| 46 |
> @#HELPER# file ONE.inc wait THREE.inc file TWO.inc |
| 47 |
> @echo '1: ; @#HELPER# file ONE wait THREE file TWO' > $@ |
| 48 |
2.inc: |
| 49 |
> @#HELPER# wait ONE.inc file THREE.inc |
| 50 |
> @echo '2: ; @#HELPER# wait ONE file THREE' > $@!, |
| 51 |
"-j4", |
| 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)); |
| 54 |
|
| 55 |
|
| 56 |
# Test parallelism with included files--this time recurse first and make |
| 57 |
# sure the jobserver works. |
| 58 |
run_make_test(q! |
| 59 |
recurse: ; @$(MAKE) --no-print-directory -f #MAKEFILE# INC=yes all |
| 60 |
all: 1 2; @#HELPER# out success |
| 61 |
|
| 62 |
INC = no |
| 63 |
ifeq ($(INC),yes) |
| 64 |
-include 1.inc 2.inc |
| 65 |
endif |
| 66 |
|
| 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' > $@!, |
| 69 |
"-j4", |
| 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)); |
| 72 |
|
| 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. |
| 78 |
|
| 79 |
run_make_test(q! |
| 80 |
export HI = $(shell $([email protected])) |
| 81 |
first.CMD = #HELPER# out hi |
| 82 |
second.CMD = #HELPER# sleep 4 |
| 83 |
|
| 84 |
.PHONY: all first second |
| 85 |
all: first second |
| 86 |
|
| 87 |
first second: ; @#HELPER# out $@ sleep 1 out $@!, |
| 88 |
'-j2', "first\nsleep 1\nfirst\nsecond\nsleep 1\nsecond", 0); |
| 89 |
|
| 90 |
# Michael Matz <[email protected]> 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. |
| 93 |
|
| 94 |
run_make_test(q! |
| 95 |
.PHONY: all fail.1 fail.2 fail.3 ok |
| 96 |
all: fail.1 ok fail.2 fail.3 |
| 97 |
|
| 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 |
| 101 |
|
| 102 |
ok: ; @#HELPER# -q sleep 4 wait fail.3 out OK!, |
| 103 |
'-rR -j5', "fail.1 |
| 104 |
#MAKE#: *** [#MAKEFILE#:5: fail.1] Error 1 |
| 105 |
#MAKE#: *** Waiting for unfinished jobs.... |
| 106 |
fail.2 |
| 107 |
#MAKE#: *** [#MAKEFILE#:6: fail.2] Error 1 |
| 108 |
fail.3 |
| 109 |
#MAKE#: *** [#MAKEFILE#:7: fail.3] Error 1 |
| 110 |
OK", |
| 111 |
512); |
| 112 |
|
| 113 |
rmfiles(qw(fail.1 fail.2 fail.3)); |
| 114 |
|
| 115 |
# Test for Savannah bug #15641. |
| 116 |
# |
| 117 |
run_make_test(' |
| 118 |
.PHONY: all |
| 119 |
all:; @: |
| 120 |
|
| 121 |
-include foo.d |
| 122 |
|
| 123 |
foo.d: comp ; @#HELPER# out $@ |
| 124 |
|
| 125 |
comp: mod_a.o mod_b.o; @: |
| 126 |
|
| 127 |
mod_a.o mod_b.o: ; @#HELPER# fail 1 |
| 128 |
', '-j2', "fail 1\nfail 1\n"); |
| 129 |
|
| 130 |
|
| 131 |
# TEST #9 -- Savannah bugs 3330 and 15919 |
| 132 |
# In earlier versions of make this will either give the wrong answer, or hang. |
| 133 |
|
| 134 |
utouch(-10, 'target'); |
| 135 |
run_make_test('target: intermed ; #HELPER# file $@ |
| 136 |
|
| 137 |
.INTERMEDIATE: intermed |
| 138 |
intermed: | phony ; #HELPER# file $@ |
| 139 |
|
| 140 |
.PHONY: phony |
| 141 |
phony: ; : phony', '-rR -j', ': phony'); |
| 142 |
rmfiles('target'); |
| 143 |
|
| 144 |
# TEST #11: Make sure -jN from MAKEFLAGS is processed even when we re-exec |
| 145 |
# See Savannah bug #33873 |
| 146 |
|
| 147 |
$ENV{MAKEFLAGS} = '-j4'; |
| 148 |
|
| 149 |
run_make_test(q! |
| 150 |
things = thing1 thing2 |
| 151 |
all: $(things) |
| 152 |
thing1:; @#HELPER# wait thing2start file $@start wait thing2end out $@end |
| 153 |
thing2:; @#HELPER# file $@start wait thing1start file $@end |
| 154 |
-include inc.mk |
| 155 |
inc.mk: ; @touch $@ |
| 156 |
!, |
| 157 |
'', "file thing2start\nwait thing2start\nfile thing1start\nwait thing1start\nfile thing2end\nwait thing2end\nthing1end\n"); |
| 158 |
|
| 159 |
rmfiles(qw(inc.mk thing1start thing1end thing2start thing2end)); |
| 160 |
|
| 161 |
# Ensure intermediate/secondary files are not pruned incorrectly. |
| 162 |
# See Savannah bug #30653 |
| 163 |
|
| 164 |
utouch(-15, 'file2'); |
| 165 |
utouch(-10, 'file4'); |
| 166 |
utouch(-5, 'file1'); |
| 167 |
|
| 168 |
run_make_test(q! |
| 169 |
.INTERMEDIATE: file3 |
| 170 |
file4: file3 ; @mv -f $< $@ |
| 171 |
file3: file2 ; touch $@ |
| 172 |
file2: file1 ; @touch $@ |
| 173 |
!, |
| 174 |
'--no-print-directory -j2', "touch file3"); |
| 175 |
|
| 176 |
rmfiles('file1', 'file2', 'file3', 'file4'); |
| 177 |
|
| 178 |
# Ensure that the jobserver is preserved across make re-exec. |
| 179 |
|
| 180 |
run_make_test(q! |
| 181 |
all: one two |
| 182 |
one: ;@ #HELPER# wait TWO file ONE |
| 183 |
two: ;@ #HELPER# file TWO |
| 184 |
include fff1.mk |
| 185 |
fff1.mk: ; touch $@ |
| 186 |
!, |
| 187 |
'-j2', "touch fff1.mk\nfile TWO\nwait TWO\nfile ONE\n"); |
| 188 |
|
| 189 |
rmfiles('fff1.mk', 'ONE', 'TWO'); |
| 190 |
|
| 191 |
# Test if a sub-make needs to re-exec and the makefile is built via |
| 192 |
# sub-make. Reported by Masahiro Yamada <[email protected]> |
| 193 |
|
| 194 |
run_make_test(q! |
| 195 |
all: ; @$(MAKE) -f #MAKEFILE# recurse |
| 196 |
|
| 197 |
recurse: one two ; @#HELPER# out $@ |
| 198 |
one: ;@ #HELPER# wait TWO file ONE |
| 199 |
two: ;@ #HELPER# file TWO |
| 200 |
|
| 201 |
mkinclude: ; touch fff1.mk |
| 202 |
|
| 203 |
ifeq ($(MAKECMDGOALS),recurse) |
| 204 |
include fff1.mk |
| 205 |
fff1.mk: ; @$(MAKE) -f #MAKEFILE# mkinclude |
| 206 |
endif |
| 207 |
!, |
| 208 |
'--no-print-directory -j2', "touch fff1.mk\nfile TWO\nwait TWO\nfile ONE\nrecurse\n"); |
| 209 |
|
| 210 |
rmfiles('fff1.mk', 'ONE', 'TWO'); |
| 211 |
|
| 212 |
|
| 213 |
# Make sure that all jobserver FDs are closed if we need to re-exec the |
| 214 |
# master copy. |
| 215 |
# |
| 216 |
# First, find the "default" file descriptors we normally use |
| 217 |
# Then make sure they're still used. |
| 218 |
# |
| 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. |
| 221 |
|
| 222 |
# run_make_test(' |
| 223 |
# submake: ; @$(MAKE) --no-print-directory -f #MAKEFILE# fdprint 5>output |
| 224 |
|
| 225 |
# dependfile: ; @echo FOO=bar > $@ |
| 226 |
|
| 227 |
# INCL := true |
| 228 |
|
| 229 |
# FOO=foo |
| 230 |
# ifeq ($(INCL),true) |
| 231 |
# -include dependfile |
| 232 |
# endif |
| 233 |
|
| 234 |
# fdprint: ; @echo $(filter --jobserver%,$(MAKEFLAGS)) |
| 235 |
|
| 236 |
# recurse: ; @$(MAKE) --no-print-directory -f #MAKEFILE# submake INCL=true', |
| 237 |
# '-j2 INCL=false fdprint', |
| 238 |
# 'bar'); |
| 239 |
|
| 240 |
# rmfiles(qw(dependfile output)); |
| 241 |
|
| 242 |
|
| 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'); |
| 245 |
|
| 246 |
# rmfiles(qw(dependfile output)); |
| 247 |
|
| 248 |
1; |