xref: /freebsd/share/mk/atf.test.mk (revision db572ab644b54b2921e8514f29f3677c814a2784)
150c5d27bSSimon J. Gerraty# $FreeBSD$
250c5d27bSSimon J. Gerraty#
3f5fd950eSJulio Merino# You must include bsd.test.mk instead of this file from your Makefile.
4f5fd950eSJulio Merino#
5d4a14c85SRui Paulo# Logic to build and install ATF test programs; i.e. test programs linked
6d4a14c85SRui Paulo# against the ATF libraries.
750c5d27bSSimon J. Gerraty
8f5fd950eSJulio Merino.if !target(__<bsd.test.mk>__)
9f5fd950eSJulio Merino.error atf.test.mk cannot be included directly.
10f5fd950eSJulio Merino.endif
1150c5d27bSSimon J. Gerraty
12d4a14c85SRui Paulo# List of C, C++ and shell test programs to build.
13d4a14c85SRui Paulo#
14d4a14c85SRui Paulo# Programs listed here are built using PROGS, PROGS_CXX and SCRIPTS,
15d4a14c85SRui Paulo# respectively, from bsd.prog.mk.  However, the build rules are tweaked to
16d4a14c85SRui Paulo# require the ATF libraries.
17d4a14c85SRui Paulo#
18d4a14c85SRui Paulo# Test programs registered in this manner are set to be installed into TESTSDIR
19d4a14c85SRui Paulo# (which should be overriden by the Makefile) and are not required to provide a
20d4a14c85SRui Paulo# manpage.
21d4a14c85SRui PauloATF_TESTS_C?=
22d4a14c85SRui PauloATF_TESTS_CXX?=
23d4a14c85SRui PauloATF_TESTS_SH?=
2450c5d27bSSimon J. Gerraty
2526ea29afSRui Paulo# Whether to allow using the deprecated ATF tools or not.
2626ea29afSRui Paulo#
2726ea29afSRui Paulo# If 'yes', this file will generate Atffiles when requested and will also
2826ea29afSRui Paulo# support using the deprecated atf-run tool to execute the tests.
2926ea29afSRui PauloALLOW_DEPRECATED_ATF_TOOLS?= no
3026ea29afSRui Paulo
3126ea29afSRui Paulo# Knob to control the handling of the Atffile for this Makefile.
3226ea29afSRui Paulo#
3326ea29afSRui Paulo# If 'yes', an Atffile exists in the source tree and is installed into
3426ea29afSRui Paulo# TESTSDIR.
3526ea29afSRui Paulo#
3626ea29afSRui Paulo# If 'auto', an Atffile is automatically generated based on the list of test
3726ea29afSRui Paulo# programs built by the Makefile and is installed into TESTSDIR.  This is the
3826ea29afSRui Paulo# default and is sufficient in the majority of the cases.
3926ea29afSRui Paulo#
4026ea29afSRui Paulo# If 'no', no Atffile is installed.
4126ea29afSRui PauloATFFILE?= auto
4226ea29afSRui Paulo
4330cc088dSRui Paulo# Path to the prefix of the installed ATF tools, if any.
4430cc088dSRui Paulo#
4530cc088dSRui Paulo# If atf-run and atf-report are installed from ports, we automatically define a
4630cc088dSRui Paulo# realtest target below to run the tests using these tools.  The tools are
4730cc088dSRui Paulo# searched for in the hierarchy specified by this variable.
4830cc088dSRui PauloATF_PREFIX?= /usr/local
4930cc088dSRui Paulo
5030cc088dSRui Paulo# C compiler passed to ATF tests that need to build code.
5130cc088dSRui PauloATF_BUILD_CC?= ${DESTDIR}/usr/bin/cc
5230cc088dSRui PauloTESTS_ENV+= ATF_BUILD_CC=${ATF_BUILD_CC}
5330cc088dSRui Paulo
5430cc088dSRui Paulo# C preprocessor passed to ATF tests that need to build code.
5530cc088dSRui PauloATF_BUILD_CPP?= ${DESTDIR}/usr/bin/cpp
5630cc088dSRui PauloTESTS_ENV+= ATF_BUILD_CPP=${ATF_BUILD_CPP}
5730cc088dSRui Paulo
5830cc088dSRui Paulo# C++ compiler passed to ATF tests that need to build code.
5930cc088dSRui PauloATF_BUILD_CXX?= ${DESTDIR}/usr/bin/c++
6030cc088dSRui PauloTESTS_ENV+= ATF_BUILD_CXX=${ATF_BUILD_CXX}
6130cc088dSRui Paulo
6230cc088dSRui Paulo# Shell interpreter used to run atf-sh(1) based tests.
6330cc088dSRui PauloATF_SHELL?= ${DESTDIR}/bin/sh
6430cc088dSRui PauloTESTS_ENV+= ATF_SHELL=${ATF_SHELL}
6530cc088dSRui Paulo
66d4a14c85SRui Paulo.if !empty(ATF_TESTS_C)
67d4a14c85SRui PauloPROGS+= ${ATF_TESTS_C}
6825b6a535SRui Paulo_TESTS+= ${ATF_TESTS_C}
69d4a14c85SRui Paulo.for _T in ${ATF_TESTS_C}
70d4a14c85SRui PauloBINDIR.${_T}= ${TESTSDIR}
71d4a14c85SRui PauloMAN.${_T}?= # empty
7250c5d27bSSimon J. GerratySRCS.${_T}?= ${_T}.c
7350c5d27bSSimon J. GerratyDPADD.${_T}+= ${LIBATF_C}
74eb1fef65SEnji Cooper.if empty(LDFLAGS:M-static) && empty(LDFLAGS.${_T}:M-static)
75d029c3aaSBaptiste DaroussinLDADD.${_T}+= ${LDATF_C}
76eb1fef65SEnji Cooper.else
77eb1fef65SEnji CooperLDADD.${_T}+= ${LIBATF_C}
78eb1fef65SEnji Cooper.endif
7917a286a9SJulio MerinoUSEPRIVATELIB+= atf-c
8025b6a535SRui PauloTEST_INTERFACE.${_T}= atf
8150c5d27bSSimon J. Gerraty.endfor
8250c5d27bSSimon J. Gerraty.endif
8350c5d27bSSimon J. Gerraty
84d4a14c85SRui Paulo.if !empty(ATF_TESTS_CXX)
85d4a14c85SRui PauloPROGS_CXX+= ${ATF_TESTS_CXX}
8625b6a535SRui Paulo_TESTS+= ${ATF_TESTS_CXX}
87d4a14c85SRui Paulo.for _T in ${ATF_TESTS_CXX}
88d4a14c85SRui PauloBINDIR.${_T}= ${TESTSDIR}
89d4a14c85SRui PauloMAN.${_T}?= # empty
9050c5d27bSSimon J. GerratySRCS.${_T}?= ${_T}${CXX_SUFFIX:U.cc}
9150c5d27bSSimon J. GerratyDPADD.${_T}+= ${LIBATF_CXX} ${LIBATF_C}
92eb1fef65SEnji Cooper.if empty(LDFLAGS:M-static) && empty(LDFLAGS.${_T}:M-static)
93d029c3aaSBaptiste DaroussinLDADD.${_T}+= ${LDATF_CXX} ${LDATF_C}
94eb1fef65SEnji Cooper.else
95eb1fef65SEnji CooperLDADD.${_T}+= ${LIBATF_CXX} ${LIBATF_C}
96eb1fef65SEnji Cooper.endif
9717a286a9SJulio MerinoUSEPRIVATELIB+= atf-c++
9825b6a535SRui PauloTEST_INTERFACE.${_T}= atf
9950c5d27bSSimon J. Gerraty.endfor
10050c5d27bSSimon J. Gerraty.endif
10150c5d27bSSimon J. Gerraty
102d4a14c85SRui Paulo.if !empty(ATF_TESTS_SH)
103d4a14c85SRui PauloSCRIPTS+= ${ATF_TESTS_SH}
10425b6a535SRui Paulo_TESTS+= ${ATF_TESTS_SH}
105d4a14c85SRui Paulo.for _T in ${ATF_TESTS_SH}
106d4a14c85SRui PauloSCRIPTSDIR_${_T}= ${TESTSDIR}
10725b6a535SRui PauloTEST_INTERFACE.${_T}= atf
10850c5d27bSSimon J. GerratyCLEANFILES+= ${_T} ${_T}.tmp
109a845d427SJulio Merino# TODO(jmmv): It seems to me that this SED and SRC functionality should
110a845d427SJulio Merino# exist in bsd.prog.mk along the support for SCRIPTS.  Move it there if
111a845d427SJulio Merino# this proves to be useful within the tests.
112a845d427SJulio MerinoATF_TESTS_SH_SED_${_T}?= # empty
113d4a14c85SRui PauloATF_TESTS_SH_SRC_${_T}?= ${_T}.sh
114d4a14c85SRui Paulo${_T}: ${ATF_TESTS_SH_SRC_${_T}}
1158c7ec47aSJulio Merino	echo '#! /usr/libexec/atf-sh' > ${.TARGET}.tmp
116*db572ab6SEnji Cooper.if empty(ATF_TESTS_SH_SED_${_T})
117*db572ab6SEnji Cooper	cat ${.ALLSRC:N*Makefile*} >>${.TARGET}.tmp
118*db572ab6SEnji Cooper.else
11964dc0245SJulio Merino	cat ${.ALLSRC:N*Makefile*} \
12064dc0245SJulio Merino	    | sed ${ATF_TESTS_SH_SED_${_T}} >>${.TARGET}.tmp
121*db572ab6SEnji Cooper.endif
12250c5d27bSSimon J. Gerraty	chmod +x ${.TARGET}.tmp
12350c5d27bSSimon J. Gerraty	mv ${.TARGET}.tmp ${.TARGET}
12450c5d27bSSimon J. Gerraty.endfor
12550c5d27bSSimon J. Gerraty.endif
12650c5d27bSSimon J. Gerraty
12726ea29afSRui Paulo.if ${ALLOW_DEPRECATED_ATF_TOOLS} != "no"
12826ea29afSRui Paulo
12926ea29afSRui Paulo.if ${ATFFILE:tl} != "no"
13026ea29afSRui PauloFILES+=	Atffile
13126ea29afSRui PauloFILESDIR_Atffile= ${TESTSDIR}
13226ea29afSRui Paulo
13326ea29afSRui Paulo.if ${ATFFILE:tl} == "auto"
13426ea29afSRui PauloCLEANFILES+= Atffile Atffile.tmp
13526ea29afSRui Paulo
13626ea29afSRui PauloAtffile: Makefile
13726ea29afSRui Paulo	@{ echo 'Content-Type: application/X-atf-atffile; version="1"'; \
13826ea29afSRui Paulo	echo; \
13926ea29afSRui Paulo	echo '# Automatically generated by atf-test.mk.'; \
14026ea29afSRui Paulo	echo; \
14126ea29afSRui Paulo	echo 'prop: test-suite = "'${TESTSUITE}'"'; \
14226ea29afSRui Paulo	echo; \
14326ea29afSRui Paulo	for tp in ${ATF_TESTS_C} ${ATF_TESTS_CXX} ${ATF_TESTS_SH} \
14426ea29afSRui Paulo	    ${TESTS_SUBDIRS}; \
14526ea29afSRui Paulo	do \
14626ea29afSRui Paulo	    echo "tp: $${tp}"; \
14726ea29afSRui Paulo	done; } >Atffile.tmp
14826ea29afSRui Paulo	@mv Atffile.tmp Atffile
14926ea29afSRui Paulo.endif
15026ea29afSRui Paulo.endif
15126ea29afSRui Paulo
15230cc088dSRui PauloATF_REPORT?= ${ATF_PREFIX}/bin/atf-report
15330cc088dSRui PauloATF_RUN?= ${ATF_PREFIX}/bin/atf-run
15430cc088dSRui Paulo.if exists(${ATF_RUN}) && exists(${ATF_REPORT})
15530cc088dSRui Paulo# Definition of the "make test" target and supporting variables.
15630cc088dSRui Paulo#
15730cc088dSRui Paulo# This target, by necessity, can only work for native builds (i.e. a freeBSD
15830cc088dSRui Paulo# host building a release for the same system).  The target runs ATF, which is
15930cc088dSRui Paulo# not in the toolchain, and the tests execute code built for the target host.
16030cc088dSRui Paulo#
16130cc088dSRui Paulo# Due to the dependencies of the binaries built by the source tree and how they
16230cc088dSRui Paulo# are used by tests, it is highly possible for a execution of "make test" to
16330cc088dSRui Paulo# report bogus results unless the new binaries are put in place.
16430cc088dSRui Paulo_TESTS_FIFO= ${.OBJDIR}/atf-run.fifo
16530cc088dSRui Paulo_TESTS_LOG= ${.OBJDIR}/atf-run.log
16630cc088dSRui PauloCLEANFILES+= ${_TESTS_FIFO} ${_TESTS_LOG}
16730cc088dSRui Paulorealtest: .PHONY
16830cc088dSRui Paulo	@set -e; \
16930cc088dSRui Paulo	if [ -z "${TESTSDIR}" ]; then \
17030cc088dSRui Paulo	    echo "*** No TESTSDIR defined; nothing to do."; \
17130cc088dSRui Paulo	    exit 0; \
17230cc088dSRui Paulo	fi; \
17330cc088dSRui Paulo	cd ${DESTDIR}${TESTSDIR}; \
17430cc088dSRui Paulo	rm -f ${_TESTS_FIFO}; \
17530cc088dSRui Paulo	mkfifo ${_TESTS_FIFO}; \
17630cc088dSRui Paulo	tee ${_TESTS_LOG} < ${_TESTS_FIFO} | ${TESTS_ENV} ${ATF_REPORT} & \
17730cc088dSRui Paulo	set +e; \
17830cc088dSRui Paulo	${TESTS_ENV} ${ATF_RUN} >> ${_TESTS_FIFO}; \
17930cc088dSRui Paulo	result=$${?}; \
18030cc088dSRui Paulo	wait; \
18130cc088dSRui Paulo	rm -f ${_TESTS_FIFO}; \
18230cc088dSRui Paulo	echo; \
18330cc088dSRui Paulo	echo "*** The verbatim output of atf-run has been saved to ${_TESTS_LOG}"; \
18430cc088dSRui Paulo	echo "***"; \
18530cc088dSRui Paulo	echo "*** WARNING: atf-run is deprecated; please install kyua instead"; \
18630cc088dSRui Paulo	exit $${result}
18730cc088dSRui Paulo.endif
18830cc088dSRui Paulo
18926ea29afSRui Paulo.endif
190