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 # Per-test program interface definition.
46 # The name provided here must match one of the interface names supported by
47 # Kyua as this is later encoded in the Kyuafile test program definitions.
48 #TEST_INTERFACE.<test-program>= interface-name
50 # Per-test program metadata properties as a list of key/value pairs.
52 # All the variables for a particular program are appended to the program's
53 # definition in the Kyuafile. This feature can be used to avoid having to
54 # explicitly supply a Kyuafile in the source directory, allowing the caller
55 # Makefile to rely on the KYUAFILE=auto behavior defined here.
56 #TEST_METADATA.<test-program>+= key="value"
58 # List of variables to pass to the tests at run-time via the environment.
61 # Ordered list of directories to construct the PATH for the tests.
62 TESTS_PATH+= ${DESTDIR}/bin ${DESTDIR}/sbin \
63 ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin
64 TESTS_ENV+= PATH=${TESTS_PATH:tW:C/ +/:/g}
66 # Ordered list of directories to construct the LD_LIBRARY_PATH for the tests.
67 TESTS_LD_LIBRARY_PATH+= ${DESTDIR}/lib ${DESTDIR}/usr/lib
68 TESTS_ENV+= LD_LIBRARY_PATH=${TESTS_LD_LIBRARY_PATH:tW:C/ +/:/g}
70 # List of all tests being built. This variable is internal should not be
71 # defined by the Makefile. The various *.test.mk modules extend this variable
75 # Path to the prefix of the installed Kyua CLI, if any.
77 # If kyua is installed from ports, we automatically define a realtest target
78 # below to run the tests using this tool. The tools are searched for in the
79 # hierarchy specified by this variable.
80 KYUA_PREFIX?= /usr/local
82 .if !empty(TESTS_SUBDIRS)
83 SUBDIR+= ${TESTS_SUBDIRS}
86 # it is rare for test cases to have man pages
92 # tell progs.mk we might want to install things
94 PROGS_TARGETS+= install
96 .if ${KYUAFILE:tl} == "yes"
98 FILESDIR_Kyuafile= ${TESTSDIR}
100 CLEANFILES+= Kyuafile.auto Kyuafile.auto.tmp
101 .elif ${KYUAFILE:tl} == "auto"
102 FILES+= Kyuafile.auto
103 FILESDIR_Kyuafile.auto= ${TESTSDIR}
104 FILESNAME_Kyuafile.auto= Kyuafile
106 CLEANFILES+= Kyuafile.auto Kyuafile.auto.tmp
108 .NOPATH: Kyuafile.auto
109 Kyuafile.auto: Makefile
111 echo '-- Automatically generated by bsd.test.mk.'; \
115 echo 'test_suite("${TESTSUITE}")'; \
119 @echo '${TEST_INTERFACE.${_T}}_test_program{name="${_T}"${TEST_METADATA.${_T}:C/$/,/:tW:C/^/, /W:C/,$//W}}' \
122 .for _T in ${TESTS_SUBDIRS:N.WAIT}
123 @echo "include(\"${_T}/Kyuafile\")" >>Kyuafile.auto.tmp
125 @mv Kyuafile.auto.tmp Kyuafile.auto
128 KYUA?= ${KYUA_PREFIX}/bin/kyua
130 # Definition of the "make test" target and supporting variables.
132 # This target, by necessity, can only work for native builds (i.e. a FreeBSD
133 # host building a release for the same system). The target runs Kyua, which is
134 # not in the toolchain, and the tests execute code built for the target host.
136 # Due to the dependencies of the binaries built by the source tree and how they
137 # are used by tests, it is highly possible for a execution of "make test" to
138 # report bogus results unless the new binaries are put in place.
140 @echo "*** WARNING: make test is experimental"
142 @echo "*** Using this test does not preclude you from running the tests"
143 @echo "*** installed in ${TESTSBASE}. This test run may raise false"
144 @echo "*** positives and/or false negatives."
147 ${KYUA} test -k ${DESTDIR}${TESTSDIR}/Kyuafile; \
150 echo "*** Once again, note that "make test" is unsupported."; \
151 test $${result} -eq 0
155 .if defined(TESTSDIR)
156 .if ${TESTSDIR} == ${TESTSBASE}
157 # Forbid running from ${TESTSBASE}. It can cause false positives/negatives and
158 # it does not cover all the tests (e.g. it misses testing software in external).
159 @echo "*** Sorry, you cannot use make test from src/tests. Install the"
160 @echo "*** tests into their final location and run them from ${TESTSBASE}"
163 @echo "*** Using this test does not preclude you from running the tests"
164 @echo "*** installed in ${TESTSBASE}. This test run may raise false"
165 @echo "*** positives and/or false negatives."
168 @echo "*** No TESTSDIR defined; nothing to do."
173 .if !target(realtest)
175 @echo "$@ not defined; skipping"
179 .ORDER: beforetest realtest
180 test: beforetest realtest
182 .if target(aftertest)
183 .ORDER: realtest aftertest
188 .include <bsd.subdir.mk>
191 .if !empty(PROGS) || !empty(PROGS_CXX) || !empty(SCRIPTS)
192 .include <bsd.progs.mk>
194 .include <bsd.files.mk>
197 .include <bsd.obj.mk>