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