xref: /freebsd/share/mk/suite.test.mk (revision fcb560670601b2a4d87bb31d7531c8dcc37ee71b)
1# $FreeBSD$
2#
3# You must include bsd.test.mk instead of this file from your Makefile.
4#
5# Internal glue for the build of /usr/tests/.
6
7.if !target(__<bsd.test.mk>__)
8.error suite.test.mk cannot be included directly.
9.endif
10
11# Directory in which to install tests defined by the current Makefile.
12# Makefiles have to override this to point to a subdirectory of TESTSBASE.
13TESTSDIR?= .
14
15# Name of the test suite these tests belong to.  Should rarely be changed for
16# Makefiles built into the FreeBSD src tree.
17TESTSUITE?= FreeBSD
18
19# Knob to control the handling of the Kyuafile for this Makefile.
20#
21# If 'yes', a Kyuafile exists in the source tree and is installed into
22# TESTSDIR.
23#
24# If 'auto', a Kyuafile is automatically generated based on the list of test
25# programs built by the Makefile and is installed into TESTSDIR.  This is the
26# default and is sufficient in the majority of the cases.
27#
28# If 'no', no Kyuafile is installed.
29KYUAFILE?= auto
30
31# Per-test program interface definition.
32#
33# The name provided here must match one of the interface names supported by
34# Kyua as this is later encoded in the Kyuafile test program definitions.
35#TEST_INTERFACE.<test-program>= interface-name
36
37# Per-test program metadata properties as a list of key/value pairs.
38#
39# All the variables for a particular program are appended to the program's
40# definition in the Kyuafile.  This feature can be used to avoid having to
41# explicitly supply a Kyuafile in the source directory, allowing the caller
42# Makefile to rely on the KYUAFILE=auto behavior defined here.
43#TEST_METADATA.<test-program>+= key="value"
44
45# Path to the prefix of the installed Kyua CLI, if any.
46#
47# If kyua is installed from ports, we automatically define a realtest target
48# below to run the tests using this tool.  The tools are searched for in the
49# hierarchy specified by this variable.
50KYUA_PREFIX?= /usr/local
51
52.if ${KYUAFILE:tl} == "yes"
53FILES+=	Kyuafile
54FILESDIR_Kyuafile= ${TESTSDIR}
55
56CLEANFILES+= Kyuafile.auto Kyuafile.auto.tmp
57.elif ${KYUAFILE:tl} == "auto"
58FILES+=	Kyuafile.auto
59FILESDIR_Kyuafile.auto= ${TESTSDIR}
60FILESNAME_Kyuafile.auto= Kyuafile
61
62CLEANFILES+= Kyuafile.auto Kyuafile.auto.tmp
63
64.NOPATH: Kyuafile.auto
65Kyuafile.auto: Makefile
66	@{ \
67	    echo '-- Automatically generated by bsd.test.mk.'; \
68	    echo; \
69	    echo 'syntax(2)'; \
70	    echo; \
71	    echo 'test_suite("${TESTSUITE}")'; \
72            echo; \
73	} >Kyuafile.auto.tmp
74.for _T in ${_TESTS}
75	@echo '${TEST_INTERFACE.${_T}}_test_program{name="${_T}"${TEST_METADATA.${_T}:C/$/,/:tW:C/^/, /W:C/,$//W}}' \
76	    >>Kyuafile.auto.tmp
77.endfor
78.for _T in ${TESTS_SUBDIRS:N.WAIT}
79	@echo "include(\"${_T}/Kyuafile\")" >>Kyuafile.auto.tmp
80.endfor
81	@mv Kyuafile.auto.tmp Kyuafile.auto
82.endif
83
84KYUA?= ${KYUA_PREFIX}/bin/kyua
85.if exists(${KYUA})
86# Definition of the "make test" target and supporting variables.
87#
88# This target, by necessity, can only work for native builds (i.e. a FreeBSD
89# host building a release for the same system).  The target runs Kyua, which is
90# not in the toolchain, and the tests execute code built for the target host.
91#
92# Due to the dependencies of the binaries built by the source tree and how they
93# are used by tests, it is highly possible for a execution of "make test" to
94# report bogus results unless the new binaries are put in place.
95realtest: .PHONY
96	@echo "*** WARNING: make test is experimental"
97	@echo "***"
98	@echo "*** Using this test does not preclude you from running the tests"
99	@echo "*** installed in ${TESTSBASE}.  This test run may raise false"
100	@echo "*** positives and/or false negatives."
101	@echo
102	@set -e; \
103	${KYUA} test -k ${DESTDIR}${TESTSDIR}/Kyuafile; \
104	result=0; \
105	echo; \
106	echo "*** Once again, note that "make test" is unsupported."; \
107	test $${result} -eq 0
108.endif
109
110beforetest: .PHONY
111.if defined(TESTSDIR)
112.if ${TESTSDIR} == ${TESTSBASE}
113# Forbid running from ${TESTSBASE}.  It can cause false positives/negatives and
114# it does not cover all the tests (e.g. it misses testing software in external).
115	@echo "*** Sorry, you cannot use make test from src/tests.  Install the"
116	@echo "*** tests into their final location and run them from ${TESTSBASE}"
117	@false
118.else
119	@echo "*** Using this test does not preclude you from running the tests"
120	@echo "*** installed in ${TESTSBASE}.  This test run may raise false"
121	@echo "*** positives and/or false negatives."
122.endif
123.else
124	@echo "*** No TESTSDIR defined; nothing to do."
125	@false
126.endif
127	@echo
128