Imported Upstream version 4.4
[platform/upstream/make.git] / tests / scripts / features / jobserver
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
18 # Simple test of MAKEFLAGS settings
19 run_make_test(q!
20 SHOW = $(patsubst --jobserver-auth=%,--jobserver-auth=<auth>,$(MAKEFLAGS))
21 recurse: ; @echo $@: "/$(SHOW)/"; $(MAKE) -f #MAKEFILE# all
22 all:;@echo $@: "/$(SHOW)/"
23 !,
24               "-j2 $np", "recurse: /-j2 --jobserver-auth=<auth> $np/\nall: /-j2 --jobserver-auth=<auth> $np/\n");
25
26 # Setting parallelism with the environment
27 # Command line should take precedence over the environment
28 $ENV{MAKEFLAGS} = "-j2 $np";
29 run_make_test(q!
30 SHOW = $(patsubst --jobserver-auth=%,--jobserver-auth=<auth>,$(MAKEFLAGS))
31 recurse: ; @echo $@: "/$(SHOW)/"; $(MAKE) -f #MAKEFILE# all
32 all:;@echo $@: "/$(SHOW)/"
33 !,
34               '', "recurse: /-j2 --jobserver-auth=<auth> $np/\nall: /-j2 --jobserver-auth=<auth> $np/\n");
35
36 # Test override of -jN
37 $ENV{MAKEFLAGS} = "-j9 $np";
38 run_make_test(q!
39 SHOW = $(patsubst --jobserver-auth=%,--jobserver-auth=<auth>,$(MAKEFLAGS))
40 recurse: ; @echo $@: "/$(SHOW)/"; $(MAKE) -j3 -f #MAKEFILE# recurse2
41 recurse2: ; @echo $@: "/$(SHOW)/"; $(MAKE) -f #MAKEFILE# all
42 all:;@echo $@: "/$(SHOW)/"
43 !,
44               "-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");
45
46 # Test override of -jN with -j
47 run_make_test(q!
48 SHOW = $(patsubst --jobserver-auth=%,--jobserver-auth=<auth>,$(MAKEFLAGS))
49 recurse: ; @echo $@: "/$(SHOW)/"; $(MAKE) -j -f #MAKEFILE# recurse2
50 recurse2: ; @echo $@: "/$(SHOW)/"; $(MAKE) -f #MAKEFILE# all
51 all:;@echo $@: "/$(SHOW)/"
52 !,
53               "-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");
54
55 # Don't put --jobserver-auth into a re-exec'd MAKEFLAGS.
56 # We can't test this directly because there's no way a makefile can
57 # show the value of MAKEFLAGS we were re-exec'd with.  We can intuit it
58 # by looking for "disabling jobserver mode" warnings; we should only
59 # get one from the original invocation and none from the re-exec.
60 # See Savannah bug #18124
61
62 unlink('inc.mk');
63
64 run_make_test(q!
65 .RECIPEPREFIX = >
66 -include inc.mk
67 recur:
68 #> @echo 'MAKEFLAGS = $(MAKEFLAGS)'
69 > @rm -f inc.mk
70 > @$(MAKE) -j2 -f #MAKEFILE# all
71 all:
72 #> @echo 'MAKEFLAGS = $(MAKEFLAGS)'
73 > @echo $@
74 inc.mk:
75 #> @echo 'MAKEFLAGS = $(MAKEFLAGS)'
76 > @echo 'FOO = bar' > $@
77 !,
78               "$np -j2", "#MAKE#[1]: warning: -j2 forced in submake: resetting jobserver mode.\nall\n");
79
80 unlink('inc.mk');
81
82 # Test recursion which is hidden from make.
83 # See Savannah bug #39934
84 # Or Red Hat bug https://bugzilla.redhat.com/show_bug.cgi?id=885474
85 # Environments that don't use a pipe won't close access, so this won't happen.
86 if ($port_type ne 'W32') {
87     create_file('Makefile2', "vpath %.c ../\n", "foo:\n");
88
89     run_make_test(q!
90 default: ; @ #MAKEPATH# -f Makefile2
91 !,
92               "--jobserver-style=pipe -j2 $np",
93 "#MAKE#[1]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
94 #MAKE#[1]: Nothing to be done for 'foo'.");
95
96     rmfiles('Makefile2');
97 }
98
99 # For Windows and named pipes, we don't need to worry about recursion
100 if ($port_type eq 'W32' || exists $FEATURES{'jobserver-fifo'}) {
101     create_file('Makefile2', "vpath %.c ../\n", "foo:\n");
102
103     run_make_test(q!
104 default: ; @ #MAKEPATH# -f Makefile2
105 !,
106               "-j2 $np",
107 "#MAKE#[1]: Nothing to be done for 'foo'.");
108
109     rmfiles('Makefile2');
110 }
111
112 # Ensure enter/leave directory messages appear before jobserver warnings
113
114 run_make_test(q!
115 all: ; @$(MAKE) -C . -f #MAKEFILE# recurse -j1
116 recurse: ; @echo hi
117 !,
118               '-w -j2', "#MAKE#: Entering directory '#PWD#'
119 #MAKE#[1]: Entering directory '#PWD#'
120 #MAKE#[1]: warning: -j1 forced in submake: resetting jobserver mode.
121 hi
122 #MAKE#[1]: Leaving directory '#PWD#'
123 #MAKE#: Leaving directory '#PWD#'\n");
124
125 # Check for invalid jobserver-style options
126
127 run_make_test(q!
128 all: a
129 all a: ; @echo $@
130 !,
131               '--jobserver-style=foo -j8',
132               "#MAKE#: *** Unknown jobserver auth style 'foo'.  Stop.", 512);
133
134 # sv 62908.
135 # Test that when mkfifo fails, make switches to pipe and succeeds.
136 # Force mkfifo to fail by attempting to create a fifo in a non existent
137 # directory.
138 # run_make_test does not allow matching a multiline pattern, therefore run the
139 # test twice.
140 # First time look for /$ERR_no_such_file/ to ensure mkfifo failed.
141 # Second time look for /Nothing to be done/ to ensure make succeeded.
142 if (exists $FEATURES{'jobserver-fifo'}) {
143   $ENV{TMPDIR} = "nosuchdir";
144   run_make_test("all:\n", '-j2', "/$ERR_no_such_file/");
145
146   $ENV{TMPDIR} = "nosuchdir";
147   run_make_test(undef, '-j2', "/Nothing to be done/");
148
149   # Verify that MAKE_TMPDIR is preferred if provided
150   $ENV{MAKE_TMPDIR} = '.';
151   $ENV{TMPDIR} = 'nosuchdir';
152
153   run_make_test(q!
154 recurse: ; @$(MAKE) -f #MAKEFILE# all
155 all:;@echo "$$MAKEFLAGS"
156 !,
157               "-j2 --no-print-directory", "/--jobserver-auth=fifo:\\./");
158 }
159
160 1;