1/*
2 * regression test support
3 *
4 * @(#)TEST.mk (AT&T Labs Research) 2009-03-19
5 *
6 * test management is still in the design phase
7 */
8
9/*
10 * three forms for :TEST:
11 *
12 *	:TEST: xxx yyy ...
13 *
14 *		$(REGRESS) $(REGRESSFLAGS) xxx.tst
15 *		$(REGRESS) $(REGRESSFLAGS) yyy.tst
16 *
17 *	:TEST: xxx.tst yyy ...
18 *
19 *		$(REGRESS) $(REGRESSFLAGS) xxx.tst yyy ...
20 *
21 *	:TEST: xxx.c [ :: test-prereq ... :: ] [ args [ : args ... ] ]
22 *
23 *	:TEST: xxx.sh [ :: test-prereq ... :: ] [ args [ : args ... ] ]
24 *
25 *	xxx :TEST: prereq ...
26 *		[ action ]
27 *
28 *		$(*) if no action
29 */
30
31":TEST:" : .MAKE .OPERATOR
32	local B G P S T
33	test : .INSERT .TESTINIT
34	if "$("tests":T=FD)"
35		.SOURCE : tests
36	end
37	P := $(>:O=1)
38	if "$(P:N=*.tst)" && ! "$(@:V)"
39		B := $(P:B)
40		if ! ( T = "$(<:V)" )
41			T := $(B)
42		end
43		test : - test.$(T)
44		eval
45			test.$$(T) : $$(B).tst
46				$$(REGRESS) $$(REGRESSFLAGS) $$(*) $(>:V:O>1)
47			:SAVE: $$(B).tst
48		end
49	elif "$(P:N=*@(.sh|$(.SUFFIX.c:/ /|/G)|$(.SUFFIX.C:/ /|/G)))"
50		B := $(P:B)
51		if ! ( T = "$(<:V)" )
52			T := $(B)
53		end
54		:INSTALLDIR: $(B)
55		$(B) :: $(P)
56		if "$(P:N=*.sh)"
57			TESTCC == $(CC)
58			$(B) : (TESTCC)
59		end
60		test : - test.$(T)
61		if "$(@:V)"
62			eval
63				test.$$(T) : $$(B) $(>:V:O>1)
64					set +x; (ulimit -c 0) >/dev/null 2>&1 && ulimit -c 0; set -x
65					$(@:V)
66			end
67		elif "$(>:V:O>1)"
68			local I A V X S R=0
69			for A $(>:V:O>1)
70				if A == "::"
71					let R = !R
72				elif A == ":"
73					let I = I + 1
74					test.$(T).$(I) := $(V:V)
75					V =
76					X := $(X:V)$(S)$$(*) $$(test.$(T).$(I):T=*)
77					S = $("\n")
78				elif R
79					test.$(A) : .VIRTUAL .FORCE
80					test.$(T) : test.$(A)
81				else
82					V += $(A:V)
83				end
84			end
85			if V
86				let I = I + 1
87				test.$(T).$(I) := $(V:V)
88				X := $(X:V)$(S)$$(*) $$(test.$(T).$(I):T=*)
89			end
90			eval
91				test.$$(T) : $$(B)
92					set +x; (ulimit -c 0) >/dev/null 2>&1 && ulimit -c 0; set -x
93					$(X:V)
94			end
95		else
96			eval
97				test.$$(T) : $$(B)
98					set +x; (ulimit -c 0) >/dev/null 2>&1 && ulimit -c 0; set -x
99					$$(*)
100			end
101		end
102	elif ! "$(<:V)"
103		G = 1
104		for B $(>)
105			if B == "-|--"
106				let G = !G
107			else
108				if ! G
109					T =
110				elif ! ( T = "$(B:A=.COMMAND)" ) && ! "$(B:A=.TARGET)"
111					for S .c .sh
112						if "$(B:B:S=$(S):T=F)"
113							:INSTALLDIR: $(B)
114							$(B) :: $(B:B:S=$(S))
115							T := $(B)
116							break
117						end
118					end
119				end
120				test : - test.$(B)
121				test.$(B) : $(T) - $(B).tst
122					$(REGRESS) $(REGRESSFLAGS) $(*:N=*.tst) $(*:N!=*.tst)
123				:SAVE: $(B).tst
124			end
125		end
126	else
127		if "$(>:V)" || "$(@:V)"
128			P := $(>)
129			T := $(P:O=1)
130			B := $(T:B)
131			if "$(T)" != "$(B)" && "$(T:G=$(B))"
132				:INSTALLDIR: $(B)
133				$(B) :: $(T) $(P:O>1:N=-*)
134				T := $(B)
135				P := $(B) $(P:O>1:N!=-*)
136			end
137			if "$(<:V)"
138				T := $(<:V)
139			end
140			test : - test.$(T)
141			if "$(@:V)"
142				eval
143				test.$$(T) : $$(P) $(>:V:O>1)
144					set +x; (ulimit -c 0) >/dev/null 2>&1 && ulimit -c 0; set -x
145					$(@:V)
146				end
147			else
148				test.$(T) : $(P)
149					set +x; (ulimit -c 0) >/dev/null 2>&1 && ulimit -c 0; set -x
150					$(*)
151			end
152		else
153			test : - test.$(<)
154			test.$(<) : $(<).tst $(<:A=.COMMAND)
155				$(REGRESS) $(REGRESSFLAGS) $(*)
156		end
157	end
158
159.TESTINIT : .MAKE .VIRTUAL .FORCE .REPEAT
160	if VARIANT == "DLL"
161		error 1 :DLL: tests skipped
162		exit 0
163	end
164	set keepgoing
165	REGRESSFLAGS &= $(TESTS:@/ /|/G:/.*/--test=&/:@Q)
166
167.SCAN.tst : .SCAN
168	$(@.SCAN.sh)
169	I| INCLUDE@ % |
170
171.ATTRIBUTE.%.tst : .SCAN.tst
172
173MKTEST = mktest
174MKTESTFLAGS = --style=regress
175
176/*
177 * test scripts are only regenerated from *.rt when --force
178 * is specified or the .rt file is newer than the script
179 * otherwise the script is accepted if it exists
180 *
181 * this avoids the case where a fresh build with no state
182 * would regenerate the test script and capture current
183 * behavior instead of expected behavior
184 */
185
186%.tst : %.rt
187	if	[[ "$(-force)" || "$(>)" -nt "$(^|<)" ]]
188	then	$(MKTEST) $(MKTESTFLAGS) $(>) > $(<)
189	fi
190
191test%.sh test%.out : %.rt
192	if	[[ "$(-force)" || "$(>)" -nt "$(^|<:O=1)" ]]
193	then	$(MKTEST) --style=shell $(>) > $(<:N=*.sh)
194		$(SHELL) $(<:N=*.sh) --accept > $(<:N=*.out)
195	fi
196