| 1 |
# -*-perl-*- |
| 2 |
|
| 3 |
$description = "Test --output-sync (-O) option."; |
| 4 |
|
| 5 |
$details = "Test the synchronization of output from parallel jobs."; |
| 6 |
|
| 7 |
# If we don't have output sync support, never mind. |
| 8 |
exists $FEATURES{'output-sync'} or return -1; |
| 9 |
|
| 10 |
# Output sync can't be tested without parallelization |
| 11 |
$parallel_jobs or return -1; |
| 12 |
|
| 13 |
|
| 14 |
# The following subdirectories with Makefiles are used in several |
| 15 |
# of the following tests. The model is: |
| 16 |
# foo/Makefile - has a "foo" target that waits for the bar target |
| 17 |
# bar/Makefile - has a "bar" target that runs immediately |
| 18 |
# - has a "baz" target that waits for the foo target |
| 19 |
# |
| 20 |
# So, you start the two sub-makes in parallel and first the "bar" target is |
| 21 |
# built, followed by "foo", followed by "baz". The trick is that first each |
| 22 |
# target prints a "start" statement, then waits (if appropriate), then prints |
| 23 |
# an end statement. Thus we can tell if the -O flag is working, since |
| 24 |
# otherwise these statements would be mixed together. |
| 25 |
|
| 26 |
@syncfiles = (); |
| 27 |
|
| 28 |
sub output_sync_clean { |
| 29 |
rmfiles('foo/Makefile', 'bar/Makefile', @syncfiles); |
| 30 |
rmdir('foo'); |
| 31 |
rmdir('bar'); |
| 32 |
} |
| 33 |
|
| 34 |
# We synchronize the different jobs by having them wait for a sentinel file to |
| 35 |
# be created, instead of relying on a certain amount of time passing. |
| 36 |
# Unfortunately in this test we have to sleep after we see the sync file, |
| 37 |
# since we also want to make the obtaining of the write synchronization lock |
| 38 |
# reliable. If things are too fast, then sometimes a different job will steal |
| 39 |
# the output sync lock and the output is mis-ordered from what we expect. |
| 40 |
sub output_sync_wait { |
| 41 |
return subst_make_string("#HELPER# \$Q wait ../mksync.$_[0] sleep 1"); |
| 42 |
} |
| 43 |
sub output_sync_set { |
| 44 |
return subst_make_string("#HELPER# \$Q file ../mksync.$_[0]"); |
| 45 |
} |
| 46 |
|
| 47 |
@syncfiles = qw(mksync.foo mksync.foo_start mksync.bar mksync.bar_start); |
| 48 |
|
| 49 |
$tmout = 30; |
| 50 |
|
| 51 |
output_sync_clean(); |
| 52 |
mkdir('foo', 0777); |
| 53 |
mkdir('bar', 0777); |
| 54 |
|
| 55 |
$set_foo = output_sync_set('foo'); |
| 56 |
$set_bar = output_sync_set('bar'); |
| 57 |
$set_foo_start = output_sync_set('foo_start'); |
| 58 |
$set_bar_start = output_sync_set('bar_start'); |
| 59 |
|
| 60 |
$wait_foo = output_sync_wait('foo'); |
| 61 |
$wait_bar = output_sync_wait('bar'); |
| 62 |
$wait_foo_start = output_sync_set('foo_start'); |
| 63 |
$wait_bar_start = output_sync_set('bar_start'); |
| 64 |
|
| 65 |
open(MAKEFILE,"> foo/Makefile"); |
| 66 |
print MAKEFILE <<EOF; |
| 67 |
all: foo |
| 68 |
|
| 69 |
foo: foo-base ; $set_foo |
| 70 |
|
| 71 |
foo-base: |
| 72 |
\t\@echo foo: start |
| 73 |
\t$wait_bar |
| 74 |
\t\@echo foo: end |
| 75 |
|
| 76 |
foo-job: foo-job-base ; $set_foo |
| 77 |
|
| 78 |
foo-job-base: |
| 79 |
\t$wait_bar_start |
| 80 |
\t\@echo foo: start |
| 81 |
\t$set_foo_start |
| 82 |
\t$wait_bar |
| 83 |
\t\@echo foo: end |
| 84 |
|
| 85 |
foo-fail: |
| 86 |
\t\@echo foo-fail: start |
| 87 |
\t$wait_bar |
| 88 |
\t\@echo foo-fail: end |
| 89 |
\texit 1 |
| 90 |
|
| 91 |
V := |
| 92 |
\$V.SILENT: |
| 93 |
Q := |
| 94 |
\$VQ := -q |
| 95 |
EOF |
| 96 |
close(MAKEFILE); |
| 97 |
|
| 98 |
open(MAKEFILE,"> bar/Makefile"); |
| 99 |
print MAKEFILE <<EOF; |
| 100 |
all: bar baz |
| 101 |
|
| 102 |
bar: bar-base ; $set_bar |
| 103 |
bar-base: |
| 104 |
\t\@echo bar: start |
| 105 |
\t\@echo bar: end |
| 106 |
|
| 107 |
bar-job: bar-job-base ; $set_bar |
| 108 |
|
| 109 |
bar-job-base: |
| 110 |
\t\@echo bar: start |
| 111 |
\t$set_bar_start |
| 112 |
\t$wait_foo_start |
| 113 |
\t\@echo bar: end |
| 114 |
|
| 115 |
baz: baz-base |
| 116 |
baz-base: |
| 117 |
\t\@echo baz: start |
| 118 |
\t$wait_foo |
| 119 |
\t\@echo baz: end |
| 120 |
|
| 121 |
V := |
| 122 |
\$V.SILENT: |
| 123 |
Q := |
| 124 |
\$VQ := -q |
| 125 |
EOF |
| 126 |
close(MAKEFILE); |
| 127 |
|
| 128 |
# Test per-make synchronization. |
| 129 |
# Note we have to sleep again here after starting the foo makefile before |
| 130 |
# starting the bar makefile, otherwise the "entering/leaving" messages for the |
| 131 |
# submakes might be ordered differently than we expect. |
| 132 |
|
| 133 |
unlink(@syncfiles); |
| 134 |
run_make_test(qq! |
| 135 |
all: make-foo make-bar |
| 136 |
|
| 137 |
make-foo: ; \$(MAKE) -C foo |
| 138 |
|
| 139 |
make-bar: ; #HELPER# -q sleep 1 ; \$(MAKE) -C bar!, |
| 140 |
'-j -Orecurse', |
| 141 |
"#MAKEPATH# -C foo |
| 142 |
#MAKE#[1]: Entering directory '#PWD#/foo' |
| 143 |
foo: start |
| 144 |
foo: end |
| 145 |
#MAKE#[1]: Leaving directory '#PWD#/foo' |
| 146 |
#HELPER# -q sleep 1 ; #MAKEPATH# -C bar |
| 147 |
#MAKE#[1]: Entering directory '#PWD#/bar' |
| 148 |
bar: start |
| 149 |
bar: end |
| 150 |
baz: start |
| 151 |
baz: end |
| 152 |
#MAKE#[1]: Leaving directory '#PWD#/bar'\n", 0, $tmout); |
| 153 |
|
| 154 |
# Test per-target synchronization. |
| 155 |
# Note we have to sleep again here after starting the foo makefile before |
| 156 |
# starting the bar makefile, otherwise the "entering/leaving" messages for the |
| 157 |
# submakes might be ordered differently than we expect. |
| 158 |
|
| 159 |
unlink(@syncfiles); |
| 160 |
run_make_test(qq! |
| 161 |
x=1 |
| 162 |
\$xMAKEFLAGS += --no-print-directory |
| 163 |
|
| 164 |
all: make-foo make-bar |
| 165 |
|
| 166 |
make-foo: ; \$(MAKE) -C foo |
| 167 |
|
| 168 |
make-bar: ; #HELPER# -q sleep 1 ; \$(MAKE) -C bar!, |
| 169 |
'-j --output-sync=target', |
| 170 |
"#MAKEPATH# -C foo |
| 171 |
#HELPER# -q sleep 1 ; #MAKEPATH# -C bar |
| 172 |
#MAKE#[1]: Entering directory '#PWD#/bar' |
| 173 |
bar: start |
| 174 |
bar: end |
| 175 |
#MAKE#[1]: Leaving directory '#PWD#/bar' |
| 176 |
#MAKE#[1]: Entering directory '#PWD#/foo' |
| 177 |
foo: start |
| 178 |
foo: end |
| 179 |
#MAKE#[1]: Leaving directory '#PWD#/foo' |
| 180 |
#MAKE#[1]: Entering directory '#PWD#/bar' |
| 181 |
baz: start |
| 182 |
baz: end |
| 183 |
#MAKE#[1]: Leaving directory '#PWD#/bar'\n", 0, $tmout); |
| 184 |
|
| 185 |
# Rerun but this time suppress the directory tracking |
| 186 |
unlink(@syncfiles); |
| 187 |
run_make_test(undef, '-j --output-sync=target x=', |
| 188 |
"#MAKEPATH# -C foo |
| 189 |
#HELPER# -q sleep 1 ; #MAKEPATH# -C bar |
| 190 |
bar: start |
| 191 |
bar: end |
| 192 |
foo: start |
| 193 |
foo: end |
| 194 |
baz: start |
| 195 |
baz: end\n", 0, $tmout); |
| 196 |
|
| 197 |
# Test that messages from make itself are enclosed with |
| 198 |
# "Entering/Leaving directory" messages. |
| 199 |
unlink(@syncfiles); |
| 200 |
run_make_test(qq! |
| 201 |
all: make-foo-fail make-bar-bar |
| 202 |
|
| 203 |
make-foo-fail: ; \$(MAKE) -C foo foo-fail |
| 204 |
|
| 205 |
make-bar-bar: ; #HELPER# -q sleep 1 ; \$(MAKE) -C bar bar!, |
| 206 |
'-j -O', |
| 207 |
"#MAKEPATH# -C foo foo-fail |
| 208 |
#HELPER# -q sleep 1 ; #MAKEPATH# -C bar bar |
| 209 |
#MAKE#[1]: Entering directory '#PWD#/bar' |
| 210 |
bar: start |
| 211 |
bar: end |
| 212 |
#MAKE#[1]: Leaving directory '#PWD#/bar' |
| 213 |
#MAKE#[1]: Entering directory '#PWD#/foo' |
| 214 |
foo-fail: start |
| 215 |
foo-fail: end |
| 216 |
#MAKE#[1]: *** [Makefile:23: foo-fail] Error 1 |
| 217 |
#MAKE#[1]: Leaving directory '#PWD#/foo' |
| 218 |
#MAKE#: *** [#MAKEFILE#:4: make-foo-fail] Error 2\n", |
| 219 |
512); |
| 220 |
|
| 221 |
# Test the per-job synchronization. |
| 222 |
# For this we'll have bar-job: |
| 223 |
# print start, invoke bar-start, wait for foo-start, print end, print-bar-end |
| 224 |
# And foo-job: |
| 225 |
# wait for bar-start, print foo-start, wait for bar-end, print end |
| 226 |
|
| 227 |
unlink(@syncfiles); |
| 228 |
run_make_test(qq! |
| 229 |
all: make-foo make-bar |
| 230 |
|
| 231 |
make-foo: ; \$(MAKE) -C foo foo-job |
| 232 |
|
| 233 |
make-bar: ; #HELPER# -q sleep 1 ; \$(MAKE) -C bar bar-job!, |
| 234 |
'-j --output-sync=line', |
| 235 |
"#MAKEPATH# -C foo foo-job |
| 236 |
#HELPER# -q sleep 1 ; #MAKEPATH# -C bar bar-job |
| 237 |
#MAKE#[1]: Entering directory '#PWD#/foo' |
| 238 |
foo: start |
| 239 |
#MAKE#[1]: Leaving directory '#PWD#/foo' |
| 240 |
#MAKE#[1]: Entering directory '#PWD#/bar' |
| 241 |
bar: start |
| 242 |
#MAKE#[1]: Leaving directory '#PWD#/bar' |
| 243 |
#MAKE#[1]: Entering directory '#PWD#/bar' |
| 244 |
bar: end |
| 245 |
#MAKE#[1]: Leaving directory '#PWD#/bar' |
| 246 |
#MAKE#[1]: Entering directory '#PWD#/foo' |
| 247 |
foo: end |
| 248 |
#MAKE#[1]: Leaving directory '#PWD#/foo'\n", 0, $tmout); |
| 249 |
|
| 250 |
# Remove temporary directories and contents. |
| 251 |
output_sync_clean(); |
| 252 |
|
| 253 |
# Ensure recursion doesn't mis-order or double-print output |
| 254 |
run_make_test(qq! |
| 255 |
all: |
| 256 |
\t\@echo foo |
| 257 |
\t\@+echo bar |
| 258 |
!, |
| 259 |
'-j -Oline', "foo\nbar\n"); |
| 260 |
|
| 261 |
run_make_test(undef, '-j -Otarget', "foo\nbar\n"); |
| 262 |
|
| 263 |
# Ensure when make writes out command it's not misordered |
| 264 |
run_make_test(qq! |
| 265 |
all: |
| 266 |
\t\@echo foobar |
| 267 |
\ttrue |
| 268 |
!, |
| 269 |
'-j -Oline', "foobar\ntrue\n"); |
| 270 |
|
| 271 |
run_make_test(undef, '-j -Otarget', "foobar\ntrue\n"); |
| 272 |
|
| 273 |
# Ensure that shell functions inside recipes write stderr to the sync file |
| 274 |
run_make_test(q! |
| 275 |
all: ; @: $(shell echo foo 1>&2) |
| 276 |
!, |
| 277 |
'-w -Oline', "#MAKE#: Entering directory '#PWD#'\nfoo\n#MAKE#: Leaving directory '#PWD#'\n"); |
| 278 |
|
| 279 |
# Ensure that output generated while parsing makefiles is synced |
| 280 |
# when appropriate. |
| 281 |
run_make_test(q! |
| 282 |
$(shell echo foo 1>&2) |
| 283 |
all: ; echo bar |
| 284 |
!, |
| 285 |
'-s -w -Otarget', "#MAKE#: Entering directory '#PWD#'\nfoo\n#MAKE#: Leaving directory '#PWD#'\n#MAKE#: Entering directory '#PWD#'\nbar\n#MAKE#: Leaving directory '#PWD#'\n"); |
| 286 |
|
| 287 |
# Test recursion |
| 288 |
$m1 = get_tmpfile(); |
| 289 |
$m2 = get_tmpfile(); |
| 290 |
|
| 291 |
open(M1, "> $m1"); |
| 292 |
print M1 <<'EOF'; |
| 293 |
$(shell echo d1 stderr 1>&2) |
| 294 |
$(info d1 stdout) |
| 295 |
all:; @: |
| 296 |
EOF |
| 297 |
close(M1); |
| 298 |
|
| 299 |
open(M2, "> $m2"); |
| 300 |
print M2 <<'EOF'; |
| 301 |
$(shell echo d2 stderr 1>&2) |
| 302 |
$(info d2 stdout) |
| 303 |
all:; @: |
| 304 |
# Force an ordering on the output |
| 305 |
$(shell sleep 1) |
| 306 |
EOF |
| 307 |
close(M2); |
| 308 |
|
| 309 |
run_make_test(qq! |
| 310 |
all: t1 t2 |
| 311 |
t1: ; \@\$(MAKE) -f $m1 |
| 312 |
t2: ; \@\$(MAKE) -f $m2 |
| 313 |
!, |
| 314 |
"-j -Oline", "#MAKE#[1]: Entering directory '#PWD#'\nd1 stderr\nd1 stdout\n#MAKE#[1]: Leaving directory '#PWD#'\n#MAKE#[1]: Entering directory '#PWD#'\nd2 stderr\nd2 stdout\n#MAKE#[1]: Leaving directory '#PWD#'\n"); |
| 315 |
|
| 316 |
rmfiles($m1, $m2); |
| 317 |
|
| 318 |
# Ensure that output generated while parsing makefiles is synced |
| 319 |
# when appropriate. |
| 320 |
$m1 = get_tmpfile(); |
| 321 |
|
| 322 |
open(M1, "> $m1"); |
| 323 |
print M1 <<'EOF'; |
| 324 |
$(shell echo d1 stderr 1>&2) |
| 325 |
$(info d1 stdout) |
| 326 |
$(error d1 failed) |
| 327 |
all:; @: |
| 328 |
EOF |
| 329 |
close(M1); |
| 330 |
|
| 331 |
run_make_test(qq! |
| 332 |
all: t1 |
| 333 |
t1: ; -\@\$(MAKE) -f $m1 |
| 334 |
!, |
| 335 |
"-j -Oline", "#MAKE#[1]: Entering directory '#PWD#'\nd1 stderr\nd1 stdout\n$m1:3: *** d1 failed. Stop.\n#MAKE#[1]: Leaving directory '#PWD#'\n#MAKE#: [#MAKEFILE#:3: t1] Error 2 (ignored)\n"); |
| 336 |
|
| 337 |
rmfiles($m1); |
| 338 |
|
| 339 |
# Test $(error ...) functions in recipes |
| 340 |
|
| 341 |
run_make_test(q! |
| 342 |
foo: $(OBJS) ; echo $(or $(filter %.o,$^),$(error fail)) |
| 343 |
!, |
| 344 |
'-O', "#MAKEFILE#:2: *** fail. Stop.\n", 512); |
| 345 |
|
| 346 |
# SV 47365: Make sure exec failure error messages are shown |
| 347 |
# Needs to be ported to Windows |
| 348 |
if ($port_type ne 'W32') { |
| 349 |
run_make_test(q! |
| 350 |
all:: ; @./foo bar baz |
| 351 |
!, |
| 352 |
'-O', "#MAKE#: ./foo: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:2: all] Error 127\n", 512); |
| 353 |
} |
| 354 |
|
| 355 |
if ($port_type eq 'UNIX') { |
| 356 |
# POSIX doesn't require sh to set PPID so test this |
| 357 |
my $cmd = create_command(); |
| 358 |
add_options($cmd, '-f', '/dev/null', '-E', q!all:;@echo $$PPID!); |
| 359 |
my $fout = 'ppidtest.out'; |
| 360 |
run_command_with_output($fout, @$cmd); |
| 361 |
$_ = read_file_into_string($fout); |
| 362 |
s/\r?\n//g; |
| 363 |
if (/^[0-9]+$/) { |
| 364 |
use POSIX (); |
| 365 |
# SV 63157. |
| 366 |
# Test that make removes temporary files, even when a signal is received. The |
| 367 |
# general test_driver postprocessing will ensure the temporary file used to |
| 368 |
# synchronize output and the jobserver fifo are both removed. sleep is needed |
| 369 |
# to let make write its "... Terminated" message to the log file. Must use |
| 370 |
# REGEX because some systems (MacOS) add extra text after Terminated. |
| 371 |
run_make_test(q! |
| 372 |
pid:=$(shell echo $$PPID) |
| 373 |
all:; @#HELPER# -q term $(pid) sleep 10 |
| 374 |
!, '-O -j2', '/#MAKE#: \*\*\* \[#MAKEFILE#:3: all] Terminated/', POSIX::SIGTERM); |
| 375 |
} |
| 376 |
unlink($fout); |
| 377 |
|
| 378 |
# SV 63333. Test that make continues to run without output sync when we |
| 379 |
# cannot create a temporary file. |
| 380 |
# Create a non-writable temporary directory. |
| 381 |
# Run the test twice, because run_make_test cannot match a regex against a |
| 382 |
# multiline input. |
| 383 |
my $tdir = 'test_tmp_dir'; |
| 384 |
mkdir($tdir, 0500); |
| 385 |
$ENV{'TMPDIR'} = $tdir; |
| 386 |
|
| 387 |
run_make_test(q! |
| 388 |
all:; $(info hello, world) |
| 389 |
!, '-Orecurse', "/suppressing output-sync/"); |
| 390 |
|
| 391 |
run_make_test(undef, '-Orecurse', "/#MAKE#: 'all' is up to date./"); |
| 392 |
|
| 393 |
rmdir($tdir); |
| 394 |
} |
| 395 |
|
| 396 |
# This tells the test driver that the perl test script executed properly. |
| 397 |
1; |