]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - share/mk/bsd.test.mk
MFC various fixes for the ATF tests.
[FreeBSD/stable/10.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 # List of variables to pass to the tests at run-time via the environment.
45 TESTS_ENV?=
46
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}
51
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}
55
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
58 # as needed.
59 _TESTS?=
60
61 # Path to the prefix of the installed Kyua CLI, if any.
62 #
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
67
68 .if !empty(TESTS_SUBDIRS)
69 SUBDIR+= ${TESTS_SUBDIRS}
70 .endif
71
72 # it is rare for test cases to have man pages
73 .if !defined(MAN)
74 WITHOUT_MAN=yes
75 .export WITHOUT_MAN
76 .endif
77
78 # tell progs.mk we might want to install things
79 PROG_VARS+= BINDIR
80 PROGS_TARGETS+= install
81
82 .if ${KYUAFILE:tl} == "yes"
83 FILES+= Kyuafile
84 FILESDIR_Kyuafile= ${TESTSDIR}
85
86 CLEANFILES+= Kyuafile.auto Kyuafile.auto.tmp
87 .elif ${KYUAFILE:tl} == "auto"
88 FILES+= Kyuafile.auto
89 FILESDIR_Kyuafile.auto= ${TESTSDIR}
90 FILESNAME_Kyuafile.auto= Kyuafile
91
92 CLEANFILES+= Kyuafile.auto Kyuafile.auto.tmp
93
94 .NOPATH: Kyuafile.auto
95 Kyuafile.auto: Makefile
96         @{ \
97             echo '-- Automatically generated by bsd.test.mk.'; \
98             echo; \
99             echo 'syntax(2)'; \
100             echo; \
101             echo 'test_suite("${TESTSUITE}")'; \
102             echo; \
103         } >Kyuafile.auto.tmp
104 .for _T in ${_TESTS}
105         @echo "${TEST_INTERFACE.${_T}}_test_program{name=\"${_T}\"}" \
106             >>Kyuafile.auto.tmp
107 .endfor
108 .for _T in ${TESTS_SUBDIRS:N.WAIT}
109         @echo "include(\"${_T}/Kyuafile\")" >>Kyuafile.auto.tmp
110 .endfor
111         @mv Kyuafile.auto.tmp Kyuafile.auto
112 .endif
113
114 KYUA?= ${KYUA_PREFIX}/bin/kyua
115 .if exists(${KYUA})
116 # Definition of the "make test" target and supporting variables.
117 #
118 # This target, by necessity, can only work for native builds (i.e. a FreeBSD
119 # host building a release for the same system).  The target runs Kyua, which is
120 # not in the toolchain, and the tests execute code built for the target host.
121 #
122 # Due to the dependencies of the binaries built by the source tree and how they
123 # are used by tests, it is highly possible for a execution of "make test" to
124 # report bogus results unless the new binaries are put in place.
125 realtest: .PHONY
126         @echo "*** WARNING: make test is experimental"
127         @echo "***"
128         @echo "*** Using this test does not preclude you from running the tests"
129         @echo "*** installed in ${TESTSBASE}.  This test run may raise false"
130         @echo "*** positives and/or false negatives."
131         @echo
132         @set -e; \
133         ${KYUA} test -k ${DESTDIR}${TESTSDIR}/Kyuafile; \
134         result=0; \
135         echo; \
136         echo "*** Once again, note that "make test" is unsupported."; \
137         test $${result} -eq 0
138 .endif
139
140 beforetest: .PHONY
141 .if defined(TESTSDIR)
142 .if ${TESTSDIR} == ${TESTSBASE}
143 # Forbid running from ${TESTSBASE}.  It can cause false positives/negatives and
144 # it does not cover all the tests (e.g. it misses testing software in external).
145         @echo "*** Sorry, you cannot use make test from src/tests.  Install the"
146         @echo "*** tests into their final location and run them from ${TESTSBASE}"
147         @false
148 .else
149         @echo "*** Using this test does not preclude you from running the tests"
150         @echo "*** installed in ${TESTSBASE}.  This test run may raise false"
151         @echo "*** positives and/or false negatives."
152 .endif
153 .else
154         @echo "*** No TESTSDIR defined; nothing to do."
155         @false
156 .endif
157         @echo
158
159 .if !target(realtest)
160 realtest: .PHONY
161         @echo "$@ not defined; skipping"
162 .endif
163
164 test: .PHONY
165 .ORDER: beforetest realtest
166 test: beforetest realtest
167
168 .if target(aftertest)
169 .ORDER: realtest aftertest
170 test: aftertest
171 .endif
172
173 .if !empty(SUBDIR)
174 .include <bsd.subdir.mk>
175 .endif
176
177 .if !empty(PROGS) || !empty(PROGS_CXX) || !empty(SCRIPTS)
178 .include <bsd.progs.mk>
179 .elif !empty(FILES)
180 .include <bsd.files.mk>
181 .endif
182
183 .include <bsd.obj.mk>