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