Debian Codegraph @

tests/scripts/features/output-sync

raw
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 if ($vos) {
15 $sleep_command = "sleep -seconds";
16 }
17 else {
18 $sleep_command = "sleep";
19 }
20
21 # The following subdirectories with Makefiles are used in several
22 # of the following tests. The model is:
23 # foo/Makefile - has a "foo" target that waits for the bar target
24 # bar/Makefile - has a "bar" target that runs immediately
25 # - has a "baz" target that waits for the foo target
26 #
27 # So, you start the two sub-makes in parallel and first the "bar" target is
28 # built, followed by "foo", followed by "baz". The trick is that first each
29 # target prints a "start" statement, then waits (if appropriate), then prints
30 # an end statement. Thus we can tell if the -O flag is working, since
31 # otherwise these statements would be mixed together.
32
33 @syncfiles = ();
34
35 sub output_sync_clean {
36 rmfiles('foo/Makefile', 'bar/Makefile', @syncfiles);
37 rmdir('foo');
38 rmdir('bar');
39 }
40
41 # We synchronize the different jobs by having them wait for a sentinel file to
42 # be created, instead of relying on a certain amount of time passing.
43 # Unfortunately in this test we have to sleep after we see the sync file,
44 # since we also want to make the obtaining of the write synchronization lock
45 # reliable. If things are too fast, then sometimes a different job will steal
46 # the output sync lock and the output is mis-ordered from what we expect.
47 sub output_sync_wait {
48 return "while [ ! -f ../mksync.$_[0] ]; do :; done; $CMD_rmfile ../mksync.$_[0].wait; $sleep_command 1";
49 }
50 sub output_sync_set {
51 return "date > ../mksync.$_[0]";
52 }
53
54 @syncfiles = qw(mksync.foo mksync.foo_start mksync.bar mksync.bar_start);
55
56 $tmout = 30;
57
58 output_sync_clean();
59 mkdir('foo', 0777);
60 mkdir('bar', 0777);
61
62 $set_foo = output_sync_set('foo');
63 $set_bar = output_sync_set('bar');
64 $set_foo_start = output_sync_set('foo_start');
65 $set_bar_start = output_sync_set('bar_start');
66
67 $wait_foo = output_sync_wait('foo');
68 $wait_bar = output_sync_wait('bar');
69 $wait_foo_start = output_sync_set('foo_start');
70 $wait_bar_start = output_sync_set('bar_start');
71
72 open(MAKEFILE,"> foo/Makefile");
73 print MAKEFILE <<EOF;
74 all: foo
75
76 foo: foo-base ; \@$set_foo
77
78 foo-base:
79 \t\@echo foo: start
80 \t\@$wait_bar
81 \t\@echo foo: end
82
83 foo-job: foo-job-base ; \@$set_foo
84
85 foo-job-base:
86 \t\@$wait_bar_start
87 \t\@echo foo: start
88 \t\@$set_foo_start
89 \t\@$wait_bar
90 \t\@echo foo: end
91
92 foo-fail:
93 \t\@echo foo-fail: start
94 \t\@$wait_bar
95 \t\@echo foo-fail: end
96 \t\@exit 1
97 EOF
98 close(MAKEFILE);
99
100 open(MAKEFILE,"> bar/Makefile");
101 print MAKEFILE <<EOF;
102 all: bar baz
103
104 bar: bar-base ; \@$set_bar
105 bar-base:
106 \t\@echo bar: start
107 \t\@echo bar: end
108
109 bar-job: bar-job-base ; \@$set_bar
110
111 bar-job-base:
112 \t\@echo bar: start
113 \t\@$set_bar_start
114 \t\@$wait_foo_start
115 \t\@echo bar: end
116
117 baz: baz-base
118 baz-base:
119 \t\@echo baz: start
120 \t\@$wait_foo
121 \t\@echo baz: end
122 EOF
123 close(MAKEFILE);
124
125 # Test per-make synchronization.
126 unlink(@syncfiles);
127 run_make_test(qq!
128 all: make-foo make-bar
129
130 make-foo: ; \$(MAKE) -C foo
131
132 make-bar: ; \$(MAKE) -C bar!,
133 '-j -Orecurse',
134 "#MAKEPATH# -C foo
135 #MAKE#[1]: Entering directory '#PWD#/foo'
136 foo: start
137 foo: end
138 #MAKE#[1]: Leaving directory '#PWD#/foo'
139 #MAKEPATH# -C bar
140 #MAKE#[1]: Entering directory '#PWD#/bar'
141 bar: start
142 bar: end
143 baz: start
144 baz: end
145 #MAKE#[1]: Leaving directory '#PWD#/bar'\n", 0, $tmout);
146
147 # Test per-target synchronization.
148 # Note we have to sleep again here after starting the foo makefile before
149 # starting the bar makefile, otherwise the "entering/leaving" messages for the
150 # submakes might be ordered differently than we expect.
151
152 unlink(@syncfiles);
153 run_make_test(qq!
154 x=1
155 \$xMAKEFLAGS += --no-print-directory
156
157 all: make-foo make-bar
158
159 make-foo: ; \$(MAKE) -C foo
160
161 make-bar: ; $sleep_command 1 ; \$(MAKE) -C bar!,
162 '-j --output-sync=target',
163 "#MAKEPATH# -C foo
164 $sleep_command 1 ; #MAKEPATH# -C bar
165 #MAKE#[1]: Entering directory '#PWD#/bar'
166 bar: start
167 bar: end
168 #MAKE#[1]: Leaving directory '#PWD#/bar'
169 #MAKE#[1]: Entering directory '#PWD#/foo'
170 foo: start
171 foo: end
172 #MAKE#[1]: Leaving directory '#PWD#/foo'
173 #MAKE#[1]: Entering directory '#PWD#/bar'
174 baz: start
175 baz: end
176 #MAKE#[1]: Leaving directory '#PWD#/bar'\n", 0, $tmout);
177
178 # Rerun but this time suppress the directory tracking
179 unlink(@syncfiles);
180 run_make_test(undef, '-j --output-sync=target x=',
181 "#MAKEPATH# -C foo
182 $sleep_command 1 ; #MAKEPATH# -C bar
183 bar: start
184 bar: end
185 foo: start
186 foo: end
187 baz: start
188 baz: end\n", 0, $tmout);
189
190 # Test that messages from make itself are enclosed with
191 # "Entering/Leaving directory" messages.
192 unlink(@syncfiles);
193
194 # FIXME rocky (add traceback stuff)
195 #run_make_test(qq!
196 #all: make-foo-fail make-bar-bar
197 #
198 #make-foo-fail: ; \$(MAKE) -C foo foo-fail
199 #
200 #make-bar-bar: ; #HELPER# -q sleep 1 ; \$(MAKE) -C bar bar!,
201 # '-j -O',
202 #"#MAKEPATH# -C foo foo-fail
203 ##HELPER# -q sleep 1 ; #MAKEPATH# -C bar bar
204 ##MAKE#[1]: Entering directory '#PWD#/bar'
205 #bar: start
206 #bar: end
207 ##MAKE#[1]: Leaving directory '#PWD#/bar'
208 ##MAKE#[1]: Entering directory '#PWD#/foo'
209 #foo-fail: start
210 #foo-fail: end
211 ##MAKE#[1]: *** [Makefile:23: foo-fail] Error 1
212 ##MAKE#[1]: Leaving directory '#PWD#/foo'
213 ##MAKE#: *** [#MAKEFILE#:4: make-foo-fail] Error 2\n",
214 #512);
215
216 # Test the per-job synchronization.
217 # For this we'll have bar-job:
218 # print start, invoke bar-start, wait for foo-start, print end, print-bar-end
219 # And foo-job:
220 # wait for bar-start, print foo-start, wait for bar-end, print end
221
222 unlink(@syncfiles);
223 run_make_test(qq!
224 all: make-foo make-bar
225
226 make-foo: ; \$(MAKE) -C foo foo-job
227
228 make-bar: ; $sleep_command 1 ; \$(MAKE) -C bar bar-job!,
229 '-j --output-sync=line',
230 "#MAKEPATH# -C foo foo-job
231 $sleep_command 1 ; #MAKEPATH# -C bar bar-job
232 #MAKE#[1]: Entering directory '#PWD#/foo'
233 foo: start
234 #MAKE#[1]: Leaving directory '#PWD#/foo'
235 #MAKE#[1]: Entering directory '#PWD#/bar'
236 bar: start
237 #MAKE#[1]: Leaving directory '#PWD#/bar'
238 #MAKE#[1]: Entering directory '#PWD#/bar'
239 bar: end
240 #MAKE#[1]: Leaving directory '#PWD#/bar'
241 #MAKE#[1]: Entering directory '#PWD#/foo'
242 foo: end
243 #MAKE#[1]: Leaving directory '#PWD#/foo'\n", 0, $tmout);
244
245
246 # Remove temporary directories and contents.
247 output_sync_clean();
248
249 # Ensure recursion doesn't mis-order or double-print output
250 run_make_test(qq!
251 all:
252 \t\@echo foo
253 \t\@+echo bar
254 !,
255 '-j -Oline', "foo\nbar\n");
256
257 run_make_test(undef, '-j -Otarget', "foo\nbar\n");
258
259 # Ensure when make writes out command it's not misordered
260 run_make_test(qq!
261 all:
262 \t\@echo foobar
263 \ttrue
264 !,
265 '-j -Oline', "foobar\ntrue\n");
266
267 run_make_test(undef, '-j -Otarget', "foobar\ntrue\n");
268
269 # Ensure that shell functions inside recipes write stderr to the sync file
270 run_make_test(q!
271 all: ; @: $(shell echo foo 1>&2)
272 !,
273 '-w -Oline', "#MAKE#: Entering directory '#PWD#'\nfoo\n#MAKE#: Leaving directory '#PWD#'\n");
274
275 # Ensure that output generated while parsing makefiles is synced
276 # when appropriate.
277 run_make_test(q!
278 $(shell echo foo 1>&2)
279 all: ; echo bar
280 !,
281 '-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");
282
283 # Test recursion
284 $m1 = get_tmpfile();
285 $m2 = get_tmpfile();
286
287 open(M1, "> $m1");
288 print M1 <<'EOF';
289 $(shell echo d1 stderr 1>&2)
290 $(info d1 stdout)
291 all:; @:
292 EOF
293 close(M1);
294
295 open(M2, "> $m2");
296 print M2 <<'EOF';
297 $(shell echo d2 stderr 1>&2)
298 $(info d2 stdout)
299 all:; @:
300 # Force an ordering on the output
301 $(shell sleep 1)
302 EOF
303 close(M2);
304
305 run_make_test(qq!
306 all: t1 t2
307 t1: ; \@\$(MAKE) -f $m1
308 t2: ; \@\$(MAKE) -f $m2
309 !,
310 "-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");
311
312 rmfiles($m1, $m2);
313
314 # Ensure that output generated while parsing makefiles is synced
315 # when appropriate.
316 $m1 = get_tmpfile();
317
318 open(M1, "> $m1");
319 print M1 <<'EOF';
320 $(shell echo d1 stderr 1>&2)
321 $(info d1 stdout)
322 $(error d1 failed)
323 all:; @:
324 EOF
325 close(M1);
326
327 # FIXME rocky (add traceback stuff)
328 #run_make_test(qq!
329 #all: t1
330 #t1: ; -\@\$(MAKE) -f $m1
331 #!,
332 # "-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");
333 #
334 #rmfiles($m1);
335
336 # Test $(error ...) functions in recipes
337
338 run_make_test(q!
339 foo: $(OBJS) ; echo $(or $(filter %.o,$^),$(error fail))
340 !,
341 '-O', "#MAKEFILE#:2: *** fail. Stop.\n", 512);
342
343 # SV 47365: Make sure exec failure error messages are shown
344 # Needs to be ported to Windows
345 # FIXME rocky (add traceback stuff)
346 #if ($port_type ne 'W32') {
347 # run_make_test(q!
348 #all:: ; @./foo bar baz
349 #!,
350 # '-O', "#MAKE#: ./foo: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:2: all] Error 127\n", 512);
351 #}
352
353 # This tells the test driver that the perl test script executed properly.
354 1;