1# $NetBSD: bsd.test.mk,v 1.13 2010/08/23 16:03:03 joerg Exp $ 2# 3 4.include <bsd.init.mk> 5 6_TESTS= # empty 7 8.if defined(TESTS_SUBDIRS) 9SUBDIR+= ${TESTS_SUBDIRS} 10_TESTS:= ${TESTS_SUBDIRS:N.WAIT} 11.endif 12 13.include <bsd.subdir.mk> 14 15.if defined(TESTS_C) 16PROGS+= ${TESTS_C} 17LDADD+= -latf-c 18. for _T in ${TESTS_C} 19BINDIR.${_T}= ${TESTSDIR} 20MAN.${_T}?= # empty 21_TESTS+= ${_T} 22. endfor 23.endif 24 25.if defined(TESTS_CXX) 26PROGS_CXX+= ${TESTS_CXX} 27LDADD+= -latf-c++ -latf-c 28. for _T in ${TESTS_CXX} 29BINDIR.${_T}= ${TESTSDIR} 30MAN.${_T}?= # empty 31_TESTS+= ${_T} 32. endfor 33.endif 34 35.if defined(TESTS_SH) 36 37. for _T in ${TESTS_SH} 38SCRIPTS+= ${_T} 39SCRIPTSDIR_${_T}= ${TESTSDIR} 40 41_TESTS+= ${_T} 42CLEANFILES+= ${_T} ${_T}.tmp 43 44TESTS_SH_SRC_${_T}?= ${_T}.sh 45${_T}: ${TESTS_SH_SRC_${_T}} 46 ${_MKTARGET_BUILD} 47 echo '#! /usr/bin/atf-sh' >${.TARGET}.tmp 48 cat ${.ALLSRC} >>${.TARGET}.tmp 49 chmod +x ${.TARGET}.tmp 50 mv ${.TARGET}.tmp ${.TARGET} 51. endfor 52.endif 53 54ATFFILE?= auto 55 56.if empty(ATFFILE:M[Nn][Oo]) 57FILES+= Atffile 58FILESDIR_Atffile= ${TESTSDIR} 59 60. if !empty(ATFFILE:M[Aa][Uu][Tt][Oo]) 61realall: Atffile 62Atffile: Makefile 63 ${_MKTARGET_CREATE} 64 @{ echo 'Content-Type: application/X-atf-atffile; version="1"'; \ 65 echo; \ 66 echo '# Automatically generated by bsd.test.mk.'; \ 67 echo; \ 68 echo 'prop: test-suite = "NetBSD"'; \ 69 echo; \ 70 for tp in ${_TESTS}; do \ 71 echo "tp: $${tp}"; \ 72 done; } >Atffile.tmp 73 @mv Atffile.tmp Atffile 74 75clean: clean-atffile 76clean-atffile: .PHONY 77 rm -f Atffile Atffile.tmp 78. endif 79 80.include <bsd.files.mk> 81.endif 82 83.if !empty(SCRIPTS) || !empty(PROGS) || !empty(PROGS_CXX) 84. include <bsd.prog.mk> 85.endif 86 87# 88# Definition of the "make test" target and supporting variables. 89# 90# This target, by necessity, can only work for native builds (i.e. a NetBSD 91# host building a release for the same system). The target runs ATF, which is 92# not in the toolchain, and the tests execute code built for the target host. 93# 94# Due to the dependencies of the binaries built by the source tree and how they 95# are used by tests, it is highly possible for a execution of "make test" to 96# report bogus results unless the new binaries are put in place. 97# 98 99TESTS_PATH += ${DESTDIR}/bin ${DESTDIR}/sbin ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin 100TESTS_LD_LIBRARY_PATH += ${DESTDIR}/lib ${DESTDIR}/usr/lib 101 102TESTS_ENV += LD_LIBRARY_PATH=${TESTS_LD_LIBRARY_PATH:tW:S/ /:/g} 103TESTS_ENV += PATH=${TESTS_PATH:tW:S/ /:/g} 104 105_TESTS_FIFO = ${.OBJDIR}/atf-run.fifo 106_TESTS_LOG = ${.OBJDIR}/atf-run.log 107CLEANFILES += ${_TESTS_FIFO} ${_TESTS_LOG} 108 109.PHONY: test 110.if defined(TESTSDIR) 111. if ${TESTSDIR} == ${TESTSBASE} 112# Forbid this case. It is likely to cause false positives/negatives and it 113# does not cover all the tests (e.g. it misses testing software in external). 114test: 115 @echo "*** Sorry, you cannot use make test from src/tests. Install the" 116 @echo "*** tests into their final location and run them from /usr/tests" 117 @false 118. else 119test: 120 @echo "*** WARNING: make test is experimental" 121 @echo "***" 122 @echo "*** Using this test does not preclude you from running the tests" 123 @echo "*** installed in /usr/tests. This test run may raise false" 124 @echo "*** positives and/or false negatives." 125 @echo 126 @set -e; \ 127 cd ${DESTDIR}${TESTSDIR}; \ 128 mkfifo ${_TESTS_FIFO}; \ 129 cat ${_TESTS_FIFO} | tee ${_TESTS_LOG} | \ 130 ${TESTS_ENV} ${DESTDIR}/usr/bin/atf-report & \ 131 ${TESTS_ENV} ${DESTDIR}/usr/bin/atf-run >>${_TESTS_FIFO}; \ 132 result=$${?}; \ 133 wait; \ 134 rm -f ${_TESTS_FIFO}; \ 135 echo; \ 136 echo "*** The verbatim output of atf-run has been saved to ${_TESTS_LOG}"; \ 137 echo "*** Once again, note that "make test" is unsupported."; \ 138 test $${result} -eq 0 139. endif 140.else 141test: 142 @echo "*** No TESTSDIR defined; nothing to do." 143.endif 144