xref: /openbsd-src/share/mk/bsd.regress.mk (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1# $OpenBSD: bsd.regress.mk,v 1.13 2014/07/19 18:15:53 miod Exp $
2# Documented in bsd.regress.mk(5)
3
4# No man pages for regression tests.
5NOMAN=
6
7# No installation.
8install:
9
10# If REGRESS_TARGETS is defined and PROG is not defined, set NOPROG
11.if defined(REGRESS_TARGETS) && !defined(PROG)
12NOPROG=
13.endif
14
15.include <bsd.prog.mk>
16
17.MAIN: all
18all: regress
19
20# Check for deprecated REGRESS* variables and assign them to the
21# new versions if the new version is not already defined.
22_REGRESS_DEPRECATED=LOG:LOG SKIPTARGETS:SKIP_TARGETS SKIPSLOW:SKIP_SLOW \
23	SKIP:SKIP TARGETS:TARGETS MAXTIME:MAXTIME ROOTTARGETS:ROOT_TARGETS
24
25.for _I in ${_REGRESS_DEPRECATED}
26_REGRESS_OLD=REGRESS${_I:C/\:.*//}
27_REGRESS_NEW=REGRESS_${_I:C/.*\://}
28.  if defined(${_REGRESS_OLD})
29ERRORS:= ${ERRORS} "Warning: ${_REGRESS_OLD} is deprecated, use ${_REGRESS_NEW} instead."
30.    if !defined(${_REGRESS_NEW})
31${_REGRESS_NEW}:=${${_REGRESS_OLD}}
32.    endif
33.  endif
34.endfor
35
36# XXX - Need full path to REGRESS_LOG, otherwise there will be much pain.
37REGRESS_LOG?=/dev/null
38REGRESS_SKIP_TARGETS?=
39REGRESS_SKIP_SLOW?=no
40REGRESS_FAIL_EARLY?=no
41
42_REGRESS_NAME=${.CURDIR:S/${BSDSRCDIR}\/regress\///}
43_REGRESS_TMP?=/dev/null
44_REGRESS_OUT= | tee -a ${REGRESS_LOG} ${_REGRESS_TMP} 2>&1 > /dev/null
45
46.if defined(PROG) && !empty(PROG)
47run-regress-${PROG}: ${PROG}
48	./${PROG}
49.endif
50
51.if defined(PROG) && !defined(REGRESS_TARGETS)
52REGRESS_TARGETS=run-regress-${PROG}
53.  if defined(REGRESS_SKIP)
54REGRESS_SKIP_TARGETS=run-regress-${PROG}
55.  endif
56.endif
57
58.if defined(REGRESS_SLOW_TARGETS) && ${REGRESS_SKIP_SLOW} != no
59REGRESS_SKIP_TARGETS+=${REGRESS_SLOW_TARGETS}
60.endif
61
62.if ${REGRESS_FAIL_EARLY} != no
63_SKIP_FAIL=
64.else
65_SKIP_FAIL=-
66.endif
67
68.if defined(REGRESS_ROOT_TARGETS)
69_ROOTUSER!=id -g
70SUDO?=
71.  if (${_ROOTUSER} != 0) && empty(SUDO)
72REGRESS_SKIP_TARGETS+=${REGRESS_ROOT_TARGETS}
73.  endif
74.endif
75
76.if defined(ERRORS)
77.BEGIN:
78.  for _m in ${ERRORS}
79	@echo 1>&2 ${_m}
80.  endfor
81.  if !empty(ERRORS:M"Fatal\:*") || !empty(ERRORS:M'Fatal\:*')
82	@exit 1
83.  endif
84.endif
85
86regress: .SILENT
87.if ! ${REGRESS_LOG:M/*}
88	echo =========================================================
89	echo REGRESS_LOG must contain an absolute path to the log-file.
90	echo It currently points to: ${REGRESS_LOG}
91	echo =========================================================
92	exit 1
93.endif
94.for RT in ${REGRESS_TARGETS}
95.  if ${REGRESS_SKIP_TARGETS:M${RT}}
96	@echo -n "SKIP " ${_REGRESS_OUT}
97.  else
98# XXX - we need a better method to see if a test fails due to timeout or just
99#       normal failure.
100.   if !defined(REGRESS_MAXTIME)
101	${_SKIP_FAIL}if cd ${.CURDIR} && ${MAKE} ${RT}; then \
102	    echo -n "SUCCESS " ${_REGRESS_OUT} ; \
103	else \
104	    echo -n "FAIL " ${_REGRESS_OUT} ; \
105	    echo FAILED ; \
106	    false; \
107	fi
108.   else
109	${_SKIP_FAIL}if cd ${.CURDIR} && \
110	    (ulimit -t ${REGRESS_MAXTIME} ; ${MAKE} ${RT}); then \
111	    echo -n "SUCCESS " ${_REGRESS_OUT} ; \
112	else \
113	    echo -n "FAIL (possible timeout) " ${_REGRESS_OUT} ; \
114	    echo FAILED ; \
115	    false; \
116	fi
117.   endif
118.  endif
119	@echo ${_REGRESS_NAME}/${RT:S/^run-regress-//} ${_REGRESS_OUT}
120.endfor
121
122.PHONY: regress
123