xref: /freebsd/share/mk/atf.test.mk (revision 6ef6ba9950260f42b47499d17874d00ca9290955)
1# $FreeBSD$
2#
3# Logic to build and install ATF test programs; i.e. test programs linked
4# against the ATF libraries.
5
6.include <bsd.init.mk>
7
8# List of C, C++ and shell test programs to build.
9#
10# Programs listed here are built using PROGS, PROGS_CXX and SCRIPTS,
11# respectively, from bsd.prog.mk.  However, the build rules are tweaked to
12# require the ATF libraries.
13#
14# Test programs registered in this manner are set to be installed into TESTSDIR
15# (which should be overriden by the Makefile) and are not required to provide a
16# manpage.
17ATF_TESTS_C?=
18ATF_TESTS_CXX?=
19ATF_TESTS_SH?=
20
21# Whether to allow using the deprecated ATF tools or not.
22#
23# If 'yes', this file will generate Atffiles when requested and will also
24# support using the deprecated atf-run tool to execute the tests.
25ALLOW_DEPRECATED_ATF_TOOLS?= no
26
27# Knob to control the handling of the Atffile for this Makefile.
28#
29# If 'yes', an Atffile exists in the source tree and is installed into
30# TESTSDIR.
31#
32# If 'auto', an Atffile is automatically generated based on the list of test
33# programs built by the Makefile and is installed into TESTSDIR.  This is the
34# default and is sufficient in the majority of the cases.
35#
36# If 'no', no Atffile is installed.
37ATFFILE?= auto
38
39# Path to the prefix of the installed ATF tools, if any.
40#
41# If atf-run and atf-report are installed from ports, we automatically define a
42# realtest target below to run the tests using these tools.  The tools are
43# searched for in the hierarchy specified by this variable.
44ATF_PREFIX?= /usr/local
45
46# C compiler passed to ATF tests that need to build code.
47ATF_BUILD_CC?= ${DESTDIR}/usr/bin/cc
48TESTS_ENV+= ATF_BUILD_CC=${ATF_BUILD_CC}
49
50# C preprocessor passed to ATF tests that need to build code.
51ATF_BUILD_CPP?= ${DESTDIR}/usr/bin/cpp
52TESTS_ENV+= ATF_BUILD_CPP=${ATF_BUILD_CPP}
53
54# C++ compiler passed to ATF tests that need to build code.
55ATF_BUILD_CXX?= ${DESTDIR}/usr/bin/c++
56TESTS_ENV+= ATF_BUILD_CXX=${ATF_BUILD_CXX}
57
58# Shell interpreter used to run atf-sh(1) based tests.
59ATF_SHELL?= ${DESTDIR}/bin/sh
60TESTS_ENV+= ATF_SHELL=${ATF_SHELL}
61
62.if !empty(ATF_TESTS_C)
63PROGS+= ${ATF_TESTS_C}
64_TESTS+= ${ATF_TESTS_C}
65.for _T in ${ATF_TESTS_C}
66BINDIR.${_T}= ${TESTSDIR}
67MAN.${_T}?= # empty
68SRCS.${_T}?= ${_T}.c
69DPADD.${_T}+= ${LIBATF_C}
70LDADD.${_T}+= -latf-c
71TEST_INTERFACE.${_T}= atf
72.endfor
73.endif
74
75.if !empty(ATF_TESTS_CXX)
76PROGS_CXX+= ${ATF_TESTS_CXX}
77PROGS+= ${ATF_TESTS_CXX}
78_TESTS+= ${ATF_TESTS_CXX}
79.for _T in ${ATF_TESTS_CXX}
80BINDIR.${_T}= ${TESTSDIR}
81MAN.${_T}?= # empty
82SRCS.${_T}?= ${_T}${CXX_SUFFIX:U.cc}
83DPADD.${_T}+= ${LIBATF_CXX} ${LIBATF_C}
84LDADD.${_T}+= -latf-c++ -latf-c
85TEST_INTERFACE.${_T}= atf
86.endfor
87.endif
88
89.if !empty(ATF_TESTS_SH)
90SCRIPTS+= ${ATF_TESTS_SH}
91_TESTS+= ${ATF_TESTS_SH}
92.for _T in ${ATF_TESTS_SH}
93SCRIPTSDIR_${_T}= ${TESTSDIR}
94TEST_INTERFACE.${_T}= atf
95CLEANFILES+= ${_T} ${_T}.tmp
96ATF_TESTS_SH_SRC_${_T}?= ${_T}.sh
97${_T}: ${ATF_TESTS_SH_SRC_${_T}}
98	echo '#! /usr/bin/atf-sh' > ${.TARGET}.tmp
99	cat ${.ALLSRC} >> ${.TARGET}.tmp
100	chmod +x ${.TARGET}.tmp
101	mv ${.TARGET}.tmp ${.TARGET}
102.endfor
103.endif
104
105.if ${ALLOW_DEPRECATED_ATF_TOOLS} != "no"
106
107.if ${ATFFILE:tl} != "no"
108FILES+=	Atffile
109FILESDIR_Atffile= ${TESTSDIR}
110
111.if ${ATFFILE:tl} == "auto"
112CLEANFILES+= Atffile Atffile.tmp
113
114Atffile: Makefile
115	@{ echo 'Content-Type: application/X-atf-atffile; version="1"'; \
116	echo; \
117	echo '# Automatically generated by atf-test.mk.'; \
118	echo; \
119	echo 'prop: test-suite = "'${TESTSUITE}'"'; \
120	echo; \
121	for tp in ${ATF_TESTS_C} ${ATF_TESTS_CXX} ${ATF_TESTS_SH} \
122	    ${TESTS_SUBDIRS}; \
123	do \
124	    echo "tp: $${tp}"; \
125	done; } >Atffile.tmp
126	@mv Atffile.tmp Atffile
127.endif
128.endif
129
130ATF_REPORT?= ${ATF_PREFIX}/bin/atf-report
131ATF_RUN?= ${ATF_PREFIX}/bin/atf-run
132.if exists(${ATF_RUN}) && exists(${ATF_REPORT})
133# Definition of the "make test" target and supporting variables.
134#
135# This target, by necessity, can only work for native builds (i.e. a freeBSD
136# host building a release for the same system).  The target runs ATF, which is
137# not in the toolchain, and the tests execute code built for the target host.
138#
139# Due to the dependencies of the binaries built by the source tree and how they
140# are used by tests, it is highly possible for a execution of "make test" to
141# report bogus results unless the new binaries are put in place.
142_TESTS_FIFO= ${.OBJDIR}/atf-run.fifo
143_TESTS_LOG= ${.OBJDIR}/atf-run.log
144CLEANFILES+= ${_TESTS_FIFO} ${_TESTS_LOG}
145realtest: .PHONY
146	@set -e; \
147	if [ -z "${TESTSDIR}" ]; then \
148	    echo "*** No TESTSDIR defined; nothing to do."; \
149	    exit 0; \
150	fi; \
151	cd ${DESTDIR}${TESTSDIR}; \
152	rm -f ${_TESTS_FIFO}; \
153	mkfifo ${_TESTS_FIFO}; \
154	tee ${_TESTS_LOG} < ${_TESTS_FIFO} | ${TESTS_ENV} ${ATF_REPORT} & \
155	set +e; \
156	${TESTS_ENV} ${ATF_RUN} >> ${_TESTS_FIFO}; \
157	result=$${?}; \
158	wait; \
159	rm -f ${_TESTS_FIFO}; \
160	echo; \
161	echo "*** The verbatim output of atf-run has been saved to ${_TESTS_LOG}"; \
162	echo "***"; \
163	echo "*** WARNING: atf-run is deprecated; please install kyua instead"; \
164	exit $${result}
165.endif
166
167.endif
168
169.include <bsd.test.mk>
170