1# $NetBSD: bsd.test.mk,v 1.24 2013/02/23 22:01:51 jmmv Exp $ 2# 3 4.include <bsd.init.mk> 5 6_TESTS:= # empty 7 8.if defined(TESTS_SUBDIRS) 9SUBDIR+= ${TESTS_SUBDIRS} 10.endif 11 12.include <bsd.subdir.mk> 13 14.if defined(TESTS_C) 15_TESTS+= ${TESTS_C} 16PROGS+= ${TESTS_C} 17. for _T in ${TESTS_C} 18BINDIR.${_T}= ${TESTSDIR} 19LDADD.${_T}+= -latf-c 20DPADD.${_T}+= ${LIBATF_C} 21MAN.${_T}?= # empty 22. endfor 23.endif 24 25.if defined(TESTS_CXX) 26_TESTS+= ${TESTS_CXX} 27PROGS_CXX+= ${TESTS_CXX} 28. for _T in ${TESTS_CXX} 29BINDIR.${_T}= ${TESTSDIR} 30LDADD.${_T}+= -latf-c++ -latf-c 31DPADD.${_T}+= ${LIBATF_CXX} ${LIBATF_C} 32MAN.${_T}?= # empty 33. endfor 34.endif 35 36.if defined(TESTS_SH) 37_TESTS+= ${TESTS_SH} 38CLEANDIRFILES+= ${TESTS_SH} 39 40. for _T in ${TESTS_SH} 41SCRIPTS+= ${_T} 42SCRIPTSDIR_${_T}= ${TESTSDIR} 43 44CLEANDIRFILES+= ${_T}.tmp 45 46TESTS_SH_SRC_${_T}?= ${_T}.sh 47${_T}: ${TESTS_SH_SRC_${_T}} 48 ${_MKTARGET_BUILD} 49 echo '#! /usr/bin/atf-sh' >${.TARGET}.tmp 50 cat ${.ALLSRC} >>${.TARGET}.tmp 51 chmod +x ${.TARGET}.tmp 52 mv ${.TARGET}.tmp ${.TARGET} 53. endfor 54.endif 55 56ATFFILE?= auto 57.if ${MKKYUA} != "no" 58KYUAFILE?= ${ATFFILE} 59.else 60KYUAFILE= no 61.endif 62 63# Additional list of 'tp' entries to add to the Atffile when ATFFILE=auto. 64# These entries must all correspond to subdirectories to descend into. 65# 66# This is useful in the cases where the tests in a single directory come 67# from various sources (e.g. src/tests and src/external/.../tests) and 68# the installation of some of those tests rely on MK* variables being set. 69ATFFILE_EXTRA_SUBDIRS?= 70 71.if ${ATFFILE:tl} != "no" 72FILES+= Atffile 73FILESDIR_Atffile= ${TESTSDIR} 74 75. if ${ATFFILE:tl} == "auto" 76CLEANDIRFILES+= Atffile Atffile.tmp 77 78realall: Atffile 79Atffile: Makefile 80 ${_MKTARGET_CREATE} 81 @{ echo 'Content-Type: application/X-atf-atffile; version="1"'; \ 82 echo; \ 83 echo '# Automatically generated by bsd.test.mk.'; \ 84 echo; \ 85 echo 'prop: test-suite = "NetBSD"'; \ 86 echo; \ 87 for tp in ${TESTS_SUBDIRS:N.WAIT} ${_TESTS} ${ATFFILE_EXTRA_SUBDIRS}; \ 88 do \ 89 echo "tp: $${tp}"; \ 90 done; } >Atffile.tmp 91 @mv Atffile.tmp Atffile 92. endif 93.endif 94 95.if ${KYUAFILE:tl} != "no" 96FILES+= Kyuafile 97FILESDIR_Kyuafile= ${TESTSDIR} 98 99. if ${KYUAFILE:tl} == "auto" 100CLEANDIRFILES+= Kyuafile Kyuafile.tmp 101 102realall: Kyuafile 103Kyuafile: Makefile 104 ${_MKTARGET_CREATE} 105 @{ \ 106 echo '-- Automatically generated by bsd.test.mk.'; \ 107 echo; \ 108 echo 'syntax(2)'; \ 109 echo; \ 110 echo 'test_suite("NetBSD")'; \ 111 if [ -n "${_TESTS}" ]; then \ 112 echo; \ 113 for tp in ${_TESTS}; do \ 114 echo "atf_test_program{name=\"$${tp}\"}"; \ 115 done; \ 116 fi; \ 117 if [ -n "${TESTS_SUBDIRS:N.WAIT}" -o \ 118 -n "${ATFFILE_EXTRA_SUBDIRS}" ]; then \ 119 echo; \ 120 for subdir in ${TESTS_SUBDIRS:N.WAIT} \ 121 ${ATFFILE_EXTRA_SUBDIRS}; do \ 122 echo "include(\"$${subdir}/Kyuafile\")"; \ 123 done; \ 124 fi; \ 125 } >Kyuafile.tmp 126 @mv Kyuafile.tmp Kyuafile 127. endif 128.endif 129 130.if ${ATFFILE:tl} != "no" || ${KYUAFILE:tl} != "no" 131. include <bsd.files.mk> 132.endif 133 134.if !empty(SCRIPTS) || !empty(PROGS) || !empty(PROGS_CXX) 135. include <bsd.prog.mk> 136.endif 137 138# 139# Definition of the "make test" target and supporting variables. 140# 141# This target, by necessity, can only work for native builds (i.e. a NetBSD 142# host building a release for the same system). The target runs ATF, which is 143# not in the toolchain, and the tests execute code built for the target host. 144# 145# Due to the dependencies of the binaries built by the source tree and how they 146# are used by tests, it is highly possible for a execution of "make test" to 147# report bogus results unless the new binaries are put in place. 148# 149 150TESTS_PATH += ${DESTDIR}/bin ${DESTDIR}/sbin ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin 151TESTS_LD_LIBRARY_PATH += ${DESTDIR}/lib ${DESTDIR}/usr/lib 152 153TESTS_ENV += ATF_BUILD_CC=${DESTDIR}/usr/bin/cc 154TESTS_ENV += ATF_BUILD_CPP=${DESTDIR}/usr/bin/cpp 155TESTS_ENV += ATF_BUILD_CXX=${DESTDIR}/usr/bin/c++ 156TESTS_ENV += ATF_CONFDIR=${DESTDIR}/etc 157TESTS_ENV += ATF_INCLUDEDIR=${DESTDIR}/usr/include 158TESTS_ENV += ATF_LIBDIR=${DESTDIR}/usr/lib 159TESTS_ENV += ATF_LIBEXECDIR=${DESTDIR}/usr/libexec 160TESTS_ENV += ATF_PKGDATADIR=${DESTDIR}/usr/share/atf 161TESTS_ENV += ATF_SHELL=${DESTDIR}/bin/sh 162TESTS_ENV += LD_LIBRARY_PATH=${TESTS_LD_LIBRARY_PATH:tW:S/ /:/g} 163TESTS_ENV += PATH=${TESTS_PATH:tW:S/ /:/g} 164 165_TESTS_FIFO = ${.OBJDIR}/atf-run.fifo 166_TESTS_LOG = ${.OBJDIR}/atf-run.log 167CLEANDIRFILES += ${_TESTS_FIFO} ${_TESTS_LOG} 168 169.PHONY: test 170.if defined(TESTSDIR) 171. if ${TESTSDIR} == ${TESTSBASE} 172# Forbid this case. It is likely to cause false positives/negatives and it 173# does not cover all the tests (e.g. it misses testing software in external). 174test: 175 @echo "*** Sorry, you cannot use make test from src/tests. Install the" 176 @echo "*** tests into their final location and run them from /usr/tests" 177 @false 178. else 179test: 180 @echo "*** WARNING: make test is experimental" 181 @echo "***" 182 @echo "*** Using this test does not preclude you from running the tests" 183 @echo "*** installed in /usr/tests. This test run may raise false" 184 @echo "*** positives and/or false negatives." 185 @echo 186 @set -e; \ 187 cd ${DESTDIR}${TESTSDIR}; \ 188 rm -f ${_TESTS_FIFO}; \ 189 mkfifo ${_TESTS_FIFO}; \ 190 cat ${_TESTS_FIFO} | tee ${_TESTS_LOG} | \ 191 ${TESTS_ENV} ${DESTDIR}/usr/bin/atf-report & \ 192 result=0; \ 193 ${TESTS_ENV} ${DESTDIR}/usr/bin/atf-run >>${_TESTS_FIFO} || result=1; \ 194 wait; \ 195 rm -f ${_TESTS_FIFO}; \ 196 echo; \ 197 echo "*** The verbatim output of atf-run has been saved to ${_TESTS_LOG}"; \ 198 echo "*** Once again, note that "make test" is unsupported."; \ 199 test $${result} -eq 0 200. endif 201.else 202test: 203 @echo "*** No TESTSDIR defined; nothing to do." 204.endif 205 206##### Pull in related .mk logic 207.include <bsd.clean.mk> 208