1#                                                                    -*-perl-*-
2
3$description = "Test jobserver.";
4
5$details = "These tests are ones that specifically are different when the
6jobserver feature is available.  Most -j tests are the same whether or not
7jobserver is available, and those appear in the 'parallelism' test suite.";
8
9exists $FEATURES{'jobserver'} or return -1;
10
11if (!$parallel_jobs) {
12  return -1;
13}
14
15# Shorthand
16my $np = '--no-print-directory';
17
18# Simple test of MAKEFLAGS settings
19run_make_test(q!
20SHOW = $(patsubst --jobserver-auth=%,--jobserver-auth=<auth>,$(MAKEFLAGS))
21recurse: ; @echo $@: "/$(SHOW)/"; $(MAKE) -f #MAKEFILE# all
22all:;@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$extraENV{MAKEFLAGS} = "-j2 $np";
29run_make_test(q!
30SHOW = $(patsubst --jobserver-auth=%,--jobserver-auth=<auth>,$(MAKEFLAGS))
31recurse: ; @echo $@: "/$(SHOW)/"; $(MAKE) -f #MAKEFILE# all
32all:;@echo $@: "/$(SHOW)/"
33!,
34              '', "recurse: /-j2 --jobserver-auth=<auth> $np/\nall: /-j2 --jobserver-auth=<auth> $np/\n");
35delete $extraENV{MAKEFLAGS};
36
37# Test override of -jN
38$extraENV{MAKEFLAGS} = "-j9 $np";
39run_make_test(q!
40SHOW = $(patsubst --jobserver-auth=%,--jobserver-auth=<auth>,$(MAKEFLAGS))
41recurse: ; @echo $@: "/$(SHOW)/"; $(MAKE) -j3 -f #MAKEFILE# recurse2
42recurse2: ; @echo $@: "/$(SHOW)/"; $(MAKE) -f #MAKEFILE# all
43all:;@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");
46delete $extraENV{MAKEFLAGS};
47
48# Test override of -jN with -j
49run_make_test(q!
50SHOW = $(patsubst --jobserver-auth=%,--jobserver-auth=<auth>,$(MAKEFLAGS))
51recurse: ; @echo $@: "/$(SHOW)/"; $(MAKE) -j -f #MAKEFILE# recurse2
52recurse2: ; @echo $@: "/$(SHOW)/"; $(MAKE) -f #MAKEFILE# all
53all:;@echo $@: "/$(SHOW)/"
54!,
55              "-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");
56
57# Don't put --jobserver-auth into a re-exec'd MAKEFLAGS.
58# We can't test this directly because there's no way a makefile can
59# show the value of MAKEFLAGS we were re-exec'd with.  We can intuit it
60# by looking for "disabling jobserver mode" warnings; we should only
61# get one from the original invocation and none from the re-exec.
62# See Savannah bug #18124
63
64unlink('inc.mk');
65
66run_make_test(q!
67-include inc.mk
68recur:
69#	@echo 'MAKEFLAGS = $(MAKEFLAGS)'
70	@rm -f inc.mk
71	@$(MAKE) -j2 -f #MAKEFILE# all
72all:
73#	@echo 'MAKEFLAGS = $(MAKEFLAGS)'
74	@echo $@
75inc.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
81unlink('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# Windows doesn't use a pipe, and doesn't close access, so this won't happen.
87if ($port_type ne 'W32') {
88    open(MAKEFILE,"> Makefile2");
89    print MAKEFILE '
90    vpath %.c ../
91    foo:
92    ';
93    close(MAKEFILE);
94
95    run_make_test(q!
96default: ; @ #MAKEPATH# -f Makefile2
97!,
98              "-j2 $np",
99"#MAKE#[1]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
100#MAKE#[1]: Nothing to be done for 'foo'.");
101
102    rmfiles('Makefile2');
103}
104
1051;
106
107### Local Variables:
108### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action))
109### End:
110