xref: /freebsd/share/mk/atf.test.mk (revision 48c5129f93c5eb5419c87b08e4677d51513f1dc0)
1# $NetBSD$
2# $FreeBSD$
3#
4
5.include <bsd.init.mk>
6
7ATF_TESTS:=
8
9.if make(*test)
10TESTSDIR?= .
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)
16SUBDIR+= ${ATF_TESTS_SUBDIRS}
17.endif
18ATF_TESTS+= ${ATF_TESTS_SUBDIRS}
19
20.include <bsd.subdir.mk>
21.endif
22
23.if defined(TESTS_C)
24ATF_TESTS+= ${TESTS_C}
25.for _T in ${TESTS_C}
26SRCS.${_T}?= ${_T}.c
27DPADD.${_T}+= ${LIBATF_C}
28LDADD.${_T}+= -latf-c
29.endfor
30.endif
31
32.if defined(TESTS_CXX)
33ATF_TESTS+= ${TESTS_CXX}
34.for _T in ${TESTS_CXX}
35SRCS.${_T}?= ${_T}${CXX_SUFFIX:U.cc}
36DPADD.${_T}+= ${LIBATF_CXX} ${LIBATF_C}
37LDADD.${_T}+= -latf-c++ -latf-c
38.endfor
39.endif
40
41.if defined(TESTS_SH)
42ATF_TESTS+= ${TESTS_SH}
43.for _T in ${TESTS_SH}
44CLEANFILES+= ${_T} ${_T}.tmp
45TESTS_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
54ATFFILE?= auto
55
56.if ${ATFFILE:tl} != "no"
57FILES+=	Atffile
58FILESDIR_Atffile= ${TESTSDIR}
59
60.if ${ATFFILE:tl} == "auto"
61CLEANFILES+= Atffile Atffile.tmp
62
63Atffile: 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.
91ATF_PATH+= ${DESTDIR}/bin ${DESTDIR}/sbin ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin
92TESTS_ENV+= PATH=${ATF_PATH:ts:}:${PATH}
93
94ATF_BUILD_CC?= ${DESTDIR}/usr/bin/cc
95ATF_BUILD_CPP?= ${DESTDIR}/usr/bin/cpp
96ATF_BUILD_CXX?= ${DESTDIR}/usr/bin/c++
97ATF_CONFDIR?= ${DESTDIR}/etc
98ATF_INCLUDEDIR?= ${DESTDIR}/usr/include
99ATF_LIBDIR?= ${DESTDIR}/usr/lib
100ATF_LIBEXECDIR?= ${DESTDIR}/usr/libexec
101ATF_PKGDATADIR?= ${DESTDIR}/usr/share/atf
102ATF_SHELL?= ${DESTDIR}/bin/sh
103LD_LIBRARY_PATH?= ${TESTS_LD_LIBRARY_PATH:tW:S/ /:/g}
104
105ATF_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)
118TESTS_ENV+= $v=${$v}
119.endif
120.endfor
121
122_TESTS_FIFO= ${.OBJDIR}/atf-run.fifo
123_TESTS_LOG= ${.OBJDIR}/atf-run.log
124CLEANFILES+= ${_TESTS_FIFO} ${_TESTS_LOG}
125
126ATF_BIN?= ${DESTDIR}/usr/bin
127ATF_REPORT?= ${ATF_BIN}/atf-report
128ATF_RUN?= ${ATF_BIN}/atf-run
129
130.PHONY: realtest
131realtest:
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>
149