]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/bsd.test.mk
Add missing skeleton file.
[FreeBSD/FreeBSD.git] / share / mk / bsd.test.mk
1 # $FreeBSD$
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 # Directory in which to install tests defined by the current Makefile.
16 # Makefiles have to override this to point to a subdirectory of TESTSBASE.
17 TESTSDIR?= .
18
19 # Name of the test suite these tests belong to.  Should rarely be changed for
20 # Makefiles built into the FreeBSD src tree.
21 TESTSUITE?= FreeBSD
22
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.
27 #
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.
30 TESTS_SUBDIRS?=
31
32 # Knob to control the handling of the Kyuafile for this Makefile.
33 #
34 # If 'yes', a Kyuafile exists in the source tree and is installed into
35 # TESTSDIR.
36 #
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.
40 #
41 # If 'no', no Kyuafile is installed.
42 KYUAFILE?= auto
43
44 # Per-test program interface definition.
45 #
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
49
50 # Per-test program metadata properties as a list of key/value pairs.
51 #
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"
57
58 # List of variables to pass to the tests at run-time via the environment.
59 TESTS_ENV?=
60
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}
65
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}
69
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
72 # as needed.
73 _TESTS?=
74
75 # Path to the prefix of the installed Kyua CLI, if any.
76 #
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
81
82 .if !empty(TESTS_SUBDIRS)
83 SUBDIR+= ${TESTS_SUBDIRS}
84 .endif
85
86 # it is rare for test cases to have man pages
87 .if !defined(MAN)
88 WITHOUT_MAN=yes
89 .export WITHOUT_MAN
90 .endif
91
92 # tell progs.mk we might want to install things
93 PROG_VARS+= BINDIR
94 PROGS_TARGETS+= install
95
96 .if ${KYUAFILE:tl} == "yes"
97 FILES+= Kyuafile
98 FILESDIR_Kyuafile= ${TESTSDIR}
99
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
105
106 CLEANFILES+= Kyuafile.auto Kyuafile.auto.tmp
107
108 .NOPATH: Kyuafile.auto
109 Kyuafile.auto: Makefile
110         @{ \
111             echo '-- Automatically generated by bsd.test.mk.'; \
112             echo; \
113             echo 'syntax(2)'; \
114             echo; \
115             echo 'test_suite("${TESTSUITE}")'; \
116             echo; \
117         } >Kyuafile.auto.tmp
118 .for _T in ${_TESTS}
119         @echo '${TEST_INTERFACE.${_T}}_test_program{name="${_T}"${TEST_METADATA.${_T}:C/$/,/:tW:C/^/, /W:C/,$//W}}' \
120             >>Kyuafile.auto.tmp
121 .endfor
122 .for _T in ${TESTS_SUBDIRS:N.WAIT}
123         @echo "include(\"${_T}/Kyuafile\")" >>Kyuafile.auto.tmp
124 .endfor
125         @mv Kyuafile.auto.tmp Kyuafile.auto
126 .endif
127
128 KYUA?= ${KYUA_PREFIX}/bin/kyua
129 .if exists(${KYUA})
130 # Definition of the "make test" target and supporting variables.
131 #
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.
135 #
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.
139 realtest: .PHONY
140         @echo "*** WARNING: make test is experimental"
141         @echo "***"
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."
145         @echo
146         @set -e; \
147         ${KYUA} test -k ${DESTDIR}${TESTSDIR}/Kyuafile; \
148         result=0; \
149         echo; \
150         echo "*** Once again, note that "make test" is unsupported."; \
151         test $${result} -eq 0
152 .endif
153
154 beforetest: .PHONY
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}"
161         @false
162 .else
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."
166 .endif
167 .else
168         @echo "*** No TESTSDIR defined; nothing to do."
169         @false
170 .endif
171         @echo
172
173 .if !target(realtest)
174 realtest: .PHONY
175         @echo "$@ not defined; skipping"
176 .endif
177
178 test: .PHONY
179 .ORDER: beforetest realtest
180 test: beforetest realtest
181
182 .if target(aftertest)
183 .ORDER: realtest aftertest
184 test: aftertest
185 .endif
186
187 .if !empty(SUBDIR)
188 .include <bsd.subdir.mk>
189 .endif
190
191 .if !empty(PROGS) || !empty(PROGS_CXX) || !empty(SCRIPTS)
192 .include <bsd.progs.mk>
193 .elif !empty(FILES)
194 .include <bsd.files.mk>
195 .endif
196
197 .include <bsd.obj.mk>