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 80CHECKDIR?= ${DESTDIR}${TESTSDIR} 81 82KYUA= ${LOCALBASE}/bin/kyua 83 84# Definition of the "make check" target and supporting variables. 85# 86# This target, by necessity, can only work for native builds (i.e. a FreeBSD 87# host building a release for the same system). The target runs Kyua, which is 88# not in the toolchain, and the tests execute code built for the target host. 89# 90# Due to the dependencies of the binaries built by the source tree and how they 91# are used by tests, it is highly possible for a execution of "make test" to 92# report bogus results unless the new binaries are put in place. 93 94realcheck: .PHONY 95 @if [ ! -x ${KYUA} ]; then \ 96 echo; \ 97 echo "kyua binary not installed at expected location (${.TARGET})"; \ 98 echo; \ 99 echo "Please install via pkg install, or specify the path to the kyua"; \ 100 echo "package via the \$${LOCALBASE} variable, e.g. "; \ 101 echo "LOCALBASE=\"${LOCALBASE}\""; \ 102 false; \ 103 fi 104 @env ${TESTS_ENV:Q} ${KYUA} test -k ${CHECKDIR}/Kyuafile 105 106.if ${MK_MAKE_CHECK_USE_SANDBOX} && make(check) 107DESTDIR:= ${.OBJDIR}/checkdir 108CLEANDIRS+= ${DESTDIR} 109 110# XXX (ngie): use daemon(1) and a pidfile to lock the directory? 111beforecheck: 112 @if [ -d "${DESTDIR}" ]; then \ 113 echo "${DESTDIR} already exists"; \ 114 echo "Aborting to avoid false positives with potentially" \ 115 "parallel instances of '${MAKE} check'"; \ 116 false; \ 117 fi 118.for t in clean all 119 @cd ${.CURDIR} && ${MAKE} $t 120.endfor 121 @cd ${.CURDIR} && ${MAKE} install \ 122 -D_FILESMKDIR \ 123 DESTDIR=${DESTDIR} 124 125# NOTE: this is intentional to ensure that "make check" can be run multiple 126# times. It won't be run if "make check" fails or is interrupted 127aftercheck: 128 @cd ${.CURDIR} && ${MAKE} clean 129 130.endif 131