1263172Sjmmv# $FreeBSD$
2263172Sjmmv#
3263172Sjmmv# You must include bsd.test.mk instead of this file from your Makefile.
4263172Sjmmv#
5263172Sjmmv# Internal glue for the build of /usr/tests/.
6263172Sjmmv
7263172Sjmmv.if !target(__<bsd.test.mk>__)
8263172Sjmmv.error suite.test.mk cannot be included directly.
9263172Sjmmv.endif
10263172Sjmmv
11263172Sjmmv# Directory in which to install tests defined by the current Makefile.
12263172Sjmmv# Makefiles have to override this to point to a subdirectory of TESTSBASE.
13263172SjmmvTESTSDIR?= .
14263172Sjmmv
15263172Sjmmv# Name of the test suite these tests belong to.  Should rarely be changed for
16263172Sjmmv# Makefiles built into the FreeBSD src tree.
17263172SjmmvTESTSUITE?= FreeBSD
18263172Sjmmv
19263172Sjmmv# Knob to control the handling of the Kyuafile for this Makefile.
20263172Sjmmv#
21263172Sjmmv# If 'yes', a Kyuafile exists in the source tree and is installed into
22263172Sjmmv# TESTSDIR.
23263172Sjmmv#
24263172Sjmmv# If 'auto', a Kyuafile is automatically generated based on the list of test
25263172Sjmmv# programs built by the Makefile and is installed into TESTSDIR.  This is the
26263172Sjmmv# default and is sufficient in the majority of the cases.
27263172Sjmmv#
28263172Sjmmv# If 'no', no Kyuafile is installed.
29263172SjmmvKYUAFILE?= auto
30263172Sjmmv
31263172Sjmmv# Per-test program interface definition.
32263172Sjmmv#
33263172Sjmmv# The name provided here must match one of the interface names supported by
34263172Sjmmv# Kyua as this is later encoded in the Kyuafile test program definitions.
35263172Sjmmv#TEST_INTERFACE.<test-program>= interface-name
36263172Sjmmv
37263172Sjmmv# Per-test program metadata properties as a list of key/value pairs.
38263172Sjmmv#
39263172Sjmmv# All the variables for a particular program are appended to the program's
40263172Sjmmv# definition in the Kyuafile.  This feature can be used to avoid having to
41263172Sjmmv# explicitly supply a Kyuafile in the source directory, allowing the caller
42263172Sjmmv# Makefile to rely on the KYUAFILE=auto behavior defined here.
43263172Sjmmv#TEST_METADATA.<test-program>+= key="value"
44263172Sjmmv
45263172Sjmmv# Path to the prefix of the installed Kyua CLI, if any.
46263172Sjmmv#
47263172Sjmmv# If kyua is installed from ports, we automatically define a realtest target
48263172Sjmmv# below to run the tests using this tool.  The tools are searched for in the
49263172Sjmmv# hierarchy specified by this variable.
50263172SjmmvKYUA_PREFIX?= /usr/local
51263172Sjmmv
52263172Sjmmv.if ${KYUAFILE:tl} == "yes"
53263172SjmmvFILES+=	Kyuafile
54263172SjmmvFILESDIR_Kyuafile= ${TESTSDIR}
55263172Sjmmv
56263172SjmmvCLEANFILES+= Kyuafile.auto Kyuafile.auto.tmp
57263172Sjmmv.elif ${KYUAFILE:tl} == "auto"
58263172SjmmvFILES+=	Kyuafile.auto
59263172SjmmvFILESDIR_Kyuafile.auto= ${TESTSDIR}
60263172SjmmvFILESNAME_Kyuafile.auto= Kyuafile
61263172Sjmmv
62263172SjmmvCLEANFILES+= Kyuafile.auto Kyuafile.auto.tmp
63263172Sjmmv
64263172Sjmmv.NOPATH: Kyuafile.auto
65263172SjmmvKyuafile.auto: Makefile
66263172Sjmmv	@{ \
67263172Sjmmv	    echo '-- Automatically generated by bsd.test.mk.'; \
68263172Sjmmv	    echo; \
69263172Sjmmv	    echo 'syntax(2)'; \
70263172Sjmmv	    echo; \
71263172Sjmmv	    echo 'test_suite("${TESTSUITE}")'; \
72263172Sjmmv            echo; \
73263172Sjmmv	} >Kyuafile.auto.tmp
74263172Sjmmv.for _T in ${_TESTS}
75263172Sjmmv	@echo '${TEST_INTERFACE.${_T}}_test_program{name="${_T}"${TEST_METADATA.${_T}:C/$/,/:tW:C/^/, /W:C/,$//W}}' \
76263172Sjmmv	    >>Kyuafile.auto.tmp
77263172Sjmmv.endfor
78263172Sjmmv.for _T in ${TESTS_SUBDIRS:N.WAIT}
79263172Sjmmv	@echo "include(\"${_T}/Kyuafile\")" >>Kyuafile.auto.tmp
80263172Sjmmv.endfor
81263172Sjmmv	@mv Kyuafile.auto.tmp Kyuafile.auto
82263172Sjmmv.endif
83263172Sjmmv
84263172SjmmvKYUA?= ${KYUA_PREFIX}/bin/kyua
85263172Sjmmv.if exists(${KYUA})
86263172Sjmmv# Definition of the "make test" target and supporting variables.
87263172Sjmmv#
88263172Sjmmv# This target, by necessity, can only work for native builds (i.e. a FreeBSD
89263172Sjmmv# host building a release for the same system).  The target runs Kyua, which is
90263172Sjmmv# not in the toolchain, and the tests execute code built for the target host.
91263172Sjmmv#
92263172Sjmmv# Due to the dependencies of the binaries built by the source tree and how they
93263172Sjmmv# are used by tests, it is highly possible for a execution of "make test" to
94263172Sjmmv# report bogus results unless the new binaries are put in place.
95263172Sjmmvrealtest: .PHONY
96263172Sjmmv	@echo "*** WARNING: make test is experimental"
97263172Sjmmv	@echo "***"
98263172Sjmmv	@echo "*** Using this test does not preclude you from running the tests"
99263172Sjmmv	@echo "*** installed in ${TESTSBASE}.  This test run may raise false"
100263172Sjmmv	@echo "*** positives and/or false negatives."
101263172Sjmmv	@echo
102263172Sjmmv	@set -e; \
103263172Sjmmv	${KYUA} test -k ${DESTDIR}${TESTSDIR}/Kyuafile; \
104263172Sjmmv	result=0; \
105263172Sjmmv	echo; \
106263172Sjmmv	echo "*** Once again, note that "make test" is unsupported."; \
107263172Sjmmv	test $${result} -eq 0
108263172Sjmmv.endif
109263172Sjmmv
110263172Sjmmvbeforetest: .PHONY
111263172Sjmmv.if defined(TESTSDIR)
112263172Sjmmv.if ${TESTSDIR} == ${TESTSBASE}
113263172Sjmmv# Forbid running from ${TESTSBASE}.  It can cause false positives/negatives and
114263172Sjmmv# it does not cover all the tests (e.g. it misses testing software in external).
115263172Sjmmv	@echo "*** Sorry, you cannot use make test from src/tests.  Install the"
116263172Sjmmv	@echo "*** tests into their final location and run them from ${TESTSBASE}"
117263172Sjmmv	@false
118263172Sjmmv.else
119263172Sjmmv	@echo "*** Using this test does not preclude you from running the tests"
120263172Sjmmv	@echo "*** installed in ${TESTSBASE}.  This test run may raise false"
121263172Sjmmv	@echo "*** positives and/or false negatives."
122263172Sjmmv.endif
123263172Sjmmv.else
124263172Sjmmv	@echo "*** No TESTSDIR defined; nothing to do."
125263172Sjmmv	@false
126263172Sjmmv.endif
127263172Sjmmv	@echo
128