1*11be35a1SLionel Sambuc# $NetBSD: bsd.test.mk,v 1.24 2013/02/23 22:01:51 jmmv Exp $ 29152e1c5SLionel Sambuc# 39152e1c5SLionel Sambuc 49152e1c5SLionel Sambuc.include <bsd.init.mk> 59152e1c5SLionel Sambuc 69152e1c5SLionel Sambuc_TESTS:= # empty 79152e1c5SLionel Sambuc 89152e1c5SLionel Sambuc.if defined(TESTS_SUBDIRS) 99152e1c5SLionel SambucSUBDIR+= ${TESTS_SUBDIRS} 109152e1c5SLionel Sambuc.endif 119152e1c5SLionel Sambuc 129152e1c5SLionel Sambuc.include <bsd.subdir.mk> 139152e1c5SLionel Sambuc 149152e1c5SLionel Sambuc.if defined(TESTS_C) 159152e1c5SLionel Sambuc_TESTS+= ${TESTS_C} 169152e1c5SLionel SambucPROGS+= ${TESTS_C} 179152e1c5SLionel Sambuc. for _T in ${TESTS_C} 189152e1c5SLionel SambucBINDIR.${_T}= ${TESTSDIR} 199152e1c5SLionel SambucLDADD.${_T}+= -latf-c 209152e1c5SLionel SambucDPADD.${_T}+= ${LIBATF_C} 219152e1c5SLionel SambucMAN.${_T}?= # empty 229152e1c5SLionel Sambuc. endfor 239152e1c5SLionel Sambuc.endif 249152e1c5SLionel Sambuc 259152e1c5SLionel Sambuc.if defined(TESTS_CXX) 269152e1c5SLionel Sambuc_TESTS+= ${TESTS_CXX} 279152e1c5SLionel SambucPROGS_CXX+= ${TESTS_CXX} 289152e1c5SLionel Sambuc. for _T in ${TESTS_CXX} 299152e1c5SLionel SambucBINDIR.${_T}= ${TESTSDIR} 309152e1c5SLionel SambucLDADD.${_T}+= -latf-c++ -latf-c 319152e1c5SLionel SambucDPADD.${_T}+= ${LIBATF_CXX} ${LIBATF_C} 329152e1c5SLionel SambucMAN.${_T}?= # empty 339152e1c5SLionel Sambuc. endfor 349152e1c5SLionel Sambuc.endif 359152e1c5SLionel Sambuc 369152e1c5SLionel Sambuc.if defined(TESTS_SH) 379152e1c5SLionel Sambuc_TESTS+= ${TESTS_SH} 389152e1c5SLionel SambucCLEANDIRFILES+= ${TESTS_SH} 399152e1c5SLionel Sambuc 409152e1c5SLionel Sambuc. for _T in ${TESTS_SH} 419152e1c5SLionel SambucSCRIPTS+= ${_T} 429152e1c5SLionel SambucSCRIPTSDIR_${_T}= ${TESTSDIR} 439152e1c5SLionel Sambuc 449152e1c5SLionel SambucCLEANDIRFILES+= ${_T}.tmp 459152e1c5SLionel Sambuc 469152e1c5SLionel SambucTESTS_SH_SRC_${_T}?= ${_T}.sh 479152e1c5SLionel Sambuc${_T}: ${TESTS_SH_SRC_${_T}} 489152e1c5SLionel Sambuc ${_MKTARGET_BUILD} 499152e1c5SLionel Sambuc echo '#! /usr/bin/atf-sh' >${.TARGET}.tmp 509152e1c5SLionel Sambuc cat ${.ALLSRC} >>${.TARGET}.tmp 519152e1c5SLionel Sambuc chmod +x ${.TARGET}.tmp 529152e1c5SLionel Sambuc mv ${.TARGET}.tmp ${.TARGET} 539152e1c5SLionel Sambuc. endfor 549152e1c5SLionel Sambuc.endif 559152e1c5SLionel Sambuc 569152e1c5SLionel SambucATFFILE?= auto 57*11be35a1SLionel Sambuc.if ${MKKYUA} != "no" 58*11be35a1SLionel SambucKYUAFILE?= ${ATFFILE} 59*11be35a1SLionel Sambuc.else 60*11be35a1SLionel SambucKYUAFILE= no 61*11be35a1SLionel Sambuc.endif 62*11be35a1SLionel Sambuc 63*11be35a1SLionel Sambuc# Additional list of 'tp' entries to add to the Atffile when ATFFILE=auto. 64*11be35a1SLionel Sambuc# These entries must all correspond to subdirectories to descend into. 65*11be35a1SLionel Sambuc# 66*11be35a1SLionel Sambuc# This is useful in the cases where the tests in a single directory come 67*11be35a1SLionel Sambuc# from various sources (e.g. src/tests and src/external/.../tests) and 68*11be35a1SLionel Sambuc# the installation of some of those tests rely on MK* variables being set. 69*11be35a1SLionel SambucATFFILE_EXTRA_SUBDIRS?= 709152e1c5SLionel Sambuc 719152e1c5SLionel Sambuc.if ${ATFFILE:tl} != "no" 729152e1c5SLionel SambucFILES+= Atffile 739152e1c5SLionel SambucFILESDIR_Atffile= ${TESTSDIR} 749152e1c5SLionel Sambuc 759152e1c5SLionel Sambuc. if ${ATFFILE:tl} == "auto" 769152e1c5SLionel SambucCLEANDIRFILES+= Atffile Atffile.tmp 779152e1c5SLionel Sambuc 789152e1c5SLionel Sambucrealall: Atffile 799152e1c5SLionel SambucAtffile: Makefile 809152e1c5SLionel Sambuc ${_MKTARGET_CREATE} 819152e1c5SLionel Sambuc @{ echo 'Content-Type: application/X-atf-atffile; version="1"'; \ 829152e1c5SLionel Sambuc echo; \ 839152e1c5SLionel Sambuc echo '# Automatically generated by bsd.test.mk.'; \ 849152e1c5SLionel Sambuc echo; \ 859152e1c5SLionel Sambuc echo 'prop: test-suite = "NetBSD"'; \ 869152e1c5SLionel Sambuc echo; \ 87*11be35a1SLionel Sambuc for tp in ${TESTS_SUBDIRS:N.WAIT} ${_TESTS} ${ATFFILE_EXTRA_SUBDIRS}; \ 88*11be35a1SLionel Sambuc do \ 899152e1c5SLionel Sambuc echo "tp: $${tp}"; \ 909152e1c5SLionel Sambuc done; } >Atffile.tmp 919152e1c5SLionel Sambuc @mv Atffile.tmp Atffile 929152e1c5SLionel Sambuc. endif 93*11be35a1SLionel Sambuc.endif 949152e1c5SLionel Sambuc 95*11be35a1SLionel Sambuc.if ${KYUAFILE:tl} != "no" 96*11be35a1SLionel SambucFILES+= Kyuafile 97*11be35a1SLionel SambucFILESDIR_Kyuafile= ${TESTSDIR} 98*11be35a1SLionel Sambuc 99*11be35a1SLionel Sambuc. if ${KYUAFILE:tl} == "auto" 100*11be35a1SLionel SambucCLEANDIRFILES+= Kyuafile Kyuafile.tmp 101*11be35a1SLionel Sambuc 102*11be35a1SLionel Sambucrealall: Kyuafile 103*11be35a1SLionel SambucKyuafile: Makefile 104*11be35a1SLionel Sambuc ${_MKTARGET_CREATE} 105*11be35a1SLionel Sambuc @{ \ 106*11be35a1SLionel Sambuc echo '-- Automatically generated by bsd.test.mk.'; \ 107*11be35a1SLionel Sambuc echo; \ 108*11be35a1SLionel Sambuc echo 'syntax(2)'; \ 109*11be35a1SLionel Sambuc echo; \ 110*11be35a1SLionel Sambuc echo 'test_suite("NetBSD")'; \ 111*11be35a1SLionel Sambuc if [ -n "${_TESTS}" ]; then \ 112*11be35a1SLionel Sambuc echo; \ 113*11be35a1SLionel Sambuc for tp in ${_TESTS}; do \ 114*11be35a1SLionel Sambuc echo "atf_test_program{name=\"$${tp}\"}"; \ 115*11be35a1SLionel Sambuc done; \ 116*11be35a1SLionel Sambuc fi; \ 117*11be35a1SLionel Sambuc if [ -n "${TESTS_SUBDIRS:N.WAIT}" -o \ 118*11be35a1SLionel Sambuc -n "${ATFFILE_EXTRA_SUBDIRS}" ]; then \ 119*11be35a1SLionel Sambuc echo; \ 120*11be35a1SLionel Sambuc for subdir in ${TESTS_SUBDIRS:N.WAIT} \ 121*11be35a1SLionel Sambuc ${ATFFILE_EXTRA_SUBDIRS}; do \ 122*11be35a1SLionel Sambuc echo "include(\"$${subdir}/Kyuafile\")"; \ 123*11be35a1SLionel Sambuc done; \ 124*11be35a1SLionel Sambuc fi; \ 125*11be35a1SLionel Sambuc } >Kyuafile.tmp 126*11be35a1SLionel Sambuc @mv Kyuafile.tmp Kyuafile 127*11be35a1SLionel Sambuc. endif 128*11be35a1SLionel Sambuc.endif 129*11be35a1SLionel Sambuc 130*11be35a1SLionel Sambuc.if ${ATFFILE:tl} != "no" || ${KYUAFILE:tl} != "no" 1319152e1c5SLionel Sambuc. include <bsd.files.mk> 1329152e1c5SLionel Sambuc.endif 1339152e1c5SLionel Sambuc 1349152e1c5SLionel Sambuc.if !empty(SCRIPTS) || !empty(PROGS) || !empty(PROGS_CXX) 1359152e1c5SLionel Sambuc. include <bsd.prog.mk> 1369152e1c5SLionel Sambuc.endif 1379152e1c5SLionel Sambuc 1389152e1c5SLionel Sambuc# 1399152e1c5SLionel Sambuc# Definition of the "make test" target and supporting variables. 1409152e1c5SLionel Sambuc# 1419152e1c5SLionel Sambuc# This target, by necessity, can only work for native builds (i.e. a NetBSD 1429152e1c5SLionel Sambuc# host building a release for the same system). The target runs ATF, which is 1439152e1c5SLionel Sambuc# not in the toolchain, and the tests execute code built for the target host. 1449152e1c5SLionel Sambuc# 1459152e1c5SLionel Sambuc# Due to the dependencies of the binaries built by the source tree and how they 1469152e1c5SLionel Sambuc# are used by tests, it is highly possible for a execution of "make test" to 1479152e1c5SLionel Sambuc# report bogus results unless the new binaries are put in place. 1489152e1c5SLionel Sambuc# 1499152e1c5SLionel Sambuc 1509152e1c5SLionel SambucTESTS_PATH += ${DESTDIR}/bin ${DESTDIR}/sbin ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin 1519152e1c5SLionel SambucTESTS_LD_LIBRARY_PATH += ${DESTDIR}/lib ${DESTDIR}/usr/lib 1529152e1c5SLionel Sambuc 1539152e1c5SLionel SambucTESTS_ENV += ATF_BUILD_CC=${DESTDIR}/usr/bin/cc 1549152e1c5SLionel SambucTESTS_ENV += ATF_BUILD_CPP=${DESTDIR}/usr/bin/cpp 1559152e1c5SLionel SambucTESTS_ENV += ATF_BUILD_CXX=${DESTDIR}/usr/bin/c++ 1569152e1c5SLionel SambucTESTS_ENV += ATF_CONFDIR=${DESTDIR}/etc 1579152e1c5SLionel SambucTESTS_ENV += ATF_INCLUDEDIR=${DESTDIR}/usr/include 1589152e1c5SLionel SambucTESTS_ENV += ATF_LIBDIR=${DESTDIR}/usr/lib 1599152e1c5SLionel SambucTESTS_ENV += ATF_LIBEXECDIR=${DESTDIR}/usr/libexec 1609152e1c5SLionel SambucTESTS_ENV += ATF_PKGDATADIR=${DESTDIR}/usr/share/atf 1619152e1c5SLionel SambucTESTS_ENV += ATF_SHELL=${DESTDIR}/bin/sh 1629152e1c5SLionel SambucTESTS_ENV += LD_LIBRARY_PATH=${TESTS_LD_LIBRARY_PATH:tW:S/ /:/g} 1639152e1c5SLionel SambucTESTS_ENV += PATH=${TESTS_PATH:tW:S/ /:/g} 1649152e1c5SLionel Sambuc 1659152e1c5SLionel Sambuc_TESTS_FIFO = ${.OBJDIR}/atf-run.fifo 1669152e1c5SLionel Sambuc_TESTS_LOG = ${.OBJDIR}/atf-run.log 1679152e1c5SLionel SambucCLEANDIRFILES += ${_TESTS_FIFO} ${_TESTS_LOG} 1689152e1c5SLionel Sambuc 1699152e1c5SLionel Sambuc.PHONY: test 1709152e1c5SLionel Sambuc.if defined(TESTSDIR) 1719152e1c5SLionel Sambuc. if ${TESTSDIR} == ${TESTSBASE} 1729152e1c5SLionel Sambuc# Forbid this case. It is likely to cause false positives/negatives and it 1739152e1c5SLionel Sambuc# does not cover all the tests (e.g. it misses testing software in external). 1749152e1c5SLionel Sambuctest: 1759152e1c5SLionel Sambuc @echo "*** Sorry, you cannot use make test from src/tests. Install the" 1769152e1c5SLionel Sambuc @echo "*** tests into their final location and run them from /usr/tests" 1779152e1c5SLionel Sambuc @false 1789152e1c5SLionel Sambuc. else 1799152e1c5SLionel Sambuctest: 1809152e1c5SLionel Sambuc @echo "*** WARNING: make test is experimental" 1819152e1c5SLionel Sambuc @echo "***" 1829152e1c5SLionel Sambuc @echo "*** Using this test does not preclude you from running the tests" 1839152e1c5SLionel Sambuc @echo "*** installed in /usr/tests. This test run may raise false" 1849152e1c5SLionel Sambuc @echo "*** positives and/or false negatives." 1859152e1c5SLionel Sambuc @echo 1869152e1c5SLionel Sambuc @set -e; \ 1879152e1c5SLionel Sambuc cd ${DESTDIR}${TESTSDIR}; \ 1889152e1c5SLionel Sambuc rm -f ${_TESTS_FIFO}; \ 1899152e1c5SLionel Sambuc mkfifo ${_TESTS_FIFO}; \ 1909152e1c5SLionel Sambuc cat ${_TESTS_FIFO} | tee ${_TESTS_LOG} | \ 1919152e1c5SLionel Sambuc ${TESTS_ENV} ${DESTDIR}/usr/bin/atf-report & \ 1929152e1c5SLionel Sambuc result=0; \ 1939152e1c5SLionel Sambuc ${TESTS_ENV} ${DESTDIR}/usr/bin/atf-run >>${_TESTS_FIFO} || result=1; \ 1949152e1c5SLionel Sambuc wait; \ 1959152e1c5SLionel Sambuc rm -f ${_TESTS_FIFO}; \ 1969152e1c5SLionel Sambuc echo; \ 1979152e1c5SLionel Sambuc echo "*** The verbatim output of atf-run has been saved to ${_TESTS_LOG}"; \ 1989152e1c5SLionel Sambuc echo "*** Once again, note that "make test" is unsupported."; \ 1999152e1c5SLionel Sambuc test $${result} -eq 0 2009152e1c5SLionel Sambuc. endif 2019152e1c5SLionel Sambuc.else 2029152e1c5SLionel Sambuctest: 2039152e1c5SLionel Sambuc @echo "*** No TESTSDIR defined; nothing to do." 2049152e1c5SLionel Sambuc.endif 2059152e1c5SLionel Sambuc 2069152e1c5SLionel Sambuc##### Pull in related .mk logic 2079152e1c5SLionel Sambuc.include <bsd.clean.mk> 208