3 # Generic build infrastructure for test programs.
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.
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
13 .include <bsd.init.mk>
15 # Directory in which to install tests defined by the current Makefile.
16 # Makefiles have to override this to point to a subdirectory of TESTSBASE.
19 # Name of the test suite these tests belong to. Should rarely be changed for
20 # Makefiles built into the FreeBSD src tree.
23 # List of subdirectories containing tests into which to recurse. This has the
24 # same semantics as SUBDIR at build-time. However, the directories listed here
25 # get registered into the run-time test suite definitions so that the test
26 # engines know to recurse into these directories.
28 # In other words: list here any directories that contain test programs but use
29 # SUBDIR for directories that may contain helper binaries and/or data files.
32 # Knob to control the handling of the Kyuafile for this Makefile.
34 # If 'yes', a Kyuafile exists in the source tree and is installed into
37 # If 'auto', a Kyuafile is automatically generated based on the list of test
38 # programs built by the Makefile and is installed into TESTSDIR. This is the
39 # default and is sufficient in the majority of the cases.
41 # If 'no', no Kyuafile is installed.
44 # List of variables to pass to the tests at run-time via the environment.
47 # Ordered list of directories to construct the PATH for the tests.
48 TESTS_PATH+= ${DESTDIR}/bin ${DESTDIR}/sbin \
49 ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin
50 TESTS_ENV+= PATH=${TESTS_PATH:tW:C/ +/:/g}
52 # Ordered list of directories to construct the LD_LIBRARY_PATH for the tests.
53 TESTS_LD_LIBRARY_PATH+= ${DESTDIR}/lib ${DESTDIR}/usr/lib
54 TESTS_ENV+= LD_LIBRARY_PATH=${TESTS_LD_LIBRARY_PATH:tW:C/ +/:/g}
56 # List of all tests being built. This variable is internal should not be
57 # defined by the Makefile. The various *.test.mk modules extend this variable
61 # Path to the prefix of the installed Kyua CLI, if any.
63 # If kyua is installed from ports, we automatically define a realtest target
64 # below to run the tests using this tool. The tools are searched for in the
65 # hierarchy specified by this variable.
66 KYUA_PREFIX?= /usr/local
68 .if !empty(TESTS_SUBDIRS)
69 SUBDIR+= ${TESTS_SUBDIRS}
72 # it is rare for test cases to have man pages
78 # tell progs.mk we might want to install things
80 PROGS_TARGETS+= install
82 .if ${KYUAFILE:tl} != "no"
84 FILESDIR_Kyuafile= ${TESTSDIR}
86 .if ${KYUAFILE:tl} == "auto"
87 CLEANFILES+= Kyuafile Kyuafile.tmp
91 echo '-- Automatically generated by bsd.test.mk.'; \
95 echo 'test_suite("${TESTSUITE}")'; \
99 @echo "${TEST_INTERFACE.${_T}}_test_program{name=\"${_T}\"}" \
102 .for _T in ${TESTS_SUBDIRS:N.WAIT}
103 @echo "include(\"${_T}/Kyuafile\")" >>Kyuafile.tmp
105 @mv Kyuafile.tmp Kyuafile
109 KYUA?= ${KYUA_PREFIX}/bin/kyua
111 # Definition of the "make test" target and supporting variables.
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.
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.
121 @echo "*** WARNING: make test is experimental"
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."
128 ${KYUA} test -k ${DESTDIR}${TESTSDIR}/Kyuafile; \
131 echo "*** Once again, note that "make test" is unsupported."; \
132 test $${result} -eq 0
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}"
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."
149 @echo "*** No TESTSDIR defined; nothing to do."
154 .if !target(realtest)
156 @echo "$@ not defined; skipping"
160 .ORDER: beforetest realtest
161 test: beforetest realtest
163 .if target(aftertest)
164 .ORDER: realtest aftertest
169 .include <bsd.subdir.mk>
172 .if !empty(PROGS) || !empty(PROGS_CXX) || !empty(SCRIPTS)
173 .include <bsd.progs.mk>
175 .include <bsd.files.mk>
178 .include <bsd.obj.mk>