xref: /freebsd/contrib/bmake/unit-tests/dotwait.mk (revision 8aac90f18aef7c9eea906c3ff9a001ca7b94f375)
1# $NetBSD: dotwait.mk,v 1.3 2020/10/24 08:50:17 rillig Exp $
2
3THISMAKEFILE:=	${.PARSEDIR}/${.PARSEFILE}
4
5TESTS=	simple recursive shared cycle
6PAUSE=	sleep 1
7
8# Use a .for loop rather than dependencies here, to ensure
9# that the tests are run one by one, with parallelism
10# only within tests.
11# Ignore "--- target ---" lines printed by parallel make.
12all:
13.for t in ${TESTS}
14	@${.MAKE} -f ${THISMAKEFILE} -j4 $t 2>&1 | grep -v "^--- "
15.endfor
16
17#
18# Within each test, the names of the sub-targets follow these
19# conventions:
20# * If it's expected that two or more targets may be made in parallel,
21#   then the target names will differ only in an alphabetic component
22#   such as ".a" or ".b".
23# * If it's expected that two or more targets should be made in sequence
24#   then the target names will differ in numeric components, such that
25#   lexical ordering of the target names matches the expected order
26#   in which the targets should be made.
27#
28# Targets may echo ${PARALLEL_TARG} to print a modified version
29# of their own name, in which alphabetic components like ".a" or ".b"
30# are converted to ".*".  Two targets that are expected to
31# be made in parallel will thus print the same strings, so that the
32# output is independent of the order in which these targets are made.
33#
34PARALLEL_TARG= ${.TARGET:C/\.[a-z]/.*/g:Q}
35.DEFAULT:
36	@echo ${PARALLEL_TARG}; ${PAUSE}; echo ${PARALLEL_TARG}
37_ECHOUSE: .USE
38	@echo ${PARALLEL_TARG}; ${PAUSE}; echo ${PARALLEL_TARG}
39
40# simple: no recursion, no cycles
41simple: simple.1 .WAIT simple.2
42
43# recursive: all children of the left hand side of the .WAIT
44# must be made before any child of the right hand side.
45recursive: recursive.1.99 .WAIT recursive.2.99
46recursive.1.99: recursive.1.1.a recursive.1.1.b _ECHOUSE
47recursive.2.99: recursive.2.1.a recursive.2.1.b _ECHOUSE
48
49# shared: both shared.1.99 and shared.2.99 depend on shared.0.
50# shared.0 must be made first, even though it is a child of
51# the right hand side of the .WAIT.
52shared: shared.1.99 .WAIT shared.2.99
53shared.1.99: shared.0 _ECHOUSE
54shared.2.99: shared.2.1 shared.0 _ECHOUSE
55
56# cycle: the cyclic dependency must not cause infinite recursion
57# leading to stack overflow and a crash.
58cycle: cycle.1.99 .WAIT cycle.2.99
59cycle.2.99: cycle.2.98 _ECHOUSE
60cycle.2.98: cycle.2.97 _ECHOUSE
61cycle.2.97: cycle.2.99 _ECHOUSE
62