1# 2# If MK_RUN_TESTS is "yes"; we want to run tests for "host" 3# during the build - and fail the build if any test fails. 4# 5# HOST_RUN_TESTS can be used to filter which tests should be built and 6# run. It should be a list of glob patterns to apply to RELDIR, 7# so "*" would mean all. 8# 9# For the DIRDEPS_BUILD, HOST_RUN_TESTS defaults to "*" as the 10# selection of tests to build and run is taken controlled at level 0 11# in local.dirdeps.mk 12# 13 14.if !target(__<bsd.test.mk>__) 15.error ${.PARSEFILE} cannot be included directly. 16.endif 17 18all: 19 20.if ${.MAKE.LEVEL} > 0 && !empty(_TESTS) && ${MACHINE:Nhost*} == "" 21 22# allow for customization 23.-include <local.host.test.mk> 24 25.if ${MK_DIRDEPS_BUILD} == "yes" 26# orchestration choices are already made 27HOST_RUN_TESTS ?= * 28.else 29.if empty(RELDIR) 30RELDIR:= ${.CURDIR:S,${SRCTOP}/,,:S,${OBJTOP}/,,} 31.endif 32.endif 33 34.if ${HOST_RUN_TESTS:Uno:@x@${RELDIR:M$x}@} != "" 35all: run-tests 36.endif 37 38KYUA?= kyua 39 40# we need to make sure kyua-report can find the results 41KYUA_RESULTS?= ${.OBJDIR}/kyua.results 42KYUA_ARGS?= --results-file=${KYUA_RESULTS} 43KYUA_ENV?= HOME=${KYUA_HOME} TMPDIR=${.OBJDIR} 44KYUA_FLAGS?= --config none --loglevel=${KYUA_LOGLEVEL:Uinfo} 45KYUA_HOME?= ${OBJTOP} 46 47.if make(debug*) 48KYUA_LOGLEVEL?= debug 49.endif 50 51# some tests have files they need 52.if ${${PACKAGE}FILES:U:NKyuafile} != "" 53run-tests run-tests.log: link-test-files 54link-test-files: ${${PACKAGE}FILES:NKyuafile} 55 @for f in ${.ALLSRC:N*Kyuafile:M*/*}; do \ 56 ln -sf $$f .; \ 57 done 58.endif 59 60# we do not want to stage any of this 61RUN_TESTS_LOG= run-tests.log 62MK_STAGING= no 63META_XTRAS+= ${RUN_TESTS_LOG} 64 65run-tests: ${RUN_TESTS_LOG} 66 67# This is the main event. 68# Run kyua-test followed by kyua-report. 69# If we have any test failues we want to run kyua-report --verbose 70# Also on fail, we rename run-tests.log to run-tests.err so we save the 71# output but the target will be out-of-date. 72# We prepend ${.OBJDIR}:${.OBJDIR:H}: to PATH seen by kyua 73# so tests for things like cat, cp, cmp etc can find the one we just built 74# rather than the one from the host. 75${RUN_TESTS_LOG}: ${_TESTS} Kyuafile 76 @( export PATH=${.OBJDIR}:${.OBJDIR:H}:${PATH}; \ 77 rm -f ${KYUA_RESULTS}; \ 78 ${KYUA_ENV} ${KYUA} ${KYUA_FLAGS} test ${KYUA_ARGS} -k ${.OBJDIR}/Kyuafile --build-root=${.OBJDIR} && \ 79 ${KYUA_ENV} ${KYUA} ${KYUA_FLAGS} report ${KYUA_ARGS} ) > ${.TARGET} || \ 80 { mv ${.TARGET} ${.TARGET:R}.err; \ 81 ${KYUA_ENV} ${KYUA} ${KYUA_FLAGS} report ${KYUA_ARGS} --verbose --results-filter broken,failed; echo See ${.TARGET:R:tA}.err; \ 82 exit 1; } 83 84# make kyua-debug KYUA_DEBUG_ARGS=app:test 85kyua-debug: 86 @(export PATH=${.OBJDIR}:${.OBJDIR:H}:${PATH}; \ 87 ${KYUA_ENV} ${KYUA} ${KYUA_FLAGS} debug ${KYUA_DEBUG_ARGS}) || true 88 89.endif 90