bsd.test.mk revision 259962
190075Sobrien# $FreeBSD: stable/10/share/mk/bsd.test.mk 259962 2013-12-27 22:00:22Z jmmv $ 290075Sobrien# 3169689Skan# Generic build infrastructure for test programs. 490075Sobrien# 590075Sobrien# The code in this file is independent of the implementation of the test 690075Sobrien# programs being built; this file just provides generic infrastructure for the 790075Sobrien# build and the definition of various helper variables and targets. 890075Sobrien# 990075Sobrien# Makefiles should never include this file directly. Instead, they should 1090075Sobrien# include one of the various *.test.mk depending on the specific test programs 1190075Sobrien# being built. 1290075Sobrien 1390075Sobrien.include <bsd.init.mk> 1490075Sobrien 1590075Sobrien# Directory in which to install tests defined by the current Makefile. 1690075Sobrien# Makefiles have to override this to point to a subdirectory of TESTSBASE. 1790075SobrienTESTSDIR?= . 1890075Sobrien 19169689Skan# Name of the test suite these tests belong to. Should rarely be changed for 20169689Skan# Makefiles built into the FreeBSD src tree. 2190075SobrienTESTSUITE?= FreeBSD 2290075Sobrien 23117395Skan# List of subdirectories containing tests into which to recurse. This has the 2490075Sobrien# same semantics as SUBDIR at build-time. However, the directories listed here 2590075Sobrien# get registered into the run-time test suite definitions so that the test 2690075Sobrien# engines know to recurse into these directories. 27117395Skan# 2890075Sobrien# In other words: list here any directories that contain test programs but use 2990075Sobrien# SUBDIR for directories that may contain helper binaries and/or data files. 30117395SkanTESTS_SUBDIRS?= 3190075Sobrien 32169689Skan# Knob to control the handling of the Kyuafile for this Makefile. 33117395Skan# 3490075Sobrien# If 'yes', a Kyuafile exists in the source tree and is installed into 3590075Sobrien# TESTSDIR. 3690075Sobrien# 3790075Sobrien# If 'auto', a Kyuafile is automatically generated based on the list of test 3890075Sobrien# programs built by the Makefile and is installed into TESTSDIR. This is the 3990075Sobrien# default and is sufficient in the majority of the cases. 4090075Sobrien# 41132718Skan# If 'no', no Kyuafile is installed. 42132718SkanKYUAFILE?= auto 4390075Sobrien 4490075Sobrien# List of variables to pass to the tests at run-time via the environment. 4590075SobrienTESTS_ENV?= 46117395Skan 4790075Sobrien# Ordered list of directories to construct the PATH for the tests. 4890075SobrienTESTS_PATH+= ${DESTDIR}/bin ${DESTDIR}/sbin \ 4990075Sobrien ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin 5090075SobrienTESTS_ENV+= PATH=${TESTS_PATH:tW:C/ +/:/g} 5190075Sobrien 5290075Sobrien# Ordered list of directories to construct the LD_LIBRARY_PATH for the tests. 5390075SobrienTESTS_LD_LIBRARY_PATH+= ${DESTDIR}/lib ${DESTDIR}/usr/lib 54117395SkanTESTS_ENV+= LD_LIBRARY_PATH=${TESTS_LD_LIBRARY_PATH:tW:C/ +/:/g} 55117395Skan 5690075Sobrien# List of all tests being built. This variable is internal should not be 5790075Sobrien# defined by the Makefile. The various *.test.mk modules extend this variable 5890075Sobrien# as needed. 59117395Skan_TESTS?= 6090075Sobrien 6190075Sobrien# Path to the prefix of the installed Kyua CLI, if any. 6290075Sobrien# 6390075Sobrien# If kyua is installed from ports, we automatically define a realtest target 6490075Sobrien# below to run the tests using this tool. The tools are searched for in the 65132718Skan# hierarchy specified by this variable. 66169689SkanKYUA_PREFIX?= /usr/local 67169689Skan 68132718Skan.if !empty(TESTS_SUBDIRS) 69132718SkanSUBDIR+= ${TESTS_SUBDIRS} 70132718Skan.endif 71132718Skan 72132718Skan# it is rare for test cases to have man pages 73132718Skan.if !defined(MAN) 74146895SkanWITHOUT_MAN=yes 75.export WITHOUT_MAN 76.endif 77 78# tell progs.mk we might want to install things 79PROG_VARS+= BINDIR 80PROGS_TARGETS+= install 81 82.if ${KYUAFILE:tl} != "no" 83FILES+= Kyuafile 84FILESDIR_Kyuafile= ${TESTSDIR} 85 86.if ${KYUAFILE:tl} == "auto" 87CLEANFILES+= Kyuafile Kyuafile.tmp 88 89Kyuafile: Makefile 90 @{ \ 91 echo '-- Automatically generated by bsd.test.mk.'; \ 92 echo; \ 93 echo 'syntax(2)'; \ 94 echo; \ 95 echo 'test_suite("${TESTSUITE}")'; \ 96 echo; \ 97 } >Kyuafile.tmp 98.for _T in ${_TESTS} 99 @echo "${TEST_INTERFACE.${_T}}_test_program{name=\"${_T}\"}" \ 100 >>Kyuafile.tmp 101.endfor 102.for _T in ${TESTS_SUBDIRS:N.WAIT} 103 @echo "include(\"${_T}/Kyuafile\")" >>Kyuafile.tmp 104.endfor 105 @mv Kyuafile.tmp Kyuafile 106.endif 107.endif 108 109KYUA?= ${KYUA_PREFIX}/bin/kyua 110.if exists(${KYUA}) 111# Definition of the "make test" target and supporting variables. 112# 113# This target, by necessity, can only work for native builds (i.e. a FreeBSD 114# host building a release for the same system). The target runs Kyua, which is 115# not in the toolchain, and the tests execute code built for the target host. 116# 117# Due to the dependencies of the binaries built by the source tree and how they 118# are used by tests, it is highly possible for a execution of "make test" to 119# report bogus results unless the new binaries are put in place. 120realtest: .PHONY 121 @echo "*** WARNING: make test is experimental" 122 @echo "***" 123 @echo "*** Using this test does not preclude you from running the tests" 124 @echo "*** installed in ${TESTSBASE}. This test run may raise false" 125 @echo "*** positives and/or false negatives." 126 @echo 127 @set -e; \ 128 ${KYUA} test -k ${DESTDIR}${TESTSDIR}/Kyuafile; \ 129 result=0; \ 130 echo; \ 131 echo "*** Once again, note that "make test" is unsupported."; \ 132 test $${result} -eq 0 133.endif 134 135beforetest: .PHONY 136.if defined(TESTSDIR) 137.if ${TESTSDIR} == ${TESTSBASE} 138# Forbid running from ${TESTSBASE}. It can cause false positives/negatives and 139# it does not cover all the tests (e.g. it misses testing software in external). 140 @echo "*** Sorry, you cannot use make test from src/tests. Install the" 141 @echo "*** tests into their final location and run them from ${TESTSBASE}" 142 @false 143.else 144 @echo "*** Using this test does not preclude you from running the tests" 145 @echo "*** installed in ${TESTSBASE}. This test run may raise false" 146 @echo "*** positives and/or false negatives." 147.endif 148.else 149 @echo "*** No TESTSDIR defined; nothing to do." 150 @false 151.endif 152 @echo 153 154.if !target(realtest) 155realtest: .PHONY 156 @echo "$@ not defined; skipping" 157.endif 158 159test: .PHONY 160.ORDER: beforetest realtest 161test: beforetest realtest 162 163.if target(aftertest) 164.ORDER: realtest aftertest 165test: aftertest 166.endif 167 168.if !empty(SUBDIR) 169.include <bsd.subdir.mk> 170.endif 171 172.if !empty(PROGS) || !empty(PROGS_CXX) || !empty(SCRIPTS) 173.include <bsd.progs.mk> 174.elif !empty(FILES) 175.include <bsd.files.mk> 176.endif 177 178.include <bsd.obj.mk> 179