Debian Codegraph @

tests/scripts/features/jobserver

raw
1 # -*-perl-*-
2
3 $description = "Test jobserver.";
4
5 $details = "These tests are ones that specifically are different when the
6 jobserver feature is available. Most -j tests are the same whether or not
7 jobserver is available, and those appear in the 'parallelism' test suite.";
8
9 exists $FEATURES{'jobserver'} or return -1;
10
11 if (!$parallel_jobs) {
12 return -1;
13 }
14
15 # Shorthand
16 my $np = '--no-print-directory';
17 my $j1err = "warning: jobserver unavailable: using -j1. Add '+' to parent make rule.";
18
19 # Simple test of MAKEFLAGS settings
20 run_make_test(q!
21 SHOW = $(patsubst --jobserver-auth=%,--jobserver-auth=<auth>,$(MAKEFLAGS))
22 recurse: ; @echo $@: "/$(SHOW)/"; $(MAKE) -f #MAKEFILE# all
23 all:;@echo $@: "/$(SHOW)/"
24 !,
25 "-j2 $np", "recurse: /-j2 --jobserver-auth=<auth> $np/\nall: /-j2 --jobserver-auth=<auth> $np/\n");
26
27 # Setting parallelism with the environment
28 # Command line should take precedence over the environment
29 $ENV{MAKEFLAGS} = "-j2 $np";
30 run_make_test(q!
31 SHOW = $(patsubst --jobserver-auth=%,--jobserver-auth=<auth>,$(MAKEFLAGS))
32 recurse: ; @echo $@: "/$(SHOW)/"; $(MAKE) -f #MAKEFILE# all
33 all:;@echo $@: "/$(SHOW)/"
34 !,
35 '', "recurse: /-j2 --jobserver-auth=<auth> $np/\nall: /-j2 --jobserver-auth=<auth> $np/\n");
36
37 # Test override of -jN
38 $ENV{MAKEFLAGS} = "-j9 $np";
39 run_make_test(q!
40 SHOW = $(patsubst --jobserver-auth=%,--jobserver-auth=<auth>,$(MAKEFLAGS))
41 recurse: ; @echo $@: "/$(SHOW)/"; $(MAKE) -j3 -f #MAKEFILE# recurse2
42 recurse2: ; @echo $@: "/$(SHOW)/"; $(MAKE) -f #MAKEFILE# all
43 all:;@echo $@: "/$(SHOW)/"
44 !,
45 "-j2 $np", "recurse: /-j2 --jobserver-auth=<auth> $np/\n#MAKE#[1]: warning: -j3 forced in submake: resetting jobserver mode.\nrecurse2: /-j3 --jobserver-auth=<auth> $np/\nall: /-j3 --jobserver-auth=<auth> $np/\n");
46
47 # Test override of -jN with -j
48 run_make_test(q!
49 SHOW = $(patsubst --jobserver-auth=%,--jobserver-auth=<auth>,$(MAKEFLAGS))
50 recurse: ; @echo $@: "/$(SHOW)/"; $(MAKE) -j -f #MAKEFILE# recurse2
51 recurse2: ; @echo $@: "/$(SHOW)/"; $(MAKE) -f #MAKEFILE# all
52 all:;@echo $@: "/$(SHOW)/"
53 !,
54 "-j2 $np", "recurse: /-j2 --jobserver-auth=<auth> $np/\n#MAKE#[1]: warning: -j0 forced in submake: resetting jobserver mode.\nrecurse2: /-j $np/\nall: /-j $np/\n");
55
56 # Don't put --jobserver-auth into a re-exec'd MAKEFLAGS.
57 # We can't test this directly because there's no way a makefile can
58 # show the value of MAKEFLAGS we were re-exec'd with. We can intuit it
59 # by looking for "disabling jobserver mode" warnings; we should only
60 # get one from the original invocation and none from the re-exec.
61 # See Savannah bug #18124
62
63 unlink('inc.mk');
64
65 run_make_test(q!
66 .RECIPEPREFIX = >
67 -include inc.mk
68 recur:
69 #> @echo 'MAKEFLAGS = $(MAKEFLAGS)'
70 > @rm -f inc.mk
71 > @$(MAKE) -j2 -f #MAKEFILE# all
72 all:
73 #> @echo 'MAKEFLAGS = $(MAKEFLAGS)'
74 > @echo $@
75 inc.mk:
76 #> @echo 'MAKEFLAGS = $(MAKEFLAGS)'
77 > @echo 'FOO = bar' > $@
78 !,
79 "$np -j2", "#MAKE#[1]: warning: -j2 forced in submake: resetting jobserver mode.\nall\n");
80
81 unlink('inc.mk');
82
83 # Test recursion which is hidden from make.
84 # See Savannah bug #39934
85 # Or Red Hat bug https://bugzilla.redhat.com/show_bug.cgi?id=885474
86 # Environments that don't use a pipe won't close access, so this won't happen.
87 if ($port_type ne 'W32') {
88 create_file('Makefile2', "vpath %.c ../\n", "foo:\n");
89
90 run_make_test(q!
91 default: ; @ #MAKEPATH# -f Makefile2
92 !,
93 "--jobserver-style=pipe -j2 $np",
94 "#MAKE#[1]: $j1err
95 #MAKE#[1]: Nothing to be done for 'foo'.");
96
97 rmfiles('Makefile2');
98 }
99
100 # For Windows and named pipes, we don't need to worry about recursion
101 if ($port_type eq 'W32' || exists $FEATURES{'jobserver-fifo'}) {
102 create_file('Makefile2', "vpath %.c ../\n", "foo:\n");
103
104 run_make_test(q!
105 default: ; @ #MAKEPATH# -f Makefile2
106 !,
107 "-j2 $np",
108 "#MAKE#[1]: Nothing to be done for 'foo'.");
109
110 rmfiles('Makefile2');
111 }
112
113 # Ensure enter/leave directory messages appear before jobserver warnings
114
115 run_make_test(q!
116 all: ; @$(MAKE) -C . -f #MAKEFILE# recurse -j1
117 recurse: ; @echo hi
118 !,
119 '-w -j2', "#MAKE#: Entering directory '#PWD#'
120 #MAKE#[1]: Entering directory '#PWD#'
121 #MAKE#[1]: warning: -j1 forced in submake: resetting jobserver mode.
122 hi
123 #MAKE#[1]: Leaving directory '#PWD#'
124 #MAKE#: Leaving directory '#PWD#'\n");
125
126 # Check for invalid jobserver-style options
127
128 run_make_test(q!
129 all: a
130 all a: ; @echo $@
131 !,
132 '--jobserver-style=foo -j8',
133 "#MAKE#: *** unknown jobserver auth style 'foo'. Stop.", 512);
134
135 # Ensure the jobserver is not disabled even if only later commands are recursive
136
137 run_make_test(q!
138 .RECIPEPREFIX := >
139 all:
140 > @echo $@ 1
141 > @echo $@ 2
142 > @$(MAKE) -f #MAKEFILE# recurse
143
144 recurse: ; @echo $@
145 !,
146 "$np -j8", "all 1\nall 2\nrecurse");
147
148 if ($port_type ne 'W32') {
149 run_make_test(undef, "$np --jobserver-style=pipe -j8",
150 "all 1\nall 2\nrecurse");
151 }
152
153 # And with + instead of $(MAKE)
154
155 run_make_test(q!
156 .RECIPEPREFIX := >
157 all:
158 > @echo $@ 1
159 > @echo $@ 2
160 > @+#MAKEPATH# -f #MAKEFILE# recurse
161
162 recurse: ; @echo $@
163 !,
164 "$np -j8", "all 1\nall 2\nrecurse");
165
166 if ($port_type ne 'W32') {
167 run_make_test(undef, "$np --jobserver-style=pipe -j8",
168 "all 1\nall 2\nrecurse");
169 }
170
171 if (exists $FEATURES{'jobserver-fifo'}) {
172 # sv 62908.
173 # Test that when mkfifo fails, make switches to pipe and succeeds.
174 # Force mkfifo to fail by attempting to create a fifo in a non existent
175 # directory.
176 # run_make_test does not allow matching a multiline pattern, therefore run
177 # the test twice.
178 # First time look for /$ERR_no_such_file/ to ensure mkfifo failed.
179 # Second time look for /Nothing to be done/ to ensure make succeeded.
180 $ENV{TMPDIR} = "nosuchdir";
181 run_make_test("all:\n", '-j2', "/$ERR_no_such_file/");
182
183 $ENV{TMPDIR} = "nosuchdir";
184 run_make_test(undef, '-j2', "/Nothing to be done/");
185
186 # Verify that MAKE_TMPDIR is preferred if provided
187 $ENV{MAKE_TMPDIR} = '.';
188 $ENV{TMPDIR} = 'nosuchdir';
189
190 run_make_test(q!
191 recurse: ; @$(MAKE) -f #MAKEFILE# all
192 all:;@echo "$$MAKEFLAGS"
193 !,
194 "-j2 --no-print-directory", "/--jobserver-auth=fifo:\\./");
195
196 # Verify we fall back to -j1 but continue, of the auth is bad.
197 $ENV{MAKEFLAGS} = '-j2 --jobserver-auth=fifo:nosuchfile';
198 run_make_test(q!all:;@echo hi!, "", "#MAKE#: cannot open jobserver nosuchfile: $ERR_no_such_file\n#MAKE#: $j1err\nhi\n");
199 }
200
201 1;