Deleted Added
full compact
bsd.test.mk (260632) bsd.test.mk (263161)
1# $FreeBSD: head/share/mk/bsd.test.mk 260632 2014-01-14 18:32:47Z jmmv $
1# $FreeBSD: head/share/mk/bsd.test.mk 263161 2014-03-14 08:56:19Z jmmv $
2#
3# Generic build infrastructure for test programs.
4#
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.
5# This is the only public file that should be included by Makefiles when
6# tests are to be built. All other *.test.mk files are internal and not
7# to be included directly.
12
13.include <bsd.init.mk>
14
8
9.include <bsd.init.mk>
10
11__<bsd.test.mk>__:
12
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.
17TESTSDIR?= .
18
19# Name of the test suite these tests belong to. Should rarely be changed for
20# Makefiles built into the FreeBSD src tree.
21TESTSUITE?= 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.
30TESTS_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.
42KYUAFILE?= 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.
59TESTS_ENV?=
60
61# Ordered list of directories to construct the PATH for the tests.
62TESTS_PATH+= ${DESTDIR}/bin ${DESTDIR}/sbin \
63 ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin
64TESTS_ENV+= PATH=${TESTS_PATH:tW:C/ +/:/g}
65
66# Ordered list of directories to construct the LD_LIBRARY_PATH for the tests.
67TESTS_LD_LIBRARY_PATH+= ${DESTDIR}/lib ${DESTDIR}/usr/lib
68TESTS_ENV+= LD_LIBRARY_PATH=${TESTS_LD_LIBRARY_PATH:tW:C/ +/:/g}
69
13# Directory in which to install tests defined by the current Makefile.
14# Makefiles have to override this to point to a subdirectory of TESTSBASE.
15TESTSDIR?= .
16
17# Name of the test suite these tests belong to. Should rarely be changed for
18# Makefiles built into the FreeBSD src tree.
19TESTSUITE?= FreeBSD
20
21# List of subdirectories containing tests into which to recurse. This has the
22# same semantics as SUBDIR at build-time. However, the directories listed here
23# get registered into the run-time test suite definitions so that the test
24# engines know to recurse into these directories.
25#
26# In other words: list here any directories that contain test programs but use
27# SUBDIR for directories that may contain helper binaries and/or data files.
28TESTS_SUBDIRS?=
29
30# Knob to control the handling of the Kyuafile for this Makefile.
31#
32# If 'yes', a Kyuafile exists in the source tree and is installed into
33# TESTSDIR.
34#
35# If 'auto', a Kyuafile is automatically generated based on the list of test
36# programs built by the Makefile and is installed into TESTSDIR. This is the
37# default and is sufficient in the majority of the cases.
38#
39# If 'no', no Kyuafile is installed.
40KYUAFILE?= auto
41
42# Per-test program interface definition.
43#
44# The name provided here must match one of the interface names supported by
45# Kyua as this is later encoded in the Kyuafile test program definitions.
46#TEST_INTERFACE.<test-program>= interface-name
47
48# Per-test program metadata properties as a list of key/value pairs.
49#
50# All the variables for a particular program are appended to the program's
51# definition in the Kyuafile. This feature can be used to avoid having to
52# explicitly supply a Kyuafile in the source directory, allowing the caller
53# Makefile to rely on the KYUAFILE=auto behavior defined here.
54#TEST_METADATA.<test-program>+= key="value"
55
56# List of variables to pass to the tests at run-time via the environment.
57TESTS_ENV?=
58
59# Ordered list of directories to construct the PATH for the tests.
60TESTS_PATH+= ${DESTDIR}/bin ${DESTDIR}/sbin \
61 ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin
62TESTS_ENV+= PATH=${TESTS_PATH:tW:C/ +/:/g}
63
64# Ordered list of directories to construct the LD_LIBRARY_PATH for the tests.
65TESTS_LD_LIBRARY_PATH+= ${DESTDIR}/lib ${DESTDIR}/usr/lib
66TESTS_ENV+= LD_LIBRARY_PATH=${TESTS_LD_LIBRARY_PATH:tW:C/ +/:/g}
67
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.
80KYUA_PREFIX?= /usr/local
81
68# Path to the prefix of the installed Kyua CLI, if any.
69#
70# If kyua is installed from ports, we automatically define a realtest target
71# below to run the tests using this tool. The tools are searched for in the
72# hierarchy specified by this variable.
73KYUA_PREFIX?= /usr/local
74
75# List of all tests being built. The various *.test.mk modules extend this
76# variable as needed.
77_TESTS=
78
79# Pull in the definitions of all supported test interfaces.
80.include <atf.test.mk>
81.include <plain.test.mk>
82.include <tap.test.mk>
83
82.if !empty(TESTS_SUBDIRS)
83SUBDIR+= ${TESTS_SUBDIRS}
84.endif
85
86# it is rare for test cases to have man pages
87.if !defined(MAN)
88WITHOUT_MAN=yes
89.export WITHOUT_MAN
90.endif
91
92# tell progs.mk we might want to install things
93PROG_VARS+= BINDIR
94PROGS_TARGETS+= install
95
96.if ${KYUAFILE:tl} == "yes"
97FILES+= Kyuafile
98FILESDIR_Kyuafile= ${TESTSDIR}
99
100CLEANFILES+= Kyuafile.auto Kyuafile.auto.tmp
101.elif ${KYUAFILE:tl} == "auto"
102FILES+= Kyuafile.auto
103FILESDIR_Kyuafile.auto= ${TESTSDIR}
104FILESNAME_Kyuafile.auto= Kyuafile
105
106CLEANFILES+= Kyuafile.auto Kyuafile.auto.tmp
107
108.NOPATH: Kyuafile.auto
109Kyuafile.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
128KYUA?= ${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.
139realtest: .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
154beforetest: .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)
174realtest: .PHONY
175 @echo "$@ not defined; skipping"
176.endif
177
178test: .PHONY
179.ORDER: beforetest realtest
180test: beforetest realtest
181
182.if target(aftertest)
183.ORDER: realtest aftertest
184test: 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>
84.if !empty(TESTS_SUBDIRS)
85SUBDIR+= ${TESTS_SUBDIRS}
86.endif
87
88# it is rare for test cases to have man pages
89.if !defined(MAN)
90WITHOUT_MAN=yes
91.export WITHOUT_MAN
92.endif
93
94# tell progs.mk we might want to install things
95PROG_VARS+= BINDIR
96PROGS_TARGETS+= install
97
98.if ${KYUAFILE:tl} == "yes"
99FILES+= Kyuafile
100FILESDIR_Kyuafile= ${TESTSDIR}
101
102CLEANFILES+= Kyuafile.auto Kyuafile.auto.tmp
103.elif ${KYUAFILE:tl} == "auto"
104FILES+= Kyuafile.auto
105FILESDIR_Kyuafile.auto= ${TESTSDIR}
106FILESNAME_Kyuafile.auto= Kyuafile
107
108CLEANFILES+= Kyuafile.auto Kyuafile.auto.tmp
109
110.NOPATH: Kyuafile.auto
111Kyuafile.auto: Makefile
112 @{ \
113 echo '-- Automatically generated by bsd.test.mk.'; \
114 echo; \
115 echo 'syntax(2)'; \
116 echo; \
117 echo 'test_suite("${TESTSUITE}")'; \
118 echo; \
119 } >Kyuafile.auto.tmp
120.for _T in ${_TESTS}
121 @echo '${TEST_INTERFACE.${_T}}_test_program{name="${_T}"${TEST_METADATA.${_T}:C/$/,/:tW:C/^/, /W:C/,$//W}}' \
122 >>Kyuafile.auto.tmp
123.endfor
124.for _T in ${TESTS_SUBDIRS:N.WAIT}
125 @echo "include(\"${_T}/Kyuafile\")" >>Kyuafile.auto.tmp
126.endfor
127 @mv Kyuafile.auto.tmp Kyuafile.auto
128.endif
129
130KYUA?= ${KYUA_PREFIX}/bin/kyua
131.if exists(${KYUA})
132# Definition of the "make test" target and supporting variables.
133#
134# This target, by necessity, can only work for native builds (i.e. a FreeBSD
135# host building a release for the same system). The target runs Kyua, which is
136# not in the toolchain, and the tests execute code built for the target host.
137#
138# Due to the dependencies of the binaries built by the source tree and how they
139# are used by tests, it is highly possible for a execution of "make test" to
140# report bogus results unless the new binaries are put in place.
141realtest: .PHONY
142 @echo "*** WARNING: make test is experimental"
143 @echo "***"
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."
147 @echo
148 @set -e; \
149 ${KYUA} test -k ${DESTDIR}${TESTSDIR}/Kyuafile; \
150 result=0; \
151 echo; \
152 echo "*** Once again, note that "make test" is unsupported."; \
153 test $${result} -eq 0
154.endif
155
156beforetest: .PHONY
157.if defined(TESTSDIR)
158.if ${TESTSDIR} == ${TESTSBASE}
159# Forbid running from ${TESTSBASE}. It can cause false positives/negatives and
160# it does not cover all the tests (e.g. it misses testing software in external).
161 @echo "*** Sorry, you cannot use make test from src/tests. Install the"
162 @echo "*** tests into their final location and run them from ${TESTSBASE}"
163 @false
164.else
165 @echo "*** Using this test does not preclude you from running the tests"
166 @echo "*** installed in ${TESTSBASE}. This test run may raise false"
167 @echo "*** positives and/or false negatives."
168.endif
169.else
170 @echo "*** No TESTSDIR defined; nothing to do."
171 @false
172.endif
173 @echo
174
175.if !target(realtest)
176realtest: .PHONY
177 @echo "$@ not defined; skipping"
178.endif
179
180test: .PHONY
181.ORDER: beforetest realtest
182test: beforetest realtest
183
184.if target(aftertest)
185.ORDER: realtest aftertest
186test: aftertest
187.endif
188
189.if !empty(SUBDIR)
190.include <bsd.subdir.mk>
191.endif
192
193.if !empty(PROGS) || !empty(PROGS_CXX) || !empty(SCRIPTS)
194.include <bsd.progs.mk>
195.elif !empty(FILES)
196.include <bsd.files.mk>
197.endif
198
199.include <bsd.obj.mk>