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# Directory in which to install tests defined by the current Makefile. 12# Makefiles have to override this to point to a subdirectory of TESTSBASE. 13TESTSDIR?= . 14 15# Name of the test suite these tests belong to. Should rarely be changed for 16# Makefiles built into the FreeBSD src tree. 17TESTSUITE?= FreeBSD 18 19# Knob to control the handling of the Kyuafile for this Makefile. 20# 21# If 'yes', a Kyuafile exists in the source tree and is installed into 22# TESTSDIR. 23# 24# If 'auto', a Kyuafile is automatically generated based on the list of test 25# programs built by the Makefile and is installed into TESTSDIR. This is the 26# default and is sufficient in the majority of the cases. 27# 28# If 'no', no Kyuafile is installed. 29KYUAFILE?= auto 30 31# Per-test program interface definition. 32# 33# The name provided here must match one of the interface names supported by 34# Kyua as this is later encoded in the Kyuafile test program definitions. 35#TEST_INTERFACE.<test-program>= interface-name 36 37# Metadata properties applicable to all test programs. 38# 39# All the variables for a test program defined in the Makefile are appended 40# to the test program's definition in the Kyuafile. This feature can be 41# used to avoid having to explicitly supply a Kyuafile in the source 42# directory, allowing the caller Makefile to rely on the KYUAFILE=auto 43# behavior defined here. 44#TEST_METADATA+= key="value" 45 46# Per-test program metadata properties as a list of key/value pairs. 47# 48# These per-test program settings _extend_ the values provided in the 49# unqualified TEST_METADATA variable. 50#TEST_METADATA.<test-program>+= key="value" 51 52# Path to the prefix of the installed Kyua CLI, if any. 53# 54# If kyua is installed from ports, we automatically define a realtest target 55# below to run the tests using this tool. The tools are searched for in the 56# hierarchy specified by this variable. 57KYUA_PREFIX?= /usr/local 58 59.if ${KYUAFILE:tl} == "yes" 60FILES+= Kyuafile 61FILESDIR_Kyuafile= ${TESTSDIR} 62 63CLEANFILES+= Kyuafile.auto Kyuafile.auto.tmp 64.elif ${KYUAFILE:tl} == "auto" 65FILES+= Kyuafile.auto 66FILESDIR_Kyuafile.auto= ${TESTSDIR} 67FILESNAME_Kyuafile.auto= Kyuafile 68 69CLEANFILES+= Kyuafile.auto Kyuafile.auto.tmp 70 71.for _T in ${_TESTS} 72_TEST_METADATA.${_T}= ${TEST_METADATA} ${TEST_METADATA.${_T}} 73.endfor 74 75.NOPATH: Kyuafile.auto 76Kyuafile.auto: Makefile 77 @{ \ 78 echo '-- Automatically generated by bsd.test.mk.'; \ 79 echo; \ 80 echo 'syntax(2)'; \ 81 echo; \ 82 echo 'test_suite("${TESTSUITE}")'; \ 83 echo; \ 84 } >Kyuafile.auto.tmp 85.for _T in ${_TESTS} 86 @echo '${TEST_INTERFACE.${_T}}_test_program{name="${_T}"${_TEST_METADATA.${_T}:C/$/,/:tW:C/^/, /W:C/,$//W}}' \ 87 >>Kyuafile.auto.tmp 88.endfor 89.for _T in ${TESTS_SUBDIRS:N.WAIT} 90 @echo "include(\"${_T}/Kyuafile\")" >>Kyuafile.auto.tmp 91.endfor 92 @mv Kyuafile.auto.tmp Kyuafile.auto 93.endif 94 95KYUA?= ${KYUA_PREFIX}/bin/kyua 96.if exists(${KYUA}) 97# Definition of the "make test" target and supporting variables. 98# 99# This target, by necessity, can only work for native builds (i.e. a FreeBSD 100# host building a release for the same system). The target runs Kyua, which is 101# not in the toolchain, and the tests execute code built for the target host. 102# 103# Due to the dependencies of the binaries built by the source tree and how they 104# are used by tests, it is highly possible for a execution of "make test" to 105# report bogus results unless the new binaries are put in place. 106realtest: .PHONY 107 @echo "*** WARNING: make test is experimental" 108 @echo "***" 109 @echo "*** Using this test does not preclude you from running the tests" 110 @echo "*** installed in ${TESTSBASE}. This test run may raise false" 111 @echo "*** positives and/or false negatives." 112 @echo 113 @${KYUA} test -k ${DESTDIR}${TESTSDIR}/Kyuafile; \ 114 result=0; \ 115 echo; \ 116 echo "*** Once again, note that "make test" is unsupported."; \ 117 test $${result} -eq 0 118.endif 119 120beforetest: .PHONY 121.if defined(TESTSDIR) 122.if ${TESTSDIR} == ${TESTSBASE} 123# Forbid running from ${TESTSBASE}. It can cause false positives/negatives and 124# it does not cover all the tests (e.g. it misses testing software in external). 125 @echo "*** Sorry, you cannot use make test from src/tests. Install the" 126 @echo "*** tests into their final location and run them from ${TESTSBASE}" 127 @false 128.else 129 @echo "*** Using this test does not preclude you from running the tests" 130 @echo "*** installed in ${TESTSBASE}. This test run may raise false" 131 @echo "*** positives and/or false negatives." 132.endif 133.else 134 @echo "*** No TESTSDIR defined; nothing to do." 135 @false 136.endif 137 @echo 138