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