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