3 $description = "Test --output-sync (-O) option.";
5 $details = "Test the synchronization of output from parallel jobs.";
7 # If we don't have output sync support, never mind.
8 exists $FEATURES{'output-sync'} or return -1;
10 # Output sync can't be tested without parallelization
11 $parallel_jobs or return -1;
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
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.
28 sub output_sync_clean {
29 rmfiles('foo/Makefile', 'bar/Makefile', @syncfiles);
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");
44 return subst_make_string("#HELPER# -q file ../mksync.$_[0]");
47 @syncfiles = qw(mksync.foo mksync.foo_start mksync.bar mksync.bar_start);
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');
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');
65 open(MAKEFILE,"> foo/Makefile");
69 foo: foo-base ; \@$set_foo
76 foo-job: foo-job-base ; \@$set_foo
86 \t\@echo foo-fail: start
88 \t\@echo foo-fail: end
93 open(MAKEFILE,"> bar/Makefile");
97 bar: bar-base ; \@$set_bar
102 bar-job: bar-job-base ; \@$set_bar
118 # Test per-make synchronization.
119 # Note we have to sleep again here after starting the foo makefile before
120 # starting the bar makefile, otherwise the "entering/leaving" messages for the
121 # submakes might be ordered differently than we expect.
125 all: make-foo make-bar
127 make-foo: ; \$(MAKE) -C foo
129 make-bar: ; #HELPER# -q sleep 1 ; \$(MAKE) -C bar!,
132 #MAKE#[1]: Entering directory '#PWD#/foo'
135 #MAKE#[1]: Leaving directory '#PWD#/foo'
136 #HELPER# -q sleep 1 ; #MAKEPATH# -C bar
137 #MAKE#[1]: Entering directory '#PWD#/bar'
142 #MAKE#[1]: Leaving directory '#PWD#/bar'\n", 0, $tmout);
144 # Test per-target synchronization.
145 # Note we have to sleep again here after starting the foo makefile before
146 # starting the bar makefile, otherwise the "entering/leaving" messages for the
147 # submakes might be ordered differently than we expect.
152 \$xMAKEFLAGS += --no-print-directory
154 all: make-foo make-bar
156 make-foo: ; \$(MAKE) -C foo
158 make-bar: ; #HELPER# -q sleep 1 ; \$(MAKE) -C bar!,
159 '-j --output-sync=target',
161 #HELPER# -q sleep 1 ; #MAKEPATH# -C bar
162 #MAKE#[1]: Entering directory '#PWD#/bar'
165 #MAKE#[1]: Leaving directory '#PWD#/bar'
166 #MAKE#[1]: Entering directory '#PWD#/foo'
169 #MAKE#[1]: Leaving directory '#PWD#/foo'
170 #MAKE#[1]: Entering directory '#PWD#/bar'
173 #MAKE#[1]: Leaving directory '#PWD#/bar'\n", 0, $tmout);
175 # Rerun but this time suppress the directory tracking
177 run_make_test(undef, '-j --output-sync=target x=',
179 #HELPER# -q sleep 1 ; #MAKEPATH# -C bar
185 baz: end\n", 0, $tmout);
187 # Test that messages from make itself are enclosed with
188 # "Entering/Leaving directory" messages.
191 all: make-foo-fail make-bar-bar
193 make-foo-fail: ; \$(MAKE) -C foo foo-fail
195 make-bar-bar: ; #HELPER# -q sleep 1 ; \$(MAKE) -C bar bar!,
197 "#MAKEPATH# -C foo foo-fail
198 #HELPER# -q sleep 1 ; #MAKEPATH# -C bar bar
199 #MAKE#[1]: Entering directory '#PWD#/bar'
202 #MAKE#[1]: Leaving directory '#PWD#/bar'
203 #MAKE#[1]: Entering directory '#PWD#/foo'
206 #MAKE#[1]: *** [Makefile:23: foo-fail] Error 1
207 #MAKE#[1]: Leaving directory '#PWD#/foo'
208 #MAKE#: *** [#MAKEFILE#:4: make-foo-fail] Error 2\n",
211 # Test the per-job synchronization.
212 # For this we'll have bar-job:
213 # print start, invoke bar-start, wait for foo-start, print end, print-bar-end
215 # wait for bar-start, print foo-start, wait for bar-end, print end
219 all: make-foo make-bar
221 make-foo: ; \$(MAKE) -C foo foo-job
223 make-bar: ; #HELPER# -q sleep 1 ; \$(MAKE) -C bar bar-job!,
224 '-j --output-sync=line',
225 "#MAKEPATH# -C foo foo-job
226 #HELPER# -q sleep 1 ; #MAKEPATH# -C bar bar-job
227 #MAKE#[1]: Entering directory '#PWD#/foo'
229 #MAKE#[1]: Leaving directory '#PWD#/foo'
230 #MAKE#[1]: Entering directory '#PWD#/bar'
232 #MAKE#[1]: Leaving directory '#PWD#/bar'
233 #MAKE#[1]: Entering directory '#PWD#/bar'
235 #MAKE#[1]: Leaving directory '#PWD#/bar'
236 #MAKE#[1]: Entering directory '#PWD#/foo'
238 #MAKE#[1]: Leaving directory '#PWD#/foo'\n", 0, $tmout);
240 # Remove temporary directories and contents.
243 # Ensure recursion doesn't mis-order or double-print output
249 '-j -Oline', "foo\nbar\n");
251 run_make_test(undef, '-j -Otarget', "foo\nbar\n");
253 # Ensure when make writes out command it's not misordered
259 '-j -Oline', "foobar\ntrue\n");
261 run_make_test(undef, '-j -Otarget', "foobar\ntrue\n");
263 # Ensure that shell functions inside recipes write stderr to the sync file
265 all: ; @: $(shell echo foo 1>&2)
267 '-w -Oline', "#MAKE#: Entering directory '#PWD#'\nfoo\n#MAKE#: Leaving directory '#PWD#'\n");
269 # Ensure that output generated while parsing makefiles is synced
272 $(shell echo foo 1>&2)
275 '-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");
283 $(shell echo d1 stderr 1>&2)
291 $(shell echo d2 stderr 1>&2)
294 # Force an ordering on the output
301 t1: ; \@\$(MAKE) -f $m1
302 t2: ; \@\$(MAKE) -f $m2
304 "-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");
308 # Ensure that output generated while parsing makefiles is synced
314 $(shell echo d1 stderr 1>&2)
323 t1: ; -\@\$(MAKE) -f $m1
325 "-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");
329 # Test $(error ...) functions in recipes
332 foo: $(OBJS) ; echo $(or $(filter %.o,$^),$(error fail))
334 '-O', "#MAKEFILE#:2: *** fail. Stop.\n", 512);
336 # SV 47365: Make sure exec failure error messages are shown
337 # Needs to be ported to Windows
338 if ($port_type ne 'W32') {
340 all:: ; @./foo bar baz
342 '-O', "#MAKE#: ./foo: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:2: all] Error 127\n", 512);
345 if ($port_type eq 'UNIX') {
346 # POSIX doesn't require sh to set PPID so test this
347 my $cmd = create_command();
348 add_options($cmd, '-f', '/dev/null', '-E', q!all:;@echo $$PPID!);
349 my $fout = 'ppidtest.out';
350 run_command_with_output($fout, @$cmd);
351 $_ = read_file_into_string($fout);
356 # Test that make removes temporary files, even when a signal is received.
357 # The general test_driver postprocessing will ensure the temporary file used
358 # to synchronize output and the jobserver fifo are both removed.
359 # sleep is needed to let make write its "... Terminated" message to the log
362 pid:=$(shell echo $$PPID)
363 all:; @kill -TERM $(pid) && sleep 16
364 !, '-O -j2', '/#MAKE#: \*\*\* \[#MAKEFILE#:3: all] Terminated/', POSIX::SIGTERM);
370 # This tells the test driver that the perl test script executed properly.