summaryrefslogtreecommitdiff
path: root/tests/scripts/features/output-sync
blob: dce2ac4393a552ffadb9cc9eb59ae2f985806168 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#                                                                    -*-perl-*-

$description = "Test --output-sync (-O) option.";

$details = "Test the synchronization of output from parallel jobs.";

if (!$parallel_jobs) {
  return -1;
}

if ($vos) {
  $sleep_command = "sleep -seconds";
}
else {
  $sleep_command = "sleep";
}

@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]";
}

@syncfiles = qw(mksync.foo mksync.bar);

# The following subdirectories with Makefiles are used in several
# of the following tests.
output_sync_clean();
mkdir('foo', 0777);
mkdir('bar', 0777);

$set_foo = output_sync_set('foo');
$set_bar = output_sync_set('bar');

$wait_foo = output_sync_wait('foo');
$wait_bar = output_sync_wait('bar');

open(MAKEFILE,"> foo/Makefile");
print MAKEFILE <<EOF;
all: foo

foo: foo-base ; \@$set_foo

foo-base: ; \@echo foo: start; $wait_bar ; echo foo: end

foo-fail: ; \@$wait_bar ; false
EOF
close(MAKEFILE);

open(MAKEFILE,"> bar/Makefile");
print MAKEFILE <<EOF;
all: bar baz

bar: ; \@echo bar: start; echo bar: end; $set_bar

baz: baz-base

baz-base: ; \@echo baz: start; $wait_foo; echo baz: end
EOF
close(MAKEFILE);

# Test coarse synchronization.
unlink(@syncfiles);
run_make_test(qq!
all: make-foo make-bar

make-foo: ; \$(MAKE) -C foo

make-bar: ; \$(MAKE) -C bar!,
              '-j -Omake',
"#MAKEPATH# -C foo
#MAKEPATH# -C bar
#MAKE#[1]: Entering directory '#PWD#/foo'
#MAKE#[1]: Entering directory '#PWD#/foo'
foo: start
foo: end
#MAKE#[1]: Leaving directory '#PWD#/foo'
#MAKE#[1]: Leaving directory '#PWD#/foo'
#MAKE#[1]: Entering directory '#PWD#/bar'
#MAKE#[1]: Entering directory '#PWD#/bar'
bar: start
bar: end
#MAKE#[1]: Leaving directory '#PWD#/bar'
#MAKE#[1]: Entering directory '#PWD#/bar'
baz: start
baz: end
#MAKE#[1]: Leaving directory '#PWD#/bar'
#MAKE#[1]: Leaving directory '#PWD#/bar'\n", 0, 6);

# Test fine synchronization.
# 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!
all: make-foo make-bar

make-foo: ; \$(MAKE) -C foo

make-bar: ; $sleep_command 1 ; \$(MAKE) -C bar!,
              '-j --output-sync=target',
"#MAKEPATH# -C foo
$sleep_command 1 ; #MAKEPATH# -C bar
#MAKE#[1]: Entering directory '#PWD#/foo'
#MAKE#[1]: Entering directory '#PWD#/bar'
#MAKE#[1]: Entering directory '#PWD#/bar'
bar: start
bar: end
#MAKE#[1]: Leaving directory '#PWD#/bar'
#MAKE#[1]: Entering directory '#PWD#/foo'
foo: start
foo: end
#MAKE#[1]: Leaving directory '#PWD#/foo'
#MAKE#[1]: Leaving directory '#PWD#/foo'
#MAKE#[1]: Entering directory '#PWD#/bar'
baz: start
baz: end
#MAKE#[1]: Leaving directory '#PWD#/bar'
#MAKE#[1]: Leaving directory '#PWD#/bar'\n", 0, 6);

# Test that messages from make itself are enclosed with
# "Entering/Leaving directory" messages.
unlink(@syncfiles);
run_make_test(qq!
all: make-foo-fail make-bar-bar

make-foo-fail: ; \$(MAKE) -C foo foo-fail

make-bar-bar: ; $sleep_command 1 ; \$(MAKE) -C bar bar!,
              '-j -O',
"#MAKEPATH# -C foo foo-fail
$sleep_command 1 ; #MAKEPATH# -C bar bar
#MAKE#[1]: Entering directory '#PWD#/foo'
#MAKE#[1]: Entering directory '#PWD#/bar'
#MAKE#[1]: Entering directory '#PWD#/bar'
bar: start
bar: end
#MAKE#[1]: Leaving directory '#PWD#/bar'
#MAKE#[1]: Leaving directory '#PWD#/bar'
#MAKE#[1]: Entering directory '#PWD#/foo'
Makefile:7: recipe for target 'foo-fail' failed
#MAKE#[1]: Leaving directory '#PWD#/foo'
#MAKE#[1]: Entering directory '#PWD#/foo'
#MAKE#[1]: *** [foo-fail] Error 1
#MAKE#[1]: Leaving directory '#PWD#/foo'
#MAKE#[1]: Leaving directory '#PWD#/foo'
#MAKEFILE#:4: recipe for target 'make-foo-fail' failed
#MAKE#: *** [make-foo-fail] Error 2\n",
512);

# Remove temporary directories and contents.
output_sync_clean();

# This tells the test driver that the perl test script executed properly.
1;