1263172Sjmmv# $FreeBSD: stable/10/share/mk/suite.test.mk 313792 2017-02-16 05:22:08Z ngie $
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# Name of the test suite these tests belong to.  Should rarely be changed for
12263172Sjmmv# Makefiles built into the FreeBSD src tree.
13263172SjmmvTESTSUITE?= FreeBSD
14263172Sjmmv
15263172Sjmmv# Knob to control the handling of the Kyuafile for this Makefile.
16263172Sjmmv#
17263172Sjmmv# If 'yes', a Kyuafile exists in the source tree and is installed into
18263172Sjmmv# TESTSDIR.
19263172Sjmmv#
20263172Sjmmv# If 'auto', a Kyuafile is automatically generated based on the list of test
21263172Sjmmv# programs built by the Makefile and is installed into TESTSDIR.  This is the
22263172Sjmmv# default and is sufficient in the majority of the cases.
23263172Sjmmv#
24263172Sjmmv# If 'no', no Kyuafile is installed.
25263172SjmmvKYUAFILE?= auto
26263172Sjmmv
27263172Sjmmv# Per-test program interface definition.
28263172Sjmmv#
29263172Sjmmv# The name provided here must match one of the interface names supported by
30263172Sjmmv# Kyua as this is later encoded in the Kyuafile test program definitions.
31263172Sjmmv#TEST_INTERFACE.<test-program>= interface-name
32263172Sjmmv
33313790Sngie# Metadata properties applicable to all test programs.
34313790Sngie#
35313790Sngie# All the variables for a test program defined in the Makefile are appended
36313790Sngie# to the test program's definition in the Kyuafile.  This feature can be
37313790Sngie# used to avoid having to explicitly supply a Kyuafile in the source
38313790Sngie# directory, allowing the caller Makefile to rely on the KYUAFILE=auto
39313790Sngie# behavior defined here.
40313790Sngie#TEST_METADATA+= key="value"
41313790Sngie
42263172Sjmmv# Per-test program metadata properties as a list of key/value pairs.
43263172Sjmmv#
44313790Sngie# These per-test program settings _extend_ the values provided in the
45313790Sngie# unqualified TEST_METADATA variable.
46263172Sjmmv#TEST_METADATA.<test-program>+= key="value"
47263172Sjmmv
48292768Sngie.if ${KYUAFILE:tl} != "no"
49263172SjmmvFILES+=	Kyuafile
50263172SjmmvFILESDIR_Kyuafile= ${TESTSDIR}
51292768Sngie.endif
52263172Sjmmv
53313790Sngie.for _T in ${_TESTS}
54313790Sngie_TEST_METADATA.${_T}= ${TEST_METADATA} ${TEST_METADATA.${_T}}
55313790Sngie.endfor
56313790Sngie
57292768Sngie.if ${KYUAFILE:tl} == "auto"
58292768SngieCLEANFILES+= Kyuafile Kyuafile.tmp
59292768SngieKyuafile: Makefile
60263172Sjmmv	@{ \
61263172Sjmmv	    echo '-- Automatically generated by bsd.test.mk.'; \
62263172Sjmmv	    echo; \
63263172Sjmmv	    echo 'syntax(2)'; \
64263172Sjmmv	    echo; \
65263172Sjmmv	    echo 'test_suite("${TESTSUITE}")'; \
66263172Sjmmv            echo; \
67292768Sngie	} > ${.TARGET}.tmp
68263172Sjmmv.for _T in ${_TESTS}
69289050Sbdrewery.if defined(.PARSEDIR)
70313790Sngie	@echo '${TEST_INTERFACE.${_T}}_test_program{name="${_T}"${_TEST_METADATA.${_T}:C/$/,/:tW:C/^/, /W:C/,$//W}}' \
71292768Sngie	    >>${.TARGET}.tmp
72289050Sbdrewery.else
73313790Sngie	@echo '${TEST_INTERFACE.${_T}}_test_program{name="${_T}"${_TEST_METADATA.${_T}:C/^/, /:Q:S/\\ ,/,/g:S,\\,,g}}' \
74313792Sngie	    >>${.TARGET}.tmp
75289050Sbdrewery.endif
76263172Sjmmv.endfor
77263172Sjmmv.for _T in ${TESTS_SUBDIRS:N.WAIT}
78292768Sngie	@echo "include(\"${_T}/${.TARGET}\")" >>${.TARGET}.tmp
79263172Sjmmv.endfor
80292768Sngie	@mv ${.TARGET}.tmp ${.TARGET}
81263172Sjmmv.endif
82263172Sjmmv
83313790SngieCHECKDIR?=	${DESTDIR}${TESTSDIR}
84313790Sngie
85292812SngieKYUA= ${LOCALBASE}/bin/kyua
86313790Sngie
87313790Sngie# Definition of the "make check" target and supporting variables.
88263172Sjmmv#
89263172Sjmmv# This target, by necessity, can only work for native builds (i.e. a FreeBSD
90263172Sjmmv# host building a release for the same system).  The target runs Kyua, which is
91263172Sjmmv# not in the toolchain, and the tests execute code built for the target host.
92263172Sjmmv#
93263172Sjmmv# Due to the dependencies of the binaries built by the source tree and how they
94263172Sjmmv# are used by tests, it is highly possible for a execution of "make test" to
95263172Sjmmv# report bogus results unless the new binaries are put in place.
96263172Sjmmv
97313790Sngierealcheck: .PHONY
98313790Sngie	@if [ ! -x ${KYUA} ]; then \
99313790Sngie		echo; \
100313790Sngie		echo "kyua binary not installed at expected location (${.TARGET})"; \
101313790Sngie		echo; \
102313790Sngie		echo "Please install via pkg install, or specify the path to the kyua"; \
103313790Sngie		echo "package via the \$${LOCALBASE} variable, e.g. "; \
104313790Sngie		echo "LOCALBASE=\"${LOCALBASE}\""; \
105313790Sngie		false; \
106313790Sngie	fi
107313790Sngie	@${KYUA} test -k ${CHECKDIR}/Kyuafile
108