xref: /freebsd/share/mk/suite.test.mk (revision 410556f1f10fd35b350102725fd8504c3cb0afc8)
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.include <bsd.opts.mk>
12
13# Name of the test suite these tests belong to.  Should rarely be changed for
14# Makefiles built into the FreeBSD src tree.
15TESTSUITE?= FreeBSD
16
17# Knob to control the handling of the Kyuafile for this Makefile.
18#
19# If 'yes', a Kyuafile exists in the source tree and is installed into
20# TESTSDIR.
21#
22# If 'auto', a Kyuafile is automatically generated based on the list of test
23# programs built by the Makefile and is installed into TESTSDIR.  This is the
24# default and is sufficient in the majority of the cases.
25#
26# If 'no', no Kyuafile is installed.
27KYUAFILE?= auto
28
29# Per-test program interface definition.
30#
31# The name provided here must match one of the interface names supported by
32# Kyua as this is later encoded in the Kyuafile test program definitions.
33#TEST_INTERFACE.<test-program>= interface-name
34
35# Metadata properties applicable to all test programs.
36#
37# All the variables for a test program defined in the Makefile are appended
38# to the test program's definition in the Kyuafile.  This feature can be
39# used to avoid having to explicitly supply a Kyuafile in the source
40# directory, allowing the caller Makefile to rely on the KYUAFILE=auto
41# behavior defined here.
42#TEST_METADATA+= key="value"
43
44# Per-test program metadata properties as a list of key/value pairs.
45#
46# These per-test program settings _extend_ the values provided in the
47# unqualified TEST_METADATA variable.
48#TEST_METADATA.<test-program>+= key="value"
49
50.if ${KYUAFILE:tl} != "no"
51${PACKAGE}FILES+=	Kyuafile
52${PACKAGE}FILESDIR_Kyuafile=	${TESTSDIR}
53.endif
54
55.for _T in ${_TESTS}
56_TEST_METADATA.${_T}= ${TEST_METADATA} ${TEST_METADATA.${_T}}
57.endfor
58
59.if ${KYUAFILE:tl} == "auto"
60CLEANFILES+= Kyuafile Kyuafile.tmp
61Kyuafile: Makefile
62	@{ \
63	    echo '-- Automatically generated by bsd.test.mk.'; \
64	    echo; \
65	    echo 'syntax(2)'; \
66	    echo; \
67	    echo 'test_suite("${TESTSUITE}")'; \
68            echo; \
69	} > ${.TARGET}.tmp
70.for _T in ${_TESTS}
71	@echo '${TEST_INTERFACE.${_T}}_test_program{name="${_T}"${_TEST_METADATA.${_T}:C/$/,/:tW:C/^/, /W:C/,$//W}}' \
72	    >>${.TARGET}.tmp
73.endfor
74.for _T in ${TESTS_SUBDIRS:N.WAIT}
75	@echo "include(\"${_T}/${.TARGET}\")" >>${.TARGET}.tmp
76.endfor
77	@mv ${.TARGET}.tmp ${.TARGET}
78.endif
79
80KYUA?=	kyua
81
82# Definition of the "make check" target and supporting variables.
83#
84# This target, by necessity, can only work for native builds (i.e. a FreeBSD
85# host building a release for the same system).  The target runs Kyua, which is
86# not in the toolchain, and the tests execute code built for the target host.
87#
88# Due to the dependencies of the binaries built by the source tree and how they
89# are used by tests, it is highly possible for a execution of "make test" to
90# report bogus results unless the new binaries are put in place.
91
92realcheck: .PHONY
93	@if ! which -s "${KYUA}"; then \
94		echo; \
95		echo "kyua binary not installed at expected location (${.TARGET})"; \
96		echo; \
97		echo "Please install via pkg install, or specify the path to the kyua"; \
98		echo "binary via the \$${KYUA} variable, e.g., "; \
99		echo "KYUA=\"${LOCALBASE}/bin/kyua\""; \
100		false; \
101	fi
102	@env ${TESTS_ENV:Q} ${KYUA} test -k ${DESTDIR}${TESTSDIR}/Kyuafile
103
104MAKE_CHECK_SANDBOX_DIR=	checkdir
105CLEANDIRS+=	${MAKE_CHECK_SANDBOX_DIR}
106
107.if ${MK_MAKE_CHECK_USE_SANDBOX} != "no" && make(check)
108DESTDIR:=	${.OBJDIR}/${MAKE_CHECK_SANDBOX_DIR}
109
110beforecheck:
111.for t in clean depend all
112	@cd ${.CURDIR} && ${MAKE} $t
113.endfor
114	@cd ${SRCTOP} && ${MAKE} hierarchy DESTDIR=${DESTDIR}
115	@cd ${.CURDIR} && ${MAKE} install \
116	    DESTDIR=${DESTDIR}
117
118# NOTE: this is intentional to ensure that "make check" can be run multiple
119#       times. "aftercheck" won't be run if "make check" fails, is interrupted,
120#       etc.
121aftercheck:
122	@cd ${.CURDIR} && ${MAKE} clean
123	@test ! -e ${DESTDIR} || chflags -R 0 "${DESTDIR}"
124	@rm -Rf "${DESTDIR}"
125
126.endif
127