bsd.test.mk revision 1.17 1 # $NetBSD: bsd.test.mk,v 1.17 2011/03/27 14:22:02 plunky Exp $
2 #
3
4 .include <bsd.init.mk>
5
6 _TESTS:= # empty
7
8 .if defined(TESTS_SUBDIRS)
9 SUBDIR+= ${TESTS_SUBDIRS}
10 _TESTS:= ${TESTS_SUBDIRS:N.WAIT}
11 .endif
12
13 .include <bsd.subdir.mk>
14
15 .if defined(TESTS_C)
16 _TESTS+= ${TESTS_C}
17 PROGS+= ${TESTS_C}
18 LDADD+= -latf-c
19 DPADD+= ${LIBATF_C}
20 . for _T in ${TESTS_C}
21 BINDIR.${_T}= ${TESTSDIR}
22 MAN.${_T}?= # empty
23 . endfor
24 .endif
25
26 .if defined(TESTS_CXX)
27 _TESTS+= ${TESTS_CXX}
28 PROGS_CXX+= ${TESTS_CXX}
29 LDADD+= -latf-c++ -latf-c
30 DPADD+= ${LIBATF_CXX} ${LIBATF_C}
31 . for _T in ${TESTS_CXX}
32 BINDIR.${_T}= ${TESTSDIR}
33 MAN.${_T}?= # empty
34 . endfor
35 .endif
36
37 .if defined(TESTS_SH)
38 _TESTS+= ${TESTS_SH}
39 CLEANFILES+= ${TESTS_SH}
40
41 . for _T in ${TESTS_SH}
42 SCRIPTS+= ${_T}
43 SCRIPTSDIR_${_T}= ${TESTSDIR}
44
45 CLEANFILES+= ${_T}.tmp
46
47 TESTS_SH_SRC_${_T}?= ${_T}.sh
48 ${_T}: ${TESTS_SH_SRC_${_T}}
49 ${_MKTARGET_BUILD}
50 echo '#! /usr/bin/atf-sh' >${.TARGET}.tmp
51 cat ${.ALLSRC} >>${.TARGET}.tmp
52 chmod +x ${.TARGET}.tmp
53 mv ${.TARGET}.tmp ${.TARGET}
54 . endfor
55 .endif
56
57 ATFFILE?= auto
58
59 .if ${ATFFILE:tl} != "no"
60 FILES+= Atffile
61 FILESDIR_Atffile= ${TESTSDIR}
62
63 . if ${ATFFILE:tl} == "auto"
64 CLEANFILES+= Atffile Atffile.tmp
65
66 realall: Atffile
67 Atffile: Makefile
68 ${_MKTARGET_CREATE}
69 @{ echo 'Content-Type: application/X-atf-atffile; version="1"'; \
70 echo; \
71 echo '# Automatically generated by bsd.test.mk.'; \
72 echo; \
73 echo 'prop: test-suite = "NetBSD"'; \
74 echo; \
75 for tp in ${_TESTS}; do \
76 echo "tp: $${tp}"; \
77 done; } >Atffile.tmp
78 @mv Atffile.tmp Atffile
79 . endif
80
81 .include <bsd.files.mk>
82 .endif
83
84 .if !empty(SCRIPTS) || !empty(PROGS) || !empty(PROGS_CXX)
85 . include <bsd.prog.mk>
86 .else
87 cleandir: cleantest
88 cleantest: .PHONY
89 rm -f ${CLEANFILES}
90 .endif
91
92 #
93 # Definition of the "make test" target and supporting variables.
94 #
95 # This target, by necessity, can only work for native builds (i.e. a NetBSD
96 # host building a release for the same system). The target runs ATF, which is
97 # not in the toolchain, and the tests execute code built for the target host.
98 #
99 # Due to the dependencies of the binaries built by the source tree and how they
100 # are used by tests, it is highly possible for a execution of "make test" to
101 # report bogus results unless the new binaries are put in place.
102 #
103
104 TESTS_PATH += ${DESTDIR}/bin ${DESTDIR}/sbin ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin
105 TESTS_LD_LIBRARY_PATH += ${DESTDIR}/lib ${DESTDIR}/usr/lib
106
107 TESTS_ENV += ATF_BUILD_CC=${DESTDIR}/usr/bin/cc
108 TESTS_ENV += ATF_BUILD_CPP=${DESTDIR}/usr/bin/cpp
109 TESTS_ENV += ATF_BUILD_CXX=${DESTDIR}/usr/bin/c++
110 TESTS_ENV += ATF_CONFDIR=${DESTDIR}/etc
111 TESTS_ENV += ATF_INCLUDEDIR=${DESTDIR}/usr/include
112 TESTS_ENV += ATF_LIBDIR=${DESTDIR}/usr/lib
113 TESTS_ENV += ATF_LIBEXECDIR=${DESTDIR}/usr/libexec
114 TESTS_ENV += ATF_PKGDATADIR=${DESTDIR}/usr/share/atf
115 TESTS_ENV += ATF_SHELL=${DESTDIR}/bin/sh
116 TESTS_ENV += LD_LIBRARY_PATH=${TESTS_LD_LIBRARY_PATH:tW:S/ /:/g}
117 TESTS_ENV += PATH=${TESTS_PATH:tW:S/ /:/g}
118
119 _TESTS_FIFO = ${.OBJDIR}/atf-run.fifo
120 _TESTS_LOG = ${.OBJDIR}/atf-run.log
121 CLEANFILES += ${_TESTS_FIFO} ${_TESTS_LOG}
122
123 .PHONY: test
124 .if defined(TESTSDIR)
125 . if ${TESTSDIR} == ${TESTSBASE}
126 # Forbid this case. It is likely to cause false positives/negatives and it
127 # does not cover all the tests (e.g. it misses testing software in external).
128 test:
129 @echo "*** Sorry, you cannot use make test from src/tests. Install the"
130 @echo "*** tests into their final location and run them from /usr/tests"
131 @false
132 . else
133 test:
134 @echo "*** WARNING: make test is experimental"
135 @echo "***"
136 @echo "*** Using this test does not preclude you from running the tests"
137 @echo "*** installed in /usr/tests. This test run may raise false"
138 @echo "*** positives and/or false negatives."
139 @echo
140 @set -e; \
141 cd ${DESTDIR}${TESTSDIR}; \
142 mkfifo ${_TESTS_FIFO}; \
143 cat ${_TESTS_FIFO} | tee ${_TESTS_LOG} | \
144 ${TESTS_ENV} ${DESTDIR}/usr/bin/atf-report & \
145 ${TESTS_ENV} ${DESTDIR}/usr/bin/atf-run >>${_TESTS_FIFO}; \
146 result=$${?}; \
147 wait; \
148 rm -f ${_TESTS_FIFO}; \
149 echo; \
150 echo "*** The verbatim output of atf-run has been saved to ${_TESTS_LOG}"; \
151 echo "*** Once again, note that "make test" is unsupported."; \
152 test $${result} -eq 0
153 . endif
154 .else
155 test:
156 @echo "*** No TESTSDIR defined; nothing to do."
157 .endif
158