]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/bsd.test.mk
Plug atf-run into the 'test' target.
[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 # Pointer to the top directory into which tests are installed.  Should not be
16 # overriden by Makefiles, but the user may choose to set this in src.conf(5).
17 TESTSBASE?= /usr/tests
18
19 # Directory in which to install tests defined by the current Makefile.
20 # Makefiles have to override this to point to a subdirectory of TESTSBASE.
21 TESTSDIR?= .
22
23 # Name of the test suite these tests belong to.  Should rarely be changed for
24 # Makefiles built into the FreeBSD src tree.
25 TESTSUITE?= FreeBSD
26
27 # List of subdirectories containing tests into which to recurse.  This has the
28 # same semantics as SUBDIR at build-time.  However, the directories listed here
29 # get registered into the run-time test suite definitions so that the test
30 # engines know to recurse into these directories.
31 #
32 # In other words: list here any directories that contain test programs but use
33 # SUBDIR for directories that may contain helper binaries and/or data files.
34 TESTS_SUBDIRS?=
35
36 # Knob to control the handling of the Kyuafile for this Makefile.
37 #
38 # If 'yes', a Kyuafile exists in the source tree and is installed into
39 # TESTSDIR.
40 #
41 # If 'auto', a Kyuafile is automatically generated based on the list of test
42 # programs built by the Makefile and is installed into TESTSDIR.  This is the
43 # default and is sufficient in the majority of the cases.
44 #
45 # If 'no', no Kyuafile is installed.
46 KYUAFILE?= auto
47
48 # List of variables to pass to the tests at run-time via the environment.
49 TESTS_ENV?=
50
51 # Ordered list of directories to construct the PATH for the tests.
52 TESTS_PATH+= ${DESTDIR}/bin ${DESTDIR}/sbin \
53              ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin
54 TESTS_ENV+= PATH=${TESTS_PATH:tW:C/ +/:/g}
55
56 # Ordered list of directories to construct the LD_LIBRARY_PATH for the tests.
57 TESTS_LD_LIBRARY_PATH+= ${DESTDIR}/lib ${DESTDIR}/usr/lib
58 TESTS_ENV+= LD_LIBRARY_PATH=${TESTS_LD_LIBRARY_PATH:tW:C/ +/:/g}
59
60 # List of all tests being built.  This variable is internal should not be
61 # defined by the Makefile.  The various *.test.mk modules extend this variable
62 # as needed.
63 _TESTS?=
64
65 .if !empty(TESTS_SUBDIRS)
66 SUBDIR+= ${TESTS_SUBDIRS}
67 .endif
68
69 # it is rare for test cases to have man pages
70 .if !defined(MAN)
71 WITHOUT_MAN=yes
72 .export WITHOUT_MAN
73 .endif
74
75 # tell progs.mk we might want to install things
76 PROG_VARS+= BINDIR
77 PROGS_TARGETS+= install
78
79 .if ${KYUAFILE:tl} != "no"
80 FILES+= Kyuafile
81 FILESDIR_Kyuafile= ${TESTSDIR}
82
83 .if ${KYUAFILE:tl} == "auto"
84 CLEANFILES+= Kyuafile Kyuafile.tmp
85
86 Kyuafile: Makefile
87         @{ \
88             echo '-- Automatically generated by bsd.test.mk.'; \
89             echo; \
90             echo 'syntax(2)'; \
91             echo; \
92             echo 'test_suite("${TESTSUITE}")'; \
93             echo; \
94         } >Kyuafile.tmp
95 .for _T in ${_TESTS}
96         @echo "${TEST_INTERFACE.${_T}}_test_program{name=\"${_T}\"}" \
97             >>Kyuafile.tmp
98 .endfor
99 .for _T in ${TESTS_SUBDIRS:N.WAIT}
100         @echo "include(\"${_T}/Kyuafile\")" >>Kyuafile.tmp
101 .endfor
102         @mv Kyuafile.tmp Kyuafile
103 .endif
104 .endif
105
106 beforetest: .PHONY
107 .if defined(TESTSDIR)
108 .if ${TESTSDIR} == ${TESTSBASE}
109 # Forbid running from ${TESTSBASE}.  It can cause false positives/negatives and
110 # it does not cover all the tests (e.g. it misses testing software in external).
111         @echo "*** Sorry, you cannot use make test from src/tests.  Install the"
112         @echo "*** tests into their final location and run them from ${TESTSBASE}"
113         @false
114 .else
115         @echo "*** Using this test does not preclude you from running the tests"
116         @echo "*** installed in ${TESTSBASE}.  This test run may raise false"
117         @echo "*** positives and/or false negatives."
118 .endif
119 .else
120         @echo "*** No TESTSDIR defined; nothing to do."
121         @false
122 .endif
123         @echo
124
125 .if !target(realtest)
126 realtest: .PHONY
127         @echo "$@ not defined; skipping"
128 .endif
129
130 test: .PHONY
131 .ORDER: beforetest realtest
132 test: beforetest realtest
133
134 .if target(aftertest)
135 .ORDER: realtest aftertest
136 test: aftertest
137 .endif
138
139 .if !empty(SUBDIR)
140 .include <bsd.subdir.mk>
141 .endif
142
143 .if !empty(PROGS) || !empty(PROGS_CXX) || !empty(SCRIPTS)
144 .include <bsd.progs.mk>
145 .elif !empty(FILES)
146 .include <bsd.files.mk>
147 .endif
148
149 .include <bsd.obj.mk>