xref: /illumos-gate/usr/src/contrib/ast/src/cmd/INIT/TEST.mk (revision b30d193948be5a7794d7ae3ba0ed9c2f72c88e0f)
1/*
2 * regression test support
3 *
4 * @(#)TEST.mk (AT&T Research) 2010-05-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) $(*:-l*|*$(CC.SUFFIX.ARCHIVE))
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 A != "-l*|*$(CC.SUFFIX.ARCHIVE)"
79					if R
80						test.$(A) : .VIRTUAL .FORCE
81						test.$(T) : test.$(A)
82					else
83						V += $(A:V)
84					end
85				end
86			end
87			if V
88				let I = I + 1
89				test.$(T).$(I) := $(V:V)
90				X := $(X:V)$(S)$$(*) $$(test.$(T).$(I):T=*)
91			end
92			eval
93				test.$$(T) : $$(B)
94					set +x; (ulimit -c 0) >/dev/null 2>&1 && ulimit -c 0; set -x
95					$(X:V)
96			end
97		else
98			eval
99				test.$$(T) : $$(B)
100					set +x; (ulimit -c 0) >/dev/null 2>&1 && ulimit -c 0; set -x
101					$$(*)
102			end
103		end
104	elif ! "$(<:V)"
105		G = 1
106		for B $(>)
107			if B == "-|--"
108				let G = !G
109			else
110				if ! G
111					T =
112				elif ! ( T = "$(B:A=.COMMAND)" ) && ! "$(B:A=.TARGET)"
113					for S .c .sh
114						if "$(B:B:S=$(S):T=F)"
115							:INSTALLDIR: $(B)
116							$(B) :: $(B:B:S=$(S))
117							T := $(B)
118							break
119						end
120					end
121				end
122				test : - test.$(B)
123				test.$(B) : $(T) - $(B).tst
124					$(REGRESS) $(REGRESSFLAGS) $(*:N=*.tst) $(*:N!=*.tst)
125				:SAVE: $(B).tst
126			end
127		end
128	else
129		if "$(>:V)" || "$(@:V)"
130			P := $(>)
131			T := $(P:O=1)
132			B := $(T:B)
133			if "$(T)" != "$(B)" && "$(T:G=$(B))"
134				:INSTALLDIR: $(B)
135				$(B) :: $(T) $(P:O>1:N=-*)
136				T := $(B)
137				P := $(B) $(P:O>1:N!=-*)
138			end
139			if "$(<:V)"
140				T := $(<:V)
141			end
142			test : - test.$(T)
143			if "$(@:V)"
144				eval
145				test.$$(T) : $$(P) $(>:V:O>1)
146					set +x; (ulimit -c 0) >/dev/null 2>&1 && ulimit -c 0; set -x
147					$(@:V)
148				end
149			else
150				test.$(T) : $(P)
151					set +x; (ulimit -c 0) >/dev/null 2>&1 && ulimit -c 0; set -x
152					$(*)
153			end
154		else
155			test : - test.$(<)
156			test.$(<) : $(<).tst $(<:A=.COMMAND)
157				$(REGRESS) $(REGRESSFLAGS) $(*)
158		end
159	end
160
161.TESTINIT : .MAKE .VIRTUAL .FORCE .REPEAT
162	if VARIANT == "DLL"
163		error 1 :DLL: tests skipped
164		exit 0
165	end
166	set keepgoing
167	REGRESSFLAGS &= $(TESTS:@/ /|/G:/.*/--test=&/:@Q)
168
169.SCAN.tst : .SCAN
170	$(@.SCAN.sh)
171	I| INCLUDE@ % |
172
173.ATTRIBUTE.%.tst : .SCAN.tst
174
175MKTEST = mktest
176MKTESTFLAGS = --style=regress
177
178/*
179 * test scripts are only regenerated from *.rt when --force
180 * is specified or the .rt file is newer than the script
181 * otherwise the script is accepted if it exists
182 *
183 * this avoids the case where a fresh build with no state
184 * would regenerate the test script and capture current
185 * behavior instead of expected behavior
186 */
187
188%.tst : %.rt
189	if	[[ "$(-force)" || "$(>)" -nt "$(^|<)" ]]
190	then	$(MKTEST) $(MKTESTFLAGS) $(>) > $(<)
191	fi
192
193test%.sh test%.out : %.rt
194	if	[[ "$(-force)" || "$(>)" -nt "$(^|<:O=1)" ]]
195	then	$(MKTEST) --style=shell $(>) > $(<:N=*.sh)
196		$(SHELL) $(<:N=*.sh) --accept > $(<:N=*.out)
197	fi
198