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