2013-04-14 19:38:07 +00:00
|
|
|
# -*-perl-*-
|
|
|
|
|
2013-04-14 20:31:18 +00:00
|
|
|
$description = "Test --output-sync (-O) option.";
|
2013-04-14 19:38:07 +00:00
|
|
|
|
|
|
|
$details = "Test the synchronization of output from parallel jobs.";
|
|
|
|
|
|
|
|
if (!$parallel_jobs) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($vos) {
|
|
|
|
$sleep_command = "sleep -seconds";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$sleep_command = "sleep";
|
|
|
|
}
|
|
|
|
|
2013-04-28 05:19:19 +00:00
|
|
|
# The following subdirectories with Makefiles are used in several
|
|
|
|
# of the following tests. The model is:
|
|
|
|
# foo/Makefile - has a "foo" target that waits for the bar target
|
|
|
|
# bar/Makefile - has a "bar" target that runs immediately
|
|
|
|
# - has a "baz" target that waits for the foo target
|
|
|
|
#
|
|
|
|
# So, you start the two sub-makes in parallel and first the "bar" target is
|
|
|
|
# built, followed by "foo", followed by "baz". The trick is that first each
|
|
|
|
# target prints a "start" statement, then waits (if appropriate), then prints
|
|
|
|
# an end statement. Thus we can tell if the -O flag is working, since
|
|
|
|
# otherwise these statements would be mixed together.
|
|
|
|
|
2013-04-14 23:13:42 +00:00
|
|
|
@syncfiles = ();
|
|
|
|
|
|
|
|
sub output_sync_clean {
|
|
|
|
rmfiles('foo/Makefile', 'bar/Makefile', @syncfiles);
|
|
|
|
rmdir('foo');
|
|
|
|
rmdir('bar');
|
|
|
|
}
|
|
|
|
|
|
|
|
# We synchronize the different jobs by having them wait for a sentinel file to
|
|
|
|
# be created, instead of relying on a certain amount of time passing.
|
|
|
|
# Unfortunately in this test we have to sleep after we see the sync file,
|
|
|
|
# since we also want to make the obtaining of the write synchronization lock
|
|
|
|
# reliable. If things are too fast, then sometimes a different job will steal
|
|
|
|
# the output sync lock and the output is mis-ordered from what we expect.
|
|
|
|
sub output_sync_wait {
|
|
|
|
return "while [ ! -f ../mksync.$_[0] ]; do :; done; rm -f ../mksync.$_[0].wait; $sleep_command 1";
|
|
|
|
}
|
|
|
|
sub output_sync_set {
|
|
|
|
return "date > ../mksync.$_[0]";
|
|
|
|
}
|
|
|
|
|
2013-04-28 05:19:19 +00:00
|
|
|
@syncfiles = qw(mksync.foo mksync.foo_start mksync.bar mksync.bar_start);
|
2013-04-14 23:13:42 +00:00
|
|
|
|
|
|
|
output_sync_clean();
|
2013-04-14 19:38:07 +00:00
|
|
|
mkdir('foo', 0777);
|
|
|
|
mkdir('bar', 0777);
|
|
|
|
|
2013-04-14 23:13:42 +00:00
|
|
|
$set_foo = output_sync_set('foo');
|
|
|
|
$set_bar = output_sync_set('bar');
|
2013-04-28 05:19:19 +00:00
|
|
|
$set_foo_start = output_sync_set('foo_start');
|
|
|
|
$set_bar_start = output_sync_set('bar_start');
|
2013-04-14 23:13:42 +00:00
|
|
|
|
|
|
|
$wait_foo = output_sync_wait('foo');
|
|
|
|
$wait_bar = output_sync_wait('bar');
|
2013-04-28 05:19:19 +00:00
|
|
|
$wait_foo_start = output_sync_set('foo_start');
|
|
|
|
$wait_bar_start = output_sync_set('bar_start');
|
2013-04-14 23:13:42 +00:00
|
|
|
|
2013-04-14 19:38:07 +00:00
|
|
|
open(MAKEFILE,"> foo/Makefile");
|
|
|
|
print MAKEFILE <<EOF;
|
|
|
|
all: foo
|
|
|
|
|
2013-04-14 23:13:42 +00:00
|
|
|
foo: foo-base ; \@$set_foo
|
|
|
|
|
2013-04-28 05:19:19 +00:00
|
|
|
foo-base:
|
|
|
|
\t\@echo foo: start
|
|
|
|
\t\@$wait_bar
|
|
|
|
\t\@echo foo: end
|
|
|
|
|
|
|
|
foo-job: foo-job-base ; \@$set_foo
|
|
|
|
|
|
|
|
foo-job-base:
|
|
|
|
\t\@$wait_bar_start
|
|
|
|
\t\@echo foo: start
|
|
|
|
\t\@$set_foo_start
|
|
|
|
\t\@$wait_bar
|
|
|
|
\t\@echo foo: end
|
|
|
|
|
|
|
|
foo-fail:
|
|
|
|
\t\@echo foo-fail: start
|
|
|
|
\t\@$wait_bar
|
|
|
|
\t\@echo foo-fail: end
|
|
|
|
\t\@false
|
2013-04-14 19:38:07 +00:00
|
|
|
EOF
|
|
|
|
close(MAKEFILE);
|
|
|
|
|
|
|
|
open(MAKEFILE,"> bar/Makefile");
|
|
|
|
print MAKEFILE <<EOF;
|
|
|
|
all: bar baz
|
|
|
|
|
2013-04-28 05:19:19 +00:00
|
|
|
bar: bar-base ; \@$set_bar
|
|
|
|
bar-base:
|
|
|
|
\t\@echo bar: start
|
|
|
|
\t\@echo bar: end
|
2013-04-14 19:38:07 +00:00
|
|
|
|
2013-04-28 05:19:19 +00:00
|
|
|
bar-job: bar-job-base ; \@$set_bar
|
|
|
|
|
|
|
|
bar-job-base:
|
|
|
|
\t\@echo bar: start
|
|
|
|
\t\@$set_bar_start
|
|
|
|
\t\@$wait_foo_start
|
|
|
|
\t\@echo bar: end
|
2013-04-14 23:13:42 +00:00
|
|
|
|
2013-04-28 05:19:19 +00:00
|
|
|
baz: baz-base
|
|
|
|
baz-base:
|
|
|
|
\t\@echo baz: start
|
|
|
|
\t\@$wait_foo
|
|
|
|
\t\@echo baz: end
|
2013-04-14 19:38:07 +00:00
|
|
|
EOF
|
|
|
|
close(MAKEFILE);
|
|
|
|
|
2013-04-28 05:19:19 +00:00
|
|
|
# Test per-make synchronization.
|
2013-04-14 23:13:42 +00:00
|
|
|
unlink(@syncfiles);
|
|
|
|
run_make_test(qq!
|
2013-04-14 19:38:07 +00:00
|
|
|
all: make-foo make-bar
|
|
|
|
|
2013-04-14 23:13:42 +00:00
|
|
|
make-foo: ; \$(MAKE) -C foo
|
2013-04-14 19:38:07 +00:00
|
|
|
|
2013-04-14 23:13:42 +00:00
|
|
|
make-bar: ; \$(MAKE) -C bar!,
|
2013-05-06 00:19:00 +00:00
|
|
|
'-j -Orecurse',
|
2013-04-14 19:38:07 +00:00
|
|
|
"#MAKEPATH# -C foo
|
|
|
|
#MAKE#[1]: Entering directory '#PWD#/foo'
|
|
|
|
foo: start
|
|
|
|
foo: end
|
|
|
|
#MAKE#[1]: Leaving directory '#PWD#/foo'
|
2013-05-05 21:03:51 +00:00
|
|
|
#MAKEPATH# -C bar
|
2013-04-14 19:38:07 +00:00
|
|
|
#MAKE#[1]: Entering directory '#PWD#/bar'
|
|
|
|
bar: start
|
|
|
|
bar: end
|
|
|
|
baz: start
|
|
|
|
baz: end
|
2013-04-14 23:13:42 +00:00
|
|
|
#MAKE#[1]: Leaving directory '#PWD#/bar'\n", 0, 6);
|
2013-04-14 19:38:07 +00:00
|
|
|
|
2013-04-28 05:19:19 +00:00
|
|
|
# Test per-target synchronization.
|
2013-04-14 23:13:42 +00:00
|
|
|
# Note we have to sleep again here after starting the foo makefile before
|
|
|
|
# starting the bar makefile, otherwise the "entering/leaving" messages for the
|
|
|
|
# submakes might be ordered differently than we expect.
|
|
|
|
|
|
|
|
unlink(@syncfiles);
|
|
|
|
run_make_test(qq!
|
2013-09-12 08:07:52 +00:00
|
|
|
x=1
|
|
|
|
\$xMAKEFLAGS += --no-print-directory
|
|
|
|
|
2013-04-14 19:38:07 +00:00
|
|
|
all: make-foo make-bar
|
|
|
|
|
2013-04-14 23:13:42 +00:00
|
|
|
make-foo: ; \$(MAKE) -C foo
|
2013-04-14 19:38:07 +00:00
|
|
|
|
2013-04-14 23:13:42 +00:00
|
|
|
make-bar: ; $sleep_command 1 ; \$(MAKE) -C bar!,
|
2013-04-15 17:22:51 +00:00
|
|
|
'-j --output-sync=target',
|
2013-04-14 19:38:07 +00:00
|
|
|
"#MAKEPATH# -C foo
|
2013-04-14 23:13:42 +00:00
|
|
|
$sleep_command 1 ; #MAKEPATH# -C bar
|
2013-04-14 19:38:07 +00:00
|
|
|
#MAKE#[1]: Entering directory '#PWD#/bar'
|
|
|
|
bar: start
|
|
|
|
bar: end
|
2013-09-12 08:07:52 +00:00
|
|
|
#MAKE#[1]: Leaving directory '#PWD#/bar'
|
2013-04-14 19:38:07 +00:00
|
|
|
#MAKE#[1]: Entering directory '#PWD#/foo'
|
|
|
|
foo: start
|
|
|
|
foo: end
|
|
|
|
#MAKE#[1]: Leaving directory '#PWD#/foo'
|
2013-09-12 08:07:52 +00:00
|
|
|
#MAKE#[1]: Entering directory '#PWD#/bar'
|
2013-04-14 19:38:07 +00:00
|
|
|
baz: start
|
|
|
|
baz: end
|
2013-04-14 23:13:42 +00:00
|
|
|
#MAKE#[1]: Leaving directory '#PWD#/bar'\n", 0, 6);
|
2013-04-14 19:38:07 +00:00
|
|
|
|
2013-09-12 08:07:52 +00:00
|
|
|
# Rerun but this time suppress the directory tracking
|
|
|
|
unlink(@syncfiles);
|
|
|
|
run_make_test(undef, '-j --output-sync=target x=',
|
|
|
|
"#MAKEPATH# -C foo
|
|
|
|
$sleep_command 1 ; #MAKEPATH# -C bar
|
|
|
|
bar: start
|
|
|
|
bar: end
|
|
|
|
foo: start
|
|
|
|
foo: end
|
|
|
|
baz: start
|
|
|
|
baz: end\n", 0, 6);
|
|
|
|
|
2013-04-14 19:38:07 +00:00
|
|
|
# Test that messages from make itself are enclosed with
|
|
|
|
# "Entering/Leaving directory" messages.
|
2013-04-14 23:13:42 +00:00
|
|
|
unlink(@syncfiles);
|
|
|
|
run_make_test(qq!
|
2013-04-14 19:38:07 +00:00
|
|
|
all: make-foo-fail make-bar-bar
|
|
|
|
|
2013-04-14 23:13:42 +00:00
|
|
|
make-foo-fail: ; \$(MAKE) -C foo foo-fail
|
2013-04-14 19:38:07 +00:00
|
|
|
|
2013-04-14 23:13:42 +00:00
|
|
|
make-bar-bar: ; $sleep_command 1 ; \$(MAKE) -C bar bar!,
|
|
|
|
'-j -O',
|
2013-04-14 19:38:07 +00:00
|
|
|
"#MAKEPATH# -C foo foo-fail
|
2013-04-14 23:13:42 +00:00
|
|
|
$sleep_command 1 ; #MAKEPATH# -C bar bar
|
2013-04-14 19:38:07 +00:00
|
|
|
#MAKE#[1]: Entering directory '#PWD#/bar'
|
|
|
|
bar: start
|
|
|
|
bar: end
|
|
|
|
#MAKE#[1]: Leaving directory '#PWD#/bar'
|
|
|
|
#MAKE#[1]: Entering directory '#PWD#/foo'
|
2013-04-28 05:19:19 +00:00
|
|
|
foo-fail: start
|
|
|
|
foo-fail: end
|
2013-04-28 23:09:20 +00:00
|
|
|
Makefile:20: recipe for target 'foo-fail' failed
|
|
|
|
#MAKE#[1]: *** [foo-fail] Error 1
|
2013-04-14 19:38:07 +00:00
|
|
|
#MAKE#[1]: Leaving directory '#PWD#/foo'
|
2013-04-14 20:31:18 +00:00
|
|
|
#MAKEFILE#:4: recipe for target 'make-foo-fail' failed
|
2013-04-14 19:38:07 +00:00
|
|
|
#MAKE#: *** [make-foo-fail] Error 2\n",
|
|
|
|
512);
|
|
|
|
|
2013-04-28 05:19:19 +00:00
|
|
|
# Test the per-job synchronization.
|
|
|
|
# For this we'll have bar-job:
|
|
|
|
# print start, invoke bar-start, wait for foo-start, print end, print-bar-end
|
|
|
|
# And foo-job:
|
|
|
|
# wait for bar-start, print foo-start, wait for bar-end, print end
|
|
|
|
|
|
|
|
unlink(@syncfiles);
|
|
|
|
run_make_test(qq!
|
|
|
|
all: make-foo make-bar
|
|
|
|
|
|
|
|
make-foo: ; \$(MAKE) -C foo foo-job
|
|
|
|
|
|
|
|
make-bar: ; $sleep_command 1 ; \$(MAKE) -C bar bar-job!,
|
2013-05-06 00:19:00 +00:00
|
|
|
'-j --output-sync=line',
|
2013-04-28 05:19:19 +00:00
|
|
|
"#MAKEPATH# -C foo foo-job
|
|
|
|
$sleep_command 1 ; #MAKEPATH# -C bar bar-job
|
|
|
|
#MAKE#[1]: Entering directory '#PWD#/foo'
|
|
|
|
foo: start
|
2013-09-12 08:07:52 +00:00
|
|
|
#MAKE#[1]: Leaving directory '#PWD#/foo'
|
2013-04-28 05:19:19 +00:00
|
|
|
#MAKE#[1]: Entering directory '#PWD#/bar'
|
|
|
|
bar: start
|
2013-09-12 08:07:52 +00:00
|
|
|
#MAKE#[1]: Leaving directory '#PWD#/bar'
|
|
|
|
#MAKE#[1]: Entering directory '#PWD#/bar'
|
2013-04-28 05:19:19 +00:00
|
|
|
bar: end
|
|
|
|
#MAKE#[1]: Leaving directory '#PWD#/bar'
|
2013-09-12 08:07:52 +00:00
|
|
|
#MAKE#[1]: Entering directory '#PWD#/foo'
|
2013-04-28 05:19:19 +00:00
|
|
|
foo: end
|
|
|
|
#MAKE#[1]: Leaving directory '#PWD#/foo'\n", 0, 6);
|
|
|
|
|
|
|
|
|
2013-04-14 19:38:07 +00:00
|
|
|
# Remove temporary directories and contents.
|
2013-04-14 23:13:42 +00:00
|
|
|
output_sync_clean();
|
2013-04-14 19:38:07 +00:00
|
|
|
|
2013-05-04 17:10:56 +00:00
|
|
|
# Ensure recursion doesn't mis-order or double-print output
|
|
|
|
run_make_test(qq!
|
|
|
|
all:
|
|
|
|
\t\@echo foo
|
|
|
|
\t\@+echo bar
|
|
|
|
!,
|
2013-05-06 00:19:00 +00:00
|
|
|
'-j -Oline', "foo\nbar\n");
|
2013-05-04 17:10:56 +00:00
|
|
|
|
|
|
|
run_make_test(undef, '-j -Otarget', "foo\nbar\n");
|
|
|
|
|
2013-05-05 21:03:51 +00:00
|
|
|
# Ensure when make writes out command it's not misordered
|
|
|
|
run_make_test(qq!
|
|
|
|
all:
|
|
|
|
\t\@echo foobar
|
|
|
|
\ttrue
|
|
|
|
!,
|
2013-05-06 00:19:00 +00:00
|
|
|
'-j -Oline', "foobar\ntrue\n");
|
2013-05-05 21:03:51 +00:00
|
|
|
|
|
|
|
run_make_test(undef, '-j -Otarget', "foobar\ntrue\n");
|
|
|
|
|
2013-04-14 19:38:07 +00:00
|
|
|
# This tells the test driver that the perl test script executed properly.
|
|
|
|
1;
|