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