]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - share/mk/atf.test.mk
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / share / mk / atf.test.mk
1 # $NetBSD$
2 # $FreeBSD$
3 #
4
5 .include <bsd.init.mk>
6
7 ATF_TESTS:=
8
9 .if make(*test)
10 TESTSDIR?= .
11 .endif
12
13 .if defined(ATF_TESTS_SUBDIRS)
14 # Only visit subdirs when building, etc because ATF does this it on its own.
15 .if !make(atf-test)
16 SUBDIR+= ${ATF_TESTS_SUBDIRS}
17 .endif
18 ATF_TESTS+= ${ATF_TESTS_SUBDIRS}
19
20 .include <bsd.subdir.mk>
21 .endif
22
23 .if defined(TESTS_C)
24 ATF_TESTS+= ${TESTS_C}
25 .for _T in ${TESTS_C}
26 SRCS.${_T}?= ${_T}.c
27 DPADD.${_T}+= ${LIBATF_C}
28 LDADD.${_T}+= -latf-c
29 .endfor
30 .endif
31
32 .if defined(TESTS_CXX)
33 ATF_TESTS+= ${TESTS_CXX}
34 .for _T in ${TESTS_CXX}
35 SRCS.${_T}?= ${_T}${CXX_SUFFIX:U.cc}
36 DPADD.${_T}+= ${LIBATF_CXX} ${LIBATF_C}
37 LDADD.${_T}+= -latf-c++ -latf-c
38 .endfor
39 .endif
40
41 .if defined(TESTS_SH)
42 ATF_TESTS+= ${TESTS_SH}
43 .for _T in ${TESTS_SH}
44 CLEANFILES+= ${_T} ${_T}.tmp
45 TESTS_SH_SRC_${_T}?= ${_T}.sh
46 ${_T}: ${TESTS_SH_SRC_${_T}}
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 ${ATFFILE:tl} != "no"
57 FILES+= Atffile
58 FILESDIR_Atffile= ${TESTSDIR}
59
60 .if ${ATFFILE:tl} == "auto"
61 CLEANFILES+= Atffile Atffile.tmp
62
63 Atffile: Makefile
64         @{ echo 'Content-Type: application/X-atf-atffile; version="1"'; \
65         echo; \
66         echo '# Automatically generated by atf-test.mk.'; \
67         echo; \
68         echo 'prop: test-suite = "'`uname -o`'"'; \
69         echo; \
70         for tp in ${ATF_TESTS}; do \
71             echo "tp: $${tp}"; \
72         done; } >Atffile.tmp
73         @mv Atffile.tmp Atffile
74 .endif
75 .endif
76
77 # Generate support variables for atf-test.
78 #
79 # atf-test can only work for native builds, i.e. a build host of a particular
80 # OS building a release for the same OS version and architecture. The target
81 # runs ATF, which is on the build host, and the tests execute code built for
82 # the target host.
83 #
84 # Due to the dependencies of the binaries built by the source tree and how they
85 # are used by tests, it is highly possible for a execution of "make test" to
86 # report bogus results unless the new binaries are put in place.
87
88 # XXX (gcooper): Executing ATF from outside the source tree is improper; it
89 # should be built as part of the OS toolchain build for the host OS and
90 # executed from there.
91 ATF_PATH+= ${DESTDIR}/bin ${DESTDIR}/sbin ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin
92 TESTS_ENV+= PATH=${ATF_PATH:ts:}:${PATH}
93
94 ATF_BUILD_CC?= ${DESTDIR}/usr/bin/cc
95 ATF_BUILD_CPP?= ${DESTDIR}/usr/bin/cpp
96 ATF_BUILD_CXX?= ${DESTDIR}/usr/bin/c++
97 ATF_CONFDIR?= ${DESTDIR}/etc
98 ATF_INCLUDEDIR?= ${DESTDIR}/usr/include
99 ATF_LIBDIR?= ${DESTDIR}/usr/lib
100 ATF_LIBEXECDIR?= ${DESTDIR}/usr/libexec
101 ATF_PKGDATADIR?= ${DESTDIR}/usr/share/atf
102 ATF_SHELL?= ${DESTDIR}/bin/sh
103 LD_LIBRARY_PATH?= ${TESTS_LD_LIBRARY_PATH:tW:S/ /:/g}
104
105 ATF_ENV_VARS= \
106         ATF_BUILD_CC \
107         ATF_BUILD_CPP \
108         ATF_BUILD_CXX \
109         ATF_CONFDIR \
110         ATF_INCLUDEDIR \
111         ATF_LIBDIR \
112         ATF_LIBEXECDIR \
113         ATF_PKGDATADIR \
114         ATF_SHELL \
115
116 .for v in ${ATF_ENV_VARS}
117 .if !empty($v)
118 TESTS_ENV+= $v=${$v}
119 .endif
120 .endfor
121
122 _TESTS_FIFO= ${.OBJDIR}/atf-run.fifo
123 _TESTS_LOG= ${.OBJDIR}/atf-run.log
124 CLEANFILES+= ${_TESTS_FIFO} ${_TESTS_LOG}
125
126 ATF_BIN?= ${DESTDIR}/usr/bin
127 ATF_REPORT?= ${ATF_BIN}/atf-report
128 ATF_RUN?= ${ATF_BIN}/atf-run
129
130 .PHONY: realtest
131 realtest:
132 .if defined(TESTSDIR)
133         @set -e; \
134         cd ${DESTDIR}${TESTSDIR}; \
135         rm -f ${_TESTS_FIFO}; \
136         mkfifo ${_TESTS_FIFO}; \
137         tee ${_TESTS_LOG} < ${_TESTS_FIFO} | ${TESTS_ENV} ${ATF_REPORT} & \
138         set +e; \
139         ${TESTS_ENV} ${ATF_RUN} >> ${_TESTS_FIFO}; \
140         result=$${?}; \
141         wait; \
142         rm -f ${_TESTS_FIFO}; \
143         echo; \
144         echo "*** The verbatim output of atf-run has been saved to ${_TESTS_LOG}"; \
145         exit $${result}
146 .endif
147
148 .include <bsd.test.mk>