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