bsd.test.mk revision 256763
1# $FreeBSD: head/share/mk/bsd.test.mk 256763 2013-10-19 06:50:56Z rpaulo $ 2# 3# Generic build infrastructure for test programs. 4# 5# The code in this file is independent of the implementation of the test 6# programs being built; this file just provides generic infrastructure for the 7# build and the definition of various helper variables and targets. 8# 9# Makefiles should never include this file directly. Instead, they should 10# include one of the various *.test.mk depending on the specific test programs 11# being built. 12 13.include <bsd.init.mk> 14 15# Pointer to the top directory into which tests are installed. Should not be 16# overriden by Makefiles, but the user may choose to set this in src.conf(5). 17TESTSBASE?= /usr/tests 18 19# Directory in which to install tests defined by the current Makefile. 20# Makefiles have to override this to point to a subdirectory of TESTSBASE. 21TESTSDIR?= . 22 23# Name of the test suite these tests belong to. Should rarely be changed for 24# Makefiles built into the FreeBSD src tree. 25TESTSUITE?= FreeBSD 26 27# List of subdirectories containing tests into which to recurse. This has the 28# same semantics as SUBDIR at build-time. However, the directories listed here 29# get registered into the run-time test suite definitions so that the test 30# engines know to recurse into these directories. 31# 32# In other words: list here any directories that contain test programs but use 33# SUBDIR for directories that may contain helper binaries and/or data files. 34TESTS_SUBDIRS?= 35 36# Knob to control the handling of the Kyuafile for this Makefile. 37# 38# If 'yes', a Kyuafile exists in the source tree and is installed into 39# TESTSDIR. 40# 41# If 'auto', a Kyuafile is automatically generated based on the list of test 42# programs built by the Makefile and is installed into TESTSDIR. This is the 43# default and is sufficient in the majority of the cases. 44# 45# If 'no', no Kyuafile is installed. 46KYUAFILE?= auto 47 48# List of all tests being built. This variable is internal should not be 49# defined by the Makefile. The various *.test.mk modules extend this variable 50# as needed. 51_TESTS?= 52 53.if !empty(TESTS_SUBDIRS) 54SUBDIR+= ${TESTS_SUBDIRS} 55.endif 56 57# it is rare for test cases to have man pages 58.if !defined(MAN) 59WITHOUT_MAN=yes 60.export WITHOUT_MAN 61.endif 62 63# tell progs.mk we might want to install things 64PROG_VARS+= BINDIR 65PROGS_TARGETS+= install 66 67.if ${KYUAFILE:tl} != "no" 68FILES+= Kyuafile 69FILESDIR_Kyuafile= ${TESTSDIR} 70 71.if ${KYUAFILE:tl} == "auto" 72CLEANFILES+= Kyuafile Kyuafile.tmp 73 74Kyuafile: Makefile 75 @{ \ 76 echo '-- Automatically generated by bsd.test.mk.'; \ 77 echo; \ 78 echo 'syntax(2)'; \ 79 echo; \ 80 echo 'test_suite("${TESTSUITE}")'; \ 81 echo; \ 82 } >Kyuafile.tmp 83.for _T in ${_TESTS} 84 @echo "${TEST_INTERFACE.${_T}}_test_program{name=\"${_T}\"}" \ 85 >>Kyuafile.tmp 86.endfor 87.for _T in ${TESTS_SUBDIRS:N.WAIT} 88 @echo "include(\"${_T}/Kyuafile\")" >>Kyuafile.tmp 89.endfor 90 @mv Kyuafile.tmp Kyuafile 91.endif 92.endif 93 94beforetest: .PHONY 95.if defined(TESTSDIR) 96.if ${TESTSDIR} == ${TESTSBASE} 97# Forbid running from ${TESTSBASE}. It can cause false positives/negatives and 98# it does not cover all the tests (e.g. it misses testing software in external). 99 @echo "*** Sorry, you cannot use make test from src/tests. Install the" 100 @echo "*** tests into their final location and run them from ${TESTSBASE}" 101 @false 102.else 103 @echo "*** Using this test does not preclude you from running the tests" 104 @echo "*** installed in ${TESTSBASE}. This test run may raise false" 105 @echo "*** positives and/or false negatives." 106.endif 107.else 108 @echo "*** No TESTSDIR defined; nothing to do." 109 @false 110.endif 111 @echo 112 113.if !target(realtest) 114realtest: .PHONY 115 @echo "$@ not defined; skipping" 116.endif 117 118test: .PHONY 119.ORDER: beforetest realtest 120test: beforetest realtest 121 122.if target(aftertest) 123.ORDER: realtest aftertest 124test: aftertest 125.endif 126 127.if !empty(SUBDIR) 128.include <bsd.subdir.mk> 129.endif 130 131.if !empty(PROGS) || !empty(PROGS_CXX) || !empty(SCRIPTS) 132.include <bsd.progs.mk> 133.elif !empty(FILES) 134.include <bsd.files.mk> 135.endif 136 137.include <bsd.obj.mk> 138