bsd.test.mk revision 1.25.2.1 1 # $NetBSD: bsd.test.mk,v 1.25.2.1 2019/01/26 21:59:58 pgoyette Exp $
2 #
3
4 .include <bsd.init.mk>
5
6 _TESTS:= # empty
7
8 .if defined(TESTS_SUBDIRS)
9 SUBDIR+= ${TESTS_SUBDIRS}
10 .endif
11 .if defined(TESTS_SUBDIR_INSTALL_ONLY)
12 SUBDIR+= ${TESTS_SUBDIR_INSTALL_ONLY}
13 .endif
14
15 .include <bsd.subdir.mk>
16
17 .if defined(TESTS_C)
18 _TESTS+= ${TESTS_C}
19 PROGS+= ${TESTS_C}
20 . for _T in ${TESTS_C}
21 BINDIR.${_T}= ${TESTSDIR}
22 LDADD.${_T}+= -latf-c
23 DPADD.${_T}+= ${LIBATF_C}
24 MAN.${_T}?= # empty
25 . endfor
26 .endif
27
28 .if defined(TESTS_CXX)
29 _TESTS+= ${TESTS_CXX}
30 PROGS_CXX+= ${TESTS_CXX}
31 . for _T in ${TESTS_CXX}
32 BINDIR.${_T}= ${TESTSDIR}
33 LDADD.${_T}+= -latf-c++ -latf-c
34 DPADD.${_T}+= ${LIBATF_CXX} ${LIBATF_C}
35 MAN.${_T}?= # empty
36 . endfor
37 .endif
38
39 .if defined(TESTS_SH)
40 _TESTS+= ${TESTS_SH}
41 CLEANDIRFILES+= ${TESTS_SH}
42
43 . for _T in ${TESTS_SH}
44 SCRIPTS+= ${_T}
45 SCRIPTSDIR_${_T}= ${TESTSDIR}
46
47 CLEANDIRFILES+= ${_T}.tmp
48
49 TESTS_SH_SRC_${_T}?= ${_T}.sh
50 ${_T}: ${TESTS_SH_SRC_${_T}}
51 ${_MKTARGET_BUILD}
52 echo '#! /usr/bin/atf-sh' >${.TARGET}.tmp
53 cat ${.ALLSRC} >>${.TARGET}.tmp
54 chmod +x ${.TARGET}.tmp
55 ${MV} ${.TARGET}.tmp ${.TARGET}
56 . endfor
57 .endif
58
59 ATFFILE?= auto
60 .if ${MKKYUA} != "no"
61 KYUAFILE?= ${ATFFILE}
62 .else
63 KYUAFILE= no
64 .endif
65
66 # Additional list of 'tp' entries to add to the Atffile when ATFFILE=auto.
67 # These entries must all correspond to subdirectories to descend into.
68 #
69 # This is useful in the cases where the tests in a single directory come
70 # from various sources (e.g. src/tests and src/external/.../tests) and
71 # the installation of some of those tests rely on MK* variables being set.
72 ATFFILE_EXTRA_SUBDIRS?=
73
74 .if ${ATFFILE:tl} != "no"
75 FILES+= Atffile
76 FILESDIR_Atffile= ${TESTSDIR}
77
78 . if ${ATFFILE:tl} == "auto"
79 CLEANDIRFILES+= Atffile Atffile.tmp
80
81 realall: Atffile
82 Atffile: Makefile
83 ${_MKTARGET_CREATE}
84 @{ echo 'Content-Type: application/X-atf-atffile; version="1"'; \
85 echo; \
86 echo '# Automatically generated by bsd.test.mk.'; \
87 echo; \
88 echo 'prop: test-suite = "NetBSD"'; \
89 echo; \
90 for tp in ${TESTS_SUBDIRS:N.WAIT} ${_TESTS} ${ATFFILE_EXTRA_SUBDIRS}; \
91 do \
92 echo "tp: $${tp}"; \
93 done; } >Atffile.tmp
94 @${MV} Atffile.tmp Atffile
95 . endif
96 .endif
97
98 .if ${KYUAFILE:tl} != "no"
99 FILES+= Kyuafile
100 FILESDIR_Kyuafile= ${TESTSDIR}
101
102 . if ${KYUAFILE:tl} == "auto"
103 CLEANDIRFILES+= Kyuafile Kyuafile.tmp
104
105 realall: Kyuafile
106 Kyuafile: Makefile
107 ${_MKTARGET_CREATE}
108 @{ \
109 echo '-- Automatically generated by bsd.test.mk.'; \
110 echo; \
111 echo 'syntax(2)'; \
112 echo; \
113 echo 'test_suite("NetBSD")'; \
114 if [ -n "${_TESTS}" ]; then \
115 echo; \
116 for tp in ${_TESTS}; do \
117 echo "atf_test_program{name=\"$${tp}\"}"; \
118 done; \
119 fi; \
120 if [ -n "${TESTS_SUBDIRS:N.WAIT}" -o \
121 -n "${ATFFILE_EXTRA_SUBDIRS}" ]; then \
122 echo; \
123 for subdir in ${TESTS_SUBDIRS:N.WAIT} \
124 ${ATFFILE_EXTRA_SUBDIRS}; do \
125 echo "include(\"$${subdir}/Kyuafile\")"; \
126 done; \
127 fi; \
128 } >Kyuafile.tmp
129 @${MV} Kyuafile.tmp Kyuafile
130 . endif
131 .endif
132
133 .if ${ATFFILE:tl} != "no" || ${KYUAFILE:tl} != "no"
134 . include <bsd.files.mk>
135 .endif
136
137 .if !empty(SCRIPTS) || !empty(PROGS) || !empty(PROGS_CXX)
138 . include <bsd.prog.mk>
139 .endif
140
141 #
142 # Definition of the "make test" target and supporting variables.
143 #
144 # This target, by necessity, can only work for native builds (i.e. a NetBSD
145 # host building a release for the same system). The target runs ATF, which is
146 # not in the toolchain, and the tests execute code built for the target host.
147 #
148 # Due to the dependencies of the binaries built by the source tree and how they
149 # are used by tests, it is highly possible for a execution of "make test" to
150 # report bogus results unless the new binaries are put in place.
151 #
152
153 TESTS_PATH += ${DESTDIR}/bin ${DESTDIR}/sbin ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin
154 TESTS_LD_LIBRARY_PATH += ${DESTDIR}/lib ${DESTDIR}/usr/lib
155
156 TESTS_ENV += ATF_BUILD_CC=${DESTDIR}/usr/bin/cc
157 TESTS_ENV += ATF_BUILD_CPP=${DESTDIR}/usr/bin/cpp
158 TESTS_ENV += ATF_BUILD_CXX=${DESTDIR}/usr/bin/c++
159 TESTS_ENV += ATF_CONFDIR=${DESTDIR}/etc
160 TESTS_ENV += ATF_INCLUDEDIR=${DESTDIR}/usr/include
161 TESTS_ENV += ATF_LIBDIR=${DESTDIR}/usr/lib
162 TESTS_ENV += ATF_LIBEXECDIR=${DESTDIR}/usr/libexec
163 TESTS_ENV += ATF_PKGDATADIR=${DESTDIR}/usr/share/atf
164 TESTS_ENV += ATF_SHELL=${DESTDIR}/bin/sh
165 TESTS_ENV += LD_LIBRARY_PATH=${TESTS_LD_LIBRARY_PATH:tW:S/ /:/g}
166 TESTS_ENV += PATH=${TESTS_PATH:tW:S/ /:/g}
167
168 _TESTS_FIFO = ${.OBJDIR}/atf-run.fifo
169 _TESTS_LOG = ${.OBJDIR}/atf-run.log
170 CLEANDIRFILES += ${_TESTS_FIFO} ${_TESTS_LOG}
171
172 .PHONY: test
173 .if defined(TESTSDIR)
174 . if ${TESTSDIR} == ${TESTSBASE}
175 # Forbid this case. It is likely to cause false positives/negatives and it
176 # does not cover all the tests (e.g. it misses testing software in external).
177 test:
178 @echo "*** Sorry, you cannot use make test from src/tests. Install the"
179 @echo "*** tests into their final location and run them from /usr/tests"
180 @false
181 . else
182 test:
183 @echo "*** WARNING: make test is experimental"
184 @echo "***"
185 @echo "*** Using this test does not preclude you from running the tests"
186 @echo "*** installed in /usr/tests. This test run may raise false"
187 @echo "*** positives and/or false negatives."
188 @echo
189 @set -e; \
190 cd ${DESTDIR}${TESTSDIR}; \
191 rm -f ${_TESTS_FIFO}; \
192 mkfifo ${_TESTS_FIFO}; \
193 cat ${_TESTS_FIFO} | tee ${_TESTS_LOG} | \
194 ${TESTS_ENV} ${DESTDIR}/usr/bin/atf-report & \
195 result=0; \
196 ${TESTS_ENV} ${DESTDIR}/usr/bin/atf-run >>${_TESTS_FIFO} || result=1; \
197 wait; \
198 rm -f ${_TESTS_FIFO}; \
199 echo; \
200 echo "*** The verbatim output of atf-run has been saved to ${_TESTS_LOG}"; \
201 echo "*** Once again, note that "make test" is unsupported."; \
202 test $${result} -eq 0
203 . endif
204 .else
205 test:
206 @echo "*** No TESTSDIR defined; nothing to do."
207 .endif
208
209 ##### Pull in related .mk logic
210 .include <bsd.clean.mk>
211