1172734Simp# $FreeBSD$
2129198Scognet#
3139735Simp# You must include bsd.test.mk instead of this file from your Makefile.
4129198Scognet#
5129198Scognet# Logic to build and install ATF test programs; i.e. test programs linked
6129198Scognet# against the ATF libraries.
7129198Scognet
8129198Scognet.if !target(__<bsd.test.mk>__)
9129198Scognet.error atf.test.mk cannot be included directly.
10129198Scognet.endif
11129198Scognet
12129198Scognet# List of C, C++ and shell test programs to build.
13129198Scognet#
14129198Scognet# Programs listed here are built using PROGS, PROGS_CXX and SCRIPTS,
15129198Scognet# respectively, from bsd.prog.mk.  However, the build rules are tweaked to
16129198Scognet# require the ATF libraries.
17129198Scognet#
18129198Scognet# Test programs registered in this manner are set to be installed into TESTSDIR
19129198Scognet# (which should be overriden by the Makefile) and are not required to provide a
20129198Scognet# manpage.
21129198ScognetATF_TESTS_C?=
22129198ScognetATF_TESTS_CXX?=
23129198ScognetATF_TESTS_SH?=
24129198Scognet
25129198Scognet# Whether to allow using the deprecated ATF tools or not.
26129198Scognet#
27129198Scognet# If 'yes', this file will generate Atffiles when requested and will also
28129198Scognet# support using the deprecated atf-run tool to execute the tests.
29129198ScognetALLOW_DEPRECATED_ATF_TOOLS?= no
30129198Scognet
31129198Scognet# Knob to control the handling of the Atffile for this Makefile.
32129198Scognet#
33129198Scognet# If 'yes', an Atffile exists in the source tree and is installed into
34129198Scognet# TESTSDIR.
35129198Scognet#
36129198Scognet# If 'auto', an Atffile is automatically generated based on the list of test
37129198Scognet# programs built by the Makefile and is installed into TESTSDIR.  This is the
38129198Scognet# default and is sufficient in the majority of the cases.
39129198Scognet#
40129198Scognet# If 'no', no Atffile is installed.
41129198ScognetATFFILE?= auto
42129198Scognet
43172734Simp# Path to the prefix of the installed ATF tools, if any.
44278656Sian#
45278656Sian# If atf-run and atf-report are installed from ports, we automatically define a
46129198Scognet# realtest target below to run the tests using these tools.  The tools are
47129198Scognet# searched for in the hierarchy specified by this variable.
48129198ScognetATF_PREFIX?= /usr/local
49129198Scognet
50129198Scognet# C compiler passed to ATF tests that need to build code.
51129198ScognetATF_BUILD_CC?= ${DESTDIR}/usr/bin/cc
52129198ScognetTESTS_ENV+= ATF_BUILD_CC=${ATF_BUILD_CC}
53278613Sian
54129198Scognet# C preprocessor passed to ATF tests that need to build code.
55278613SianATF_BUILD_CPP?= ${DESTDIR}/usr/bin/cpp
56129198ScognetTESTS_ENV+= ATF_BUILD_CPP=${ATF_BUILD_CPP}
57129198Scognet
58129198Scognet# C++ compiler passed to ATF tests that need to build code.
59278613SianATF_BUILD_CXX?= ${DESTDIR}/usr/bin/c++
60278613SianTESTS_ENV+= ATF_BUILD_CXX=${ATF_BUILD_CXX}
61278613Sian
62278613Sian# Shell interpreter used to run atf-sh(1) based tests.
63278613SianATF_SHELL?= ${DESTDIR}/bin/sh
64278613SianTESTS_ENV+= ATF_SHELL=${ATF_SHELL}
65278613Sian
66278613Sian.if !empty(ATF_TESTS_C)
67278613SianPROGS+= ${ATF_TESTS_C}
68278613Sian_TESTS+= ${ATF_TESTS_C}
69278613Sian.for _T in ${ATF_TESTS_C}
70278613SianBINDIR.${_T}= ${TESTSDIR}
71278613SianMAN.${_T}?= # empty
72129198ScognetSRCS.${_T}?= ${_T}.c
73129198ScognetDPADD.${_T}+= ${LIBATF_C}
74129198ScognetLDADD.${_T}+= -latf-c
75129198ScognetUSEPRIVATELIB+= atf-c
76129198ScognetTEST_INTERFACE.${_T}= atf
77129198Scognet.endfor
78129198Scognet.endif
79172734Simp
80129198Scognet.if !empty(ATF_TESTS_CXX)
81129198ScognetPROGS_CXX+= ${ATF_TESTS_CXX}
82129198Scognet_TESTS+= ${ATF_TESTS_CXX}
83129198Scognet.for _T in ${ATF_TESTS_CXX}
84129198ScognetBINDIR.${_T}= ${TESTSDIR}
85129198ScognetMAN.${_T}?= # empty
86266311SianSRCS.${_T}?= ${_T}${CXX_SUFFIX:U.cc}
87129198ScognetDPADD.${_T}+= ${LIBATF_CXX} ${LIBATF_C}
88129198ScognetLDADD.${_T}+= -latf-c++ -latf-c
89129198ScognetUSEPRIVATELIB+= atf-c++
90129198ScognetTEST_INTERFACE.${_T}= atf
91129198Scognet.endfor
92129198Scognet.endif
93129198Scognet
94172734Simp.if !empty(ATF_TESTS_SH)
95172734SimpSCRIPTS+= ${ATF_TESTS_SH}
96239268Sgonzo_TESTS+= ${ATF_TESTS_SH}
97129198Scognet.for _T in ${ATF_TESTS_SH}
98129198ScognetSCRIPTSDIR_${_T}= ${TESTSDIR}
99129198ScognetTEST_INTERFACE.${_T}= atf
100129198ScognetCLEANFILES+= ${_T} ${_T}.tmp
101129198Scognet# TODO(jmmv): It seems to me that this SED and SRC functionality should
102129198Scognet# exist in bsd.prog.mk along the support for SCRIPTS.  Move it there if
103129198Scognet# this proves to be useful within the tests.
104129198ScognetATF_TESTS_SH_SED_${_T}?= # empty
105129198ScognetATF_TESTS_SH_SRC_${_T}?= ${_T}.sh
106129198Scognet${_T}: ${ATF_TESTS_SH_SRC_${_T}}
107129198Scognet	echo '#! /usr/libexec/atf-sh' > ${.TARGET}.tmp
108129198Scognet	cat ${.ALLSRC:N*Makefile*} \
109129198Scognet	    | sed ${ATF_TESTS_SH_SED_${_T}} >>${.TARGET}.tmp
110129198Scognet	chmod +x ${.TARGET}.tmp
111129198Scognet	mv ${.TARGET}.tmp ${.TARGET}
112129198Scognet.endfor
113266311Sian.endif
114129198Scognet
115152653Scognet.if ${ALLOW_DEPRECATED_ATF_TOOLS} != "no"
116129198Scognet
117172734Simp.if ${ATFFILE:tl} != "no"
118129198ScognetFILES+=	Atffile
119129198ScognetFILESDIR_Atffile= ${TESTSDIR}
120129198Scognet
121129198Scognet.if ${ATFFILE:tl} == "auto"
122129198ScognetCLEANFILES+= Atffile Atffile.tmp
123129198Scognet
124172734SimpAtffile: Makefile
125172734Simp	@{ echo 'Content-Type: application/X-atf-atffile; version="1"'; \
126172734Simp	echo; \
127244480Sgonzo	echo '# Automatically generated by atf-test.mk.'; \
128253857Sganbold	echo; \
129239268Sgonzo	echo 'prop: test-suite = "'${TESTSUITE}'"'; \
130239268Sgonzo	echo; \
131239268Sgonzo	for tp in ${ATF_TESTS_C} ${ATF_TESTS_CXX} ${ATF_TESTS_SH} \
132239268Sgonzo	    ${TESTS_SUBDIRS}; \
133239268Sgonzo	do \
134249999Swkoszek	    echo "tp: $${tp}"; \
135266341Sian	done; } >Atffile.tmp
136266341Sian	@mv Atffile.tmp Atffile
137266341Sian.endif
138266341Sian.endif
139266058Sian
140129198ScognetATF_REPORT?= ${ATF_PREFIX}/bin/atf-report
141183835SrajATF_RUN?= ${ATF_PREFIX}/bin/atf-run
142239268Sgonzo.if exists(${ATF_RUN}) && exists(${ATF_REPORT})
143183835Sraj# Definition of the "make test" target and supporting variables.
144239268Sgonzo#
145239268Sgonzo# This target, by necessity, can only work for native builds (i.e. a freeBSD
146239268Sgonzo# host building a release for the same system).  The target runs ATF, which is
147239268Sgonzo# not in the toolchain, and the tests execute code built for the target host.
148239268Sgonzo#
149239268Sgonzo# Due to the dependencies of the binaries built by the source tree and how they
150239268Sgonzo# are used by tests, it is highly possible for a execution of "make test" to
151239268Sgonzo# report bogus results unless the new binaries are put in place.
152239268Sgonzo_TESTS_FIFO= ${.OBJDIR}/atf-run.fifo
153239268Sgonzo_TESTS_LOG= ${.OBJDIR}/atf-run.log
154239268SgonzoCLEANFILES+= ${_TESTS_FIFO} ${_TESTS_LOG}
155239268Sgonzorealtest: .PHONY
156240486Sgber	@set -e; \
157239268Sgonzo	if [ -z "${TESTSDIR}" ]; then \
158239268Sgonzo	    echo "*** No TESTSDIR defined; nothing to do."; \
159239268Sgonzo	    exit 0; \
160204121Skevlo	fi; \
161204121Skevlo	cd ${DESTDIR}${TESTSDIR}; \
162129198Scognet	rm -f ${_TESTS_FIFO}; \
163129198Scognet	mkfifo ${_TESTS_FIFO}; \
164129198Scognet	tee ${_TESTS_LOG} < ${_TESTS_FIFO} | ${TESTS_ENV} ${ATF_REPORT} & \
165129198Scognet	set +e; \
166129198Scognet	${TESTS_ENV} ${ATF_RUN} >> ${_TESTS_FIFO}; \
167129198Scognet	result=$${?}; \
168129198Scognet	wait; \
169129198Scognet	rm -f ${_TESTS_FIFO}; \
170129198Scognet	echo; \
171172734Simp	echo "*** The verbatim output of atf-run has been saved to ${_TESTS_LOG}"; \
172129198Scognet	echo "***"; \
173129198Scognet	echo "*** WARNING: atf-run is deprecated; please install kyua instead"; \
174129198Scognet	exit $${result}
175129198Scognet.endif
176161592Scognet
177161592Scognet.endif
178164080Scognet