Home | History | Annotate | Line # | Download | only in mk
bsd.test.mk revision 1.19.2.2
      1 # $NetBSD: bsd.test.mk,v 1.19.2.2 2014/05/22 11:37:53 yamt Exp $
      2 #
      3 
      4 .include <bsd.init.mk>
      5 
      6 _TESTS:=	# empty
      7 
      8 .if defined(TESTS_SUBDIRS)
      9 SUBDIR+=	${TESTS_SUBDIRS}
     10 .endif
     11 
     12 .include <bsd.subdir.mk>
     13 
     14 .if defined(TESTS_C)
     15 _TESTS+=	${TESTS_C}
     16 PROGS+=		${TESTS_C}
     17 .  for _T in ${TESTS_C}
     18 BINDIR.${_T}=	${TESTSDIR}
     19 LDADD.${_T}+=	-latf-c
     20 DPADD.${_T}+=	${LIBATF_C}
     21 MAN.${_T}?=	# empty
     22 .  endfor
     23 .endif
     24 
     25 .if defined(TESTS_CXX)
     26 _TESTS+=	${TESTS_CXX}
     27 PROGS_CXX+=	${TESTS_CXX}
     28 .  for _T in ${TESTS_CXX}
     29 BINDIR.${_T}=	${TESTSDIR}
     30 LDADD.${_T}+=	-latf-c++ -latf-c
     31 DPADD.${_T}+=	${LIBATF_CXX} ${LIBATF_C}
     32 MAN.${_T}?=	# empty
     33 .  endfor
     34 .endif
     35 
     36 .if defined(TESTS_SH)
     37 _TESTS+=		${TESTS_SH}
     38 CLEANDIRFILES+=		${TESTS_SH}
     39 
     40 .  for _T in ${TESTS_SH}
     41 SCRIPTS+=		${_T}
     42 SCRIPTSDIR_${_T}=	${TESTSDIR}
     43 
     44 CLEANDIRFILES+=		${_T}.tmp
     45 
     46 TESTS_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 
     56 ATFFILE?=	auto
     57 .if ${MKKYUA} != "no"
     58 KYUAFILE?=	${ATFFILE}
     59 .else
     60 KYUAFILE=	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.
     69 ATFFILE_EXTRA_SUBDIRS?=
     70 
     71 .if ${ATFFILE:tl} != "no"
     72 FILES+=			Atffile
     73 FILESDIR_Atffile=	${TESTSDIR}
     74 
     75 .  if ${ATFFILE:tl} == "auto"
     76 CLEANDIRFILES+=	Atffile Atffile.tmp
     77 
     78 realall: Atffile
     79 Atffile: 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"
     96 FILES+=			Kyuafile
     97 FILESDIR_Kyuafile=	${TESTSDIR}
     98 
     99 .  if ${KYUAFILE:tl} == "auto"
    100 CLEANDIRFILES+=	Kyuafile Kyuafile.tmp
    101 
    102 realall: Kyuafile
    103 Kyuafile: 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 
    150 TESTS_PATH += ${DESTDIR}/bin ${DESTDIR}/sbin ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin
    151 TESTS_LD_LIBRARY_PATH += ${DESTDIR}/lib ${DESTDIR}/usr/lib
    152 
    153 TESTS_ENV += ATF_BUILD_CC=${DESTDIR}/usr/bin/cc
    154 TESTS_ENV += ATF_BUILD_CPP=${DESTDIR}/usr/bin/cpp
    155 TESTS_ENV += ATF_BUILD_CXX=${DESTDIR}/usr/bin/c++
    156 TESTS_ENV += ATF_CONFDIR=${DESTDIR}/etc
    157 TESTS_ENV += ATF_INCLUDEDIR=${DESTDIR}/usr/include
    158 TESTS_ENV += ATF_LIBDIR=${DESTDIR}/usr/lib
    159 TESTS_ENV += ATF_LIBEXECDIR=${DESTDIR}/usr/libexec
    160 TESTS_ENV += ATF_PKGDATADIR=${DESTDIR}/usr/share/atf
    161 TESTS_ENV += ATF_SHELL=${DESTDIR}/bin/sh
    162 TESTS_ENV += LD_LIBRARY_PATH=${TESTS_LD_LIBRARY_PATH:tW:S/ /:/g}
    163 TESTS_ENV += PATH=${TESTS_PATH:tW:S/ /:/g}
    164 
    165 _TESTS_FIFO = ${.OBJDIR}/atf-run.fifo
    166 _TESTS_LOG = ${.OBJDIR}/atf-run.log
    167 CLEANDIRFILES += ${_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).
    174 test:
    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
    179 test:
    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
    202 test:
    203 	@echo "*** No TESTSDIR defined; nothing to do."
    204 .endif
    205 
    206 ##### Pull in related .mk logic
    207 .include <bsd.clean.mk>
    208