3 # You must include bsd.test.mk instead of this file from your Makefile.
5 # Logic to build and install ATF test programs; i.e. test programs linked
6 # against the ATF libraries.
8 .if !target(__<bsd.test.mk>__)
9 .error atf.test.mk cannot be included directly.
12 # List of C, C++ and shell test programs to build.
14 # Programs listed here are built using PROGS, PROGS_CXX and SCRIPTS,
15 # respectively, from bsd.prog.mk. However, the build rules are tweaked to
16 # require the ATF libraries.
18 # Test programs registered in this manner are set to be installed into TESTSDIR
19 # (which should be overriden by the Makefile) and are not required to provide a
25 # Whether to allow using the deprecated ATF tools or not.
27 # If 'yes', this file will generate Atffiles when requested and will also
28 # support using the deprecated atf-run tool to execute the tests.
29 ALLOW_DEPRECATED_ATF_TOOLS?= no
31 # Knob to control the handling of the Atffile for this Makefile.
33 # If 'yes', an Atffile exists in the source tree and is installed into
36 # If 'auto', an Atffile is automatically generated based on the list of test
37 # programs built by the Makefile and is installed into TESTSDIR. This is the
38 # default and is sufficient in the majority of the cases.
40 # If 'no', no Atffile is installed.
43 # Path to the prefix of the installed ATF tools, if any.
45 # If atf-run and atf-report are installed from ports, we automatically define a
46 # realtest target below to run the tests using these tools. The tools are
47 # searched for in the hierarchy specified by this variable.
48 ATF_PREFIX?= /usr/local
50 # C compiler passed to ATF tests that need to build code.
51 ATF_BUILD_CC?= ${DESTDIR}/usr/bin/cc
52 TESTS_ENV+= ATF_BUILD_CC=${ATF_BUILD_CC}
54 # C preprocessor passed to ATF tests that need to build code.
55 ATF_BUILD_CPP?= ${DESTDIR}/usr/bin/cpp
56 TESTS_ENV+= ATF_BUILD_CPP=${ATF_BUILD_CPP}
58 # C++ compiler passed to ATF tests that need to build code.
59 ATF_BUILD_CXX?= ${DESTDIR}/usr/bin/c++
60 TESTS_ENV+= ATF_BUILD_CXX=${ATF_BUILD_CXX}
62 # Shell interpreter used to run atf-sh(1) based tests.
63 ATF_SHELL?= ${DESTDIR}/bin/sh
64 TESTS_ENV+= ATF_SHELL=${ATF_SHELL}
66 .if !empty(ATF_TESTS_C)
67 PROGS+= ${ATF_TESTS_C}
68 _TESTS+= ${ATF_TESTS_C}
69 .for _T in ${ATF_TESTS_C}
70 BINDIR.${_T}= ${TESTSDIR}
73 DPADD.${_T}+= ${LIBATF_C}
74 .if empty(LDFLAGS:M-static) && empty(LDFLAGS.${_T}:M-static)
75 LDADD.${_T}+= ${LDADD_atf_c}
77 LDADD.${_T}+= ${LIBATF_C}
79 TEST_INTERFACE.${_T}= atf
83 .if !empty(ATF_TESTS_CXX)
84 PROGS_CXX+= ${ATF_TESTS_CXX}
85 _TESTS+= ${ATF_TESTS_CXX}
86 .for _T in ${ATF_TESTS_CXX}
87 BINDIR.${_T}= ${TESTSDIR}
89 SRCS.${_T}?= ${_T}${CXX_SUFFIX:U.cc}
90 DPADD.${_T}+= ${LIBATF_CXX} ${LIBATF_C}
91 .if empty(LDFLAGS:M-static) && empty(LDFLAGS.${_T}:M-static)
92 LDADD.${_T}+= ${LDADD_atf_cxx} ${LDADD_atf_c}
94 LDADD.${_T}+= ${LIBATF_CXX} ${LIBATF_C}
96 TEST_INTERFACE.${_T}= atf
100 .if !empty(ATF_TESTS_SH)
101 SCRIPTS+= ${ATF_TESTS_SH}
102 _TESTS+= ${ATF_TESTS_SH}
103 .for _T in ${ATF_TESTS_SH}
104 SCRIPTSDIR_${_T}= ${TESTSDIR}
105 TEST_INTERFACE.${_T}= atf
106 CLEANFILES+= ${_T} ${_T}.tmp
107 # TODO(jmmv): It seems to me that this SED and SRC functionality should
108 # exist in bsd.prog.mk along the support for SCRIPTS. Move it there if
109 # this proves to be useful within the tests.
110 ATF_TESTS_SH_SED_${_T}?= # empty
111 ATF_TESTS_SH_SRC_${_T}?= ${_T}.sh
112 ${_T}: ${ATF_TESTS_SH_SRC_${_T}}
113 echo '#! /usr/libexec/atf-sh' > ${.TARGET}.tmp
114 .if empty(ATF_TESTS_SH_SED_${_T})
115 cat ${.ALLSRC:N*Makefile*} >>${.TARGET}.tmp
117 cat ${.ALLSRC:N*Makefile*} \
118 | sed ${ATF_TESTS_SH_SED_${_T}} >>${.TARGET}.tmp
120 chmod +x ${.TARGET}.tmp
121 mv ${.TARGET}.tmp ${.TARGET}
125 .if ${ALLOW_DEPRECATED_ATF_TOOLS} != "no"
127 .if ${ATFFILE:tl} != "no"
129 FILESDIR_Atffile= ${TESTSDIR}
131 .if ${ATFFILE:tl} == "auto"
132 CLEANFILES+= Atffile Atffile.tmp
135 @{ echo 'Content-Type: application/X-atf-atffile; version="1"'; \
137 echo '# Automatically generated by atf-test.mk.'; \
139 echo 'prop: test-suite = "'${TESTSUITE}'"'; \
141 for tp in ${ATF_TESTS_C} ${ATF_TESTS_CXX} ${ATF_TESTS_SH} \
146 @mv Atffile.tmp Atffile
150 ATF_REPORT?= ${ATF_PREFIX}/bin/atf-report
151 ATF_RUN?= ${ATF_PREFIX}/bin/atf-run
152 .if exists(${ATF_RUN}) && exists(${ATF_REPORT})
153 # Definition of the "make test" target and supporting variables.
155 # This target, by necessity, can only work for native builds (i.e. a freeBSD
156 # host building a release for the same system). The target runs ATF, which is
157 # not in the toolchain, and the tests execute code built for the target host.
159 # Due to the dependencies of the binaries built by the source tree and how they
160 # are used by tests, it is highly possible for a execution of "make test" to
161 # report bogus results unless the new binaries are put in place.
162 _TESTS_FIFO= ${.OBJDIR}/atf-run.fifo
163 _TESTS_LOG= ${.OBJDIR}/atf-run.log
164 CLEANFILES+= ${_TESTS_FIFO} ${_TESTS_LOG}
167 if [ -z "${TESTSDIR}" ]; then \
168 echo "*** No TESTSDIR defined; nothing to do."; \
171 cd ${DESTDIR}${TESTSDIR}; \
172 rm -f ${_TESTS_FIFO}; \
173 mkfifo ${_TESTS_FIFO}; \
174 tee ${_TESTS_LOG} < ${_TESTS_FIFO} | ${TESTS_ENV} ${ATF_REPORT} & \
176 ${TESTS_ENV} ${ATF_RUN} >> ${_TESTS_FIFO}; \
179 rm -f ${_TESTS_FIFO}; \
181 echo "*** The verbatim output of atf-run has been saved to ${_TESTS_LOG}"; \
183 echo "*** WARNING: atf-run is deprecated; please install kyua instead"; \