xref: /freebsd/share/mk/suite.test.mk (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1a784098cSJulio Merino#
2a784098cSJulio Merino# You must include bsd.test.mk instead of this file from your Makefile.
3a784098cSJulio Merino#
4a784098cSJulio Merino# Internal glue for the build of /usr/tests/.
5a784098cSJulio Merino
6a784098cSJulio Merino.if !target(__<bsd.test.mk>__)
7a784098cSJulio Merino.error suite.test.mk cannot be included directly.
8a784098cSJulio Merino.endif
9a784098cSJulio Merino
1038f8fddfSEnji Cooper.include <bsd.opts.mk>
1138f8fddfSEnji Cooper
12a784098cSJulio Merino# Name of the test suite these tests belong to.  Should rarely be changed for
13a784098cSJulio Merino# Makefiles built into the FreeBSD src tree.
14a784098cSJulio MerinoTESTSUITE?= FreeBSD
15a784098cSJulio Merino
16a784098cSJulio Merino# Knob to control the handling of the Kyuafile for this Makefile.
17a784098cSJulio Merino#
18a784098cSJulio Merino# If 'yes', a Kyuafile exists in the source tree and is installed into
19a784098cSJulio Merino# TESTSDIR.
20a784098cSJulio Merino#
21a784098cSJulio Merino# If 'auto', a Kyuafile is automatically generated based on the list of test
22a784098cSJulio Merino# programs built by the Makefile and is installed into TESTSDIR.  This is the
23a784098cSJulio Merino# default and is sufficient in the majority of the cases.
24a784098cSJulio Merino#
25a784098cSJulio Merino# If 'no', no Kyuafile is installed.
26a784098cSJulio MerinoKYUAFILE?= auto
27a784098cSJulio Merino
28a784098cSJulio Merino# Per-test program interface definition.
29a784098cSJulio Merino#
30a784098cSJulio Merino# The name provided here must match one of the interface names supported by
31a784098cSJulio Merino# Kyua as this is later encoded in the Kyuafile test program definitions.
32a784098cSJulio Merino#TEST_INTERFACE.<test-program>= interface-name
33a784098cSJulio Merino
3430161d03SJulio Merino# Metadata properties applicable to all test programs.
3530161d03SJulio Merino#
3630161d03SJulio Merino# All the variables for a test program defined in the Makefile are appended
3730161d03SJulio Merino# to the test program's definition in the Kyuafile.  This feature can be
3830161d03SJulio Merino# used to avoid having to explicitly supply a Kyuafile in the source
3930161d03SJulio Merino# directory, allowing the caller Makefile to rely on the KYUAFILE=auto
4030161d03SJulio Merino# behavior defined here.
4130161d03SJulio Merino#TEST_METADATA+= key="value"
4230161d03SJulio Merino
43a784098cSJulio Merino# Per-test program metadata properties as a list of key/value pairs.
44a784098cSJulio Merino#
4530161d03SJulio Merino# These per-test program settings _extend_ the values provided in the
4630161d03SJulio Merino# unqualified TEST_METADATA variable.
47a784098cSJulio Merino#TEST_METADATA.<test-program>+= key="value"
48a784098cSJulio Merino
49c4835f11SEnji Cooper.if ${KYUAFILE:tl} != "no"
50430f7286SEnji Cooper${PACKAGE}FILES+=	Kyuafile
51430f7286SEnji Cooper${PACKAGE}FILESDIR_Kyuafile=	${TESTSDIR}
52c4835f11SEnji Cooper.endif
53a784098cSJulio Merino
5430161d03SJulio Merino.for _T in ${_TESTS}
5530161d03SJulio Merino_TEST_METADATA.${_T}= ${TEST_METADATA} ${TEST_METADATA.${_T}}
5630161d03SJulio Merino.endfor
5730161d03SJulio Merino
58cc696e80SEnji Cooper.if ${KYUAFILE:tl} == "auto"
5971b7fa12SEnji CooperCLEANFILES+= Kyuafile Kyuafile.tmp
60c4835f11SEnji CooperKyuafile: Makefile
61a784098cSJulio Merino	@{ \
62a784098cSJulio Merino	    echo '-- Automatically generated by bsd.test.mk.'; \
63a784098cSJulio Merino	    echo; \
64a784098cSJulio Merino	    echo 'syntax(2)'; \
65a784098cSJulio Merino	    echo; \
66a784098cSJulio Merino	    echo 'test_suite("${TESTSUITE}")'; \
67a784098cSJulio Merino            echo; \
68c4835f11SEnji Cooper	} > ${.TARGET}.tmp
69a784098cSJulio Merino.for _T in ${_TESTS}
7030161d03SJulio Merino	@echo '${TEST_INTERFACE.${_T}}_test_program{name="${_T}"${_TEST_METADATA.${_T}:C/$/,/:tW:C/^/, /W:C/,$//W}}' \
71c4835f11SEnji Cooper	    >>${.TARGET}.tmp
72a784098cSJulio Merino.endfor
73a784098cSJulio Merino.for _T in ${TESTS_SUBDIRS:N.WAIT}
74fd6f8c37SEnji Cooper	@echo "include(\"${_T}/${.TARGET}\")" >>${.TARGET}.tmp
75a784098cSJulio Merino.endfor
76c4835f11SEnji Cooper	@mv ${.TARGET}.tmp ${.TARGET}
77a784098cSJulio Merino.endif
78a784098cSJulio Merino
79986deea5SKyle EvansKYUA?=	kyua
8071b7fa12SEnji Cooper
8171b7fa12SEnji Cooper# Definition of the "make check" target and supporting variables.
82a784098cSJulio Merino#
83a784098cSJulio Merino# This target, by necessity, can only work for native builds (i.e. a FreeBSD
84a784098cSJulio Merino# host building a release for the same system).  The target runs Kyua, which is
85a784098cSJulio Merino# not in the toolchain, and the tests execute code built for the target host.
86a784098cSJulio Merino#
87a784098cSJulio Merino# Due to the dependencies of the binaries built by the source tree and how they
88a784098cSJulio Merino# are used by tests, it is highly possible for a execution of "make test" to
89a784098cSJulio Merino# report bogus results unless the new binaries are put in place.
90a784098cSJulio Merino
9171b7fa12SEnji Cooperrealcheck: .PHONY
92*0bc776f3SKyle Evans	@if ! which -s "${KYUA}"; then \
9371b7fa12SEnji Cooper		echo; \
9471b7fa12SEnji Cooper		echo "kyua binary not installed at expected location (${.TARGET})"; \
9571b7fa12SEnji Cooper		echo; \
9671b7fa12SEnji Cooper		echo "Please install via pkg install, or specify the path to the kyua"; \
97986deea5SKyle Evans		echo "binary via the \$${KYUA} variable, e.g., "; \
98986deea5SKyle Evans		echo "KYUA=\"${LOCALBASE}/bin/kyua\""; \
9971b7fa12SEnji Cooper		false; \
10071b7fa12SEnji Cooper	fi
10138f8fddfSEnji Cooper	@env ${TESTS_ENV:Q} ${KYUA} test -k ${DESTDIR}${TESTSDIR}/Kyuafile
10238f8fddfSEnji Cooper
103b91ed584SBryan DreweryMAKE_CHECK_SANDBOX_DIR=	checkdir
10438f8fddfSEnji CooperCLEANDIRS+=	${MAKE_CHECK_SANDBOX_DIR}
10538f8fddfSEnji Cooper
10638f8fddfSEnji Cooper.if ${MK_MAKE_CHECK_USE_SANDBOX} != "no" && make(check)
107b91ed584SBryan DreweryDESTDIR:=	${.OBJDIR}/${MAKE_CHECK_SANDBOX_DIR}
10838f8fddfSEnji Cooper
10938f8fddfSEnji Cooperbeforecheck:
11038f8fddfSEnji Cooper.for t in clean depend all
11138f8fddfSEnji Cooper	@cd ${.CURDIR} && ${MAKE} $t
11238f8fddfSEnji Cooper.endfor
11338f8fddfSEnji Cooper	@cd ${SRCTOP} && ${MAKE} hierarchy DESTDIR=${DESTDIR}
11438f8fddfSEnji Cooper	@cd ${.CURDIR} && ${MAKE} install \
11538f8fddfSEnji Cooper	    DESTDIR=${DESTDIR}
11638f8fddfSEnji Cooper
11738f8fddfSEnji Cooper# NOTE: this is intentional to ensure that "make check" can be run multiple
11838f8fddfSEnji Cooper#       times. "aftercheck" won't be run if "make check" fails, is interrupted,
11938f8fddfSEnji Cooper#       etc.
12038f8fddfSEnji Cooperaftercheck:
12138f8fddfSEnji Cooper	@cd ${.CURDIR} && ${MAKE} clean
122e1136567SDimitry Andric	@test ! -e ${DESTDIR} || chflags -R 0 "${DESTDIR}"
12304d6e324SEnji Cooper	@rm -Rf "${DESTDIR}"
12438f8fddfSEnji Cooper
12538f8fddfSEnji Cooper.endif
126