| 1 | # -*-perl-*-
|
|---|
| 2 |
|
|---|
| 3 | $description = "Test parallelism (-j) option.";
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 | $details = "This test creates a makefile with two double-colon default
|
|---|
| 7 | rules. The first rule has a series of sleep and echo commands
|
|---|
| 8 | intended to run in series. The second and third have just an
|
|---|
| 9 | echo statement. When make is called in this test, it is given
|
|---|
| 10 | the -j option with a value of 4. This tells make that it may
|
|---|
| 11 | start up to four jobs simultaneously. In this case, since the
|
|---|
| 12 | first command is a sleep command, the output of the second
|
|---|
| 13 | and third commands will appear before the first if indeed
|
|---|
| 14 | make is running all of these commands in parallel.";
|
|---|
| 15 |
|
|---|
| 16 | if (!$parallel_jobs) {
|
|---|
| 17 | return -1;
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | if ($vos) {
|
|---|
| 21 | $sleep_command = "sleep -seconds";
|
|---|
| 22 | }
|
|---|
| 23 | else {
|
|---|
| 24 | $sleep_command = "sleep";
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | run_make_test("
|
|---|
| 29 | all : def_1 def_2 def_3
|
|---|
| 30 | def_1 : ; \@echo ONE; $sleep_command 3 ; echo TWO
|
|---|
| 31 | def_2 : ; \@$sleep_command 2 ; echo THREE
|
|---|
| 32 | def_3 : ; \@$sleep_command 1 ; echo FOUR",
|
|---|
| 33 | '-j4', "ONE\nFOUR\nTHREE\nTWO");
|
|---|
| 34 |
|
|---|
| 35 | # Test parallelism with included files. Here we sleep/echo while
|
|---|
| 36 | # building the included files, to test that they are being built in
|
|---|
| 37 | # parallel.
|
|---|
| 38 | run_make_test("
|
|---|
| 39 | all: 1 2; \@echo success
|
|---|
| 40 | -include 1.inc 2.inc
|
|---|
| 41 | 1.inc: ; \@echo ONE.inc; $sleep_command 2; echo TWO.inc; echo '1: ; \@echo ONE; $sleep_command 2; echo TWO' > \$\@
|
|---|
| 42 | 2.inc: ; \@$sleep_command 1; echo THREE.inc; echo '2: ; \@$sleep_command 1; echo THREE' > \$\@",
|
|---|
| 43 | "-j4",
|
|---|
| 44 | "ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n");
|
|---|
| 45 |
|
|---|
| 46 | unlink('1.inc', '2.inc');
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | # Test parallelism with included files--this time recurse first and make
|
|---|
| 50 | # sure the jobserver works.
|
|---|
| 51 | run_make_test("
|
|---|
| 52 | recurse: ; \@\$(MAKE) --no-print-directory -f #MAKEFILE# INC=yes all
|
|---|
| 53 | all: 1 2; \@echo success
|
|---|
| 54 |
|
|---|
| 55 | INC = no
|
|---|
| 56 | ifeq (\$(INC),yes)
|
|---|
| 57 | -include 1.inc 2.inc
|
|---|
| 58 | endif
|
|---|
| 59 |
|
|---|
| 60 | 1.inc: ; \@echo ONE.inc; $sleep_command 2; echo TWO.inc; echo '1: ; \@echo ONE; $sleep_command 2; echo TWO' > \$\@
|
|---|
| 61 | 2.inc: ; \@$sleep_command 1; echo THREE.inc; echo '2: ; \@$sleep_command 1; echo THREE' > \$\@",
|
|---|
| 62 | "-j4",
|
|---|
| 63 | "ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n");
|
|---|
| 64 |
|
|---|
| 65 | unlink('1.inc', '2.inc');
|
|---|
| 66 |
|
|---|
| 67 | # Grant Taylor reports a problem where tokens can be lost (not written back
|
|---|
| 68 | # to the pipe when they should be): this happened when there is a $(shell ...)
|
|---|
| 69 | # function in an exported recursive variable. I added some code to check
|
|---|
| 70 | # for this situation and print a message if it occurred. This test used
|
|---|
| 71 | # to trigger this code when I added it but no longer does after the fix.
|
|---|
| 72 |
|
|---|
| 73 | run_make_test("
|
|---|
| 74 | export HI = \$(shell \$(\$\@.CMD))
|
|---|
| 75 | first.CMD = echo hi
|
|---|
| 76 | second.CMD = $sleep_command 4; echo hi
|
|---|
| 77 |
|
|---|
| 78 | .PHONY: all first second
|
|---|
| 79 | all: first second
|
|---|
| 80 |
|
|---|
| 81 | first second: ; \@echo \$\@; $sleep_command 1; echo \$\@",
|
|---|
| 82 | '-j2', "first\nfirst\nsecond\nsecond");
|
|---|
| 83 |
|
|---|
| 84 | # Michael Matz <matz@suse.de> reported a bug where if make is running in
|
|---|
| 85 | # parallel without -k and two jobs die in a row, but not too close to each
|
|---|
| 86 | # other, then make will quit without waiting for the rest of the jobs to die.
|
|---|
| 87 |
|
|---|
| 88 | run_make_test("
|
|---|
| 89 | .PHONY: all fail.1 fail.2 fail.3 ok
|
|---|
| 90 | all: fail.1 ok fail.2 fail.3
|
|---|
| 91 |
|
|---|
| 92 | fail.1 fail.2 fail.3:
|
|---|
| 93 | \@sleep \$(patsubst fail.%,%,\$\@)
|
|---|
| 94 | \@echo Fail
|
|---|
| 95 | \@exit 1
|
|---|
| 96 |
|
|---|
| 97 | ok:
|
|---|
| 98 | \@sleep 4
|
|---|
| 99 | \@echo Ok done",
|
|---|
| 100 | '-rR -j5', 'Fail
|
|---|
| 101 | #MAKE#: *** [fail.1] Error 1
|
|---|
| 102 | #MAKE#: *** Waiting for unfinished jobs....
|
|---|
| 103 | Fail
|
|---|
| 104 | #MAKE#: *** [fail.2] Error 1
|
|---|
| 105 | Fail
|
|---|
| 106 | #MAKE#: *** [fail.3] Error 1
|
|---|
| 107 | Ok done',
|
|---|
| 108 | 512);
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 | # Test for Savannah bug #15641.
|
|---|
| 112 | #
|
|---|
| 113 | run_make_test('
|
|---|
| 114 | .PHONY: all
|
|---|
| 115 | all:; @:
|
|---|
| 116 |
|
|---|
| 117 | -include foo.d
|
|---|
| 118 |
|
|---|
| 119 | foo.d: comp
|
|---|
| 120 | @echo building $@
|
|---|
| 121 |
|
|---|
| 122 | comp: mod_a.o mod_b.o; @:
|
|---|
| 123 |
|
|---|
| 124 | mod_a.o mod_b.o:
|
|---|
| 125 | @exit 1
|
|---|
| 126 | ', '-j2', '');
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 | # Make sure that all jobserver FDs are closed if we need to re-exec the
|
|---|
| 130 | # master copy.
|
|---|
| 131 | #
|
|---|
| 132 | # First, find the "default" file descriptors we normally use
|
|---|
| 133 | # Then make sure they're still used.
|
|---|
| 134 | #
|
|---|
| 135 | # Right now we don't have a way to run a makefile and capture the output
|
|---|
| 136 | # without checking it, so we can't really write this test.
|
|---|
| 137 |
|
|---|
| 138 | # run_make_test('
|
|---|
| 139 | # submake: ; @$(MAKE) --no-print-directory -f #MAKEFILE# fdprint 5>output
|
|---|
| 140 |
|
|---|
| 141 | # dependfile: ; @echo FOO=bar > $@
|
|---|
| 142 |
|
|---|
| 143 | # INCL := true
|
|---|
| 144 |
|
|---|
| 145 | # FOO=foo
|
|---|
| 146 | # ifeq ($(INCL),true)
|
|---|
| 147 | # -include dependfile
|
|---|
| 148 | # endif
|
|---|
| 149 |
|
|---|
| 150 | # fdprint: ; @echo $(filter --jobserver%,$(MAKEFLAGS))
|
|---|
| 151 |
|
|---|
| 152 | # recurse: ; @$(MAKE) --no-print-directory -f #MAKEFILE# submake INCL=true',
|
|---|
| 153 | # '-j2 INCL=false fdprint',
|
|---|
| 154 | # 'bar');
|
|---|
| 155 |
|
|---|
| 156 | # unlink('dependfile', 'output');
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 | # # Do it again, this time where the include is done by the non-master make.
|
|---|
| 160 | # run_make_test(undef, '-j2 recurse INCL=false', 'bar');
|
|---|
| 161 |
|
|---|
| 162 | # unlink('dependfile', 'output');
|
|---|
| 163 |
|
|---|
| 164 | 1;
|
|---|