From bf0395b7a5aecd3253a8c577a57bc5d35467f6e0 Mon Sep 17 00:00:00 2001 From: sjg Date: Wed, 7 Nov 2012 22:02:02 +0000 Subject: Enable ATF testing. Submitted by: Garrett Cooper Approved by: marcel (mentor) --- share/mk/atf.test.mk | 148 +++++++++++++++++++++++++++++++++++++++++++++++++ share/mk/bsd.subdir.mk | 5 ++ share/mk/bsd.test.mk | 79 ++++++++++++++++++++++++++ 3 files changed, 232 insertions(+) create mode 100644 share/mk/atf.test.mk create mode 100644 share/mk/bsd.test.mk (limited to 'share') diff --git a/share/mk/atf.test.mk b/share/mk/atf.test.mk new file mode 100644 index 0000000..7e19087 --- /dev/null +++ b/share/mk/atf.test.mk @@ -0,0 +1,148 @@ +# $NetBSD$ +# $FreeBSD$ +# + +.include + +ATF_TESTS:= + +.if make(*test) +TESTSDIR?= . +.endif + +.if defined(ATF_TESTS_SUBDIRS) +# Only visit subdirs when building, etc because ATF does this it on its own. +.if !make(atf-test) +SUBDIR+= ${ATF_TESTS_SUBDIRS} +.endif +ATF_TESTS+= ${ATF_TESTS_SUBDIRS} + +.include +.endif + +.if defined(TESTS_C) +ATF_TESTS+= ${TESTS_C} +.for _T in ${TESTS_C} +SRCS.${_T}?= ${_T}.c +DPADD.${_T}+= ${LIBATF_C} +LDADD.${_T}+= -latf-c +.endfor +.endif + +.if defined(TESTS_CXX) +ATF_TESTS+= ${TESTS_CXX} +.for _T in ${TESTS_CXX} +SRCS.${_T}?= ${_T}${CXX_SUFFIX:U.cc} +DPADD.${_T}+= ${LIBATF_CXX} ${LIBATF_C} +LDADD.${_T}+= -latf-c++ -latf-c +.endfor +.endif + +.if defined(TESTS_SH) +ATF_TESTS+= ${TESTS_SH} +.for _T in ${TESTS_SH} +CLEANFILES+= ${_T} ${_T}.tmp +TESTS_SH_SRC_${_T}?= ${_T}.sh +${_T}: ${TESTS_SH_SRC_${_T}} + echo '#! /usr/bin/atf-sh' > ${.TARGET}.tmp + cat ${.ALLSRC} >> ${.TARGET}.tmp + chmod +x ${.TARGET}.tmp + mv ${.TARGET}.tmp ${.TARGET} +.endfor +.endif + +ATFFILE?= auto + +.if ${ATFFILE:tl} != "no" +FILES+= Atffile +FILESDIR_Atffile= ${TESTSDIR} + +.if ${ATFFILE:tl} == "auto" +CLEANFILES+= Atffile Atffile.tmp + +Atffile: Makefile + @{ echo 'Content-Type: application/X-atf-atffile; version="1"'; \ + echo; \ + echo '# Automatically generated by atf-test.mk.'; \ + echo; \ + echo 'prop: test-suite = "'`uname -o`'"'; \ + echo; \ + for tp in ${ATF_TESTS}; do \ + echo "tp: $${tp}"; \ + done; } >Atffile.tmp + @mv Atffile.tmp Atffile +.endif +.endif + +# Generate support variables for atf-test. +# +# atf-test can only work for native builds, i.e. a build host of a particular +# OS building a release for the same OS version and architecture. The target +# runs ATF, which is on the build host, and the tests execute code built for +# the target host. +# +# Due to the dependencies of the binaries built by the source tree and how they +# are used by tests, it is highly possible for a execution of "make test" to +# report bogus results unless the new binaries are put in place. + +# XXX (gcooper): Executing ATF from outside the source tree is improper; it +# should be built as part of the OS toolchain build for the host OS and +# executed from there. +ATF_PATH+= ${DESTDIR}/bin ${DESTDIR}/sbin ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin +TESTS_ENV+= PATH=${ATF_PATH:ts:}:${PATH} + +ATF_BUILD_CC?= ${DESTDIR}/usr/bin/cc +ATF_BUILD_CPP?= ${DESTDIR}/usr/bin/cpp +ATF_BUILD_CXX?= ${DESTDIR}/usr/bin/c++ +ATF_CONFDIR?= ${DESTDIR}/etc +ATF_INCLUDEDIR?= ${DESTDIR}/usr/include +ATF_LIBDIR?= ${DESTDIR}/usr/lib +ATF_LIBEXECDIR?= ${DESTDIR}/usr/libexec +ATF_PKGDATADIR?= ${DESTDIR}/usr/share/atf +ATF_SHELL?= ${DESTDIR}/bin/sh +LD_LIBRARY_PATH?= ${TESTS_LD_LIBRARY_PATH:tW:S/ /:/g} + +ATF_ENV_VARS= \ + ATF_BUILD_CC \ + ATF_BUILD_CPP \ + ATF_BUILD_CXX \ + ATF_CONFDIR \ + ATF_INCLUDEDIR \ + ATF_LIBDIR \ + ATF_LIBEXECDIR \ + ATF_PKGDATADIR \ + ATF_SHELL \ + +.for v in ${ATF_ENV_VARS} +.if !empty($v) +TESTS_ENV+= $v=${$v} +.endif +.endfor + +_TESTS_FIFO= ${.OBJDIR}/atf-run.fifo +_TESTS_LOG= ${.OBJDIR}/atf-run.log +CLEANFILES+= ${_TESTS_FIFO} ${_TESTS_LOG} + +ATF_BIN?= ${DESTDIR}/usr/bin +ATF_REPORT?= ${ATF_BIN}/atf-report +ATF_RUN?= ${ATF_BIN}/atf-run + +.PHONY: realtest +realtest: +.if defined(TESTSDIR) + @set -e; \ + cd ${DESTDIR}${TESTSDIR}; \ + rm -f ${_TESTS_FIFO}; \ + mkfifo ${_TESTS_FIFO}; \ + tee ${_TESTS_LOG} < ${_TESTS_FIFO} | ${TESTS_ENV} ${ATF_REPORT} & \ + set +e; \ + ${TESTS_ENV} ${ATF_RUN} >> ${_TESTS_FIFO}; \ + result=$${?}; \ + wait; \ + rm -f ${_TESTS_FIFO}; \ + echo; \ + echo "*** The verbatim output of atf-run has been saved to ${_TESTS_LOG}"; \ + exit $${result} +.endif + +.include diff --git a/share/mk/bsd.subdir.mk b/share/mk/bsd.subdir.mk index a66ab9b..3d5fb61 100644 --- a/share/mk/bsd.subdir.mk +++ b/share/mk/bsd.subdir.mk @@ -29,6 +29,9 @@ # maninstall, manlint, obj, objlink, realinstall, regress, tags # +.if !target(____) +____: + .include DISTRIBUTION?= base @@ -92,3 +95,5 @@ afterinstall: install: beforeinstall realinstall afterinstall .ORDER: beforeinstall realinstall afterinstall .endif + +.endif diff --git a/share/mk/bsd.test.mk b/share/mk/bsd.test.mk new file mode 100644 index 0000000..a75298f --- /dev/null +++ b/share/mk/bsd.test.mk @@ -0,0 +1,79 @@ +# $NetBSD: bsd.test.mk,v 1.21 2012/08/25 22:21:16 jmmv Exp $ +# $FreeBSD$ + +.include + +.if defined(TESTS_C) +PROGS+= ${TESTS_C} +.for _T in ${TESTS_C} +BINDIR.${_T}= ${TESTSDIR} +MAN.${_T}?= # empty +.endfor +.endif + +.if defined(TESTS_CXX) +PROGS_CXX+= ${TESTS_CXX} +PROGS+= ${TESTS_CXX} +.for _T in ${TESTS_CXX} +BINDIR.${_T}= ${TESTSDIR} +MAN.${_T}?= # empty +.endfor +.endif + +.if defined(TESTS_SH) +SCRIPTS+= ${TESTS_SH} +.for _T in ${TESTS_SH} +SCRIPTSDIR_${_T}= ${TESTSDIR} +.endfor +.endif + +TESTSBASE?= ${DESTDIR}/usr/tests + +# it is rare for test cases to have man pages +.if !defined(MAN) +WITHOUT_MAN=yes +.export WITHOUT_MAN +.endif + +# tell progs.mk we might want to install things +PROG_VARS+= BINDIR +PROGS_TARGETS+= install + +.if !empty(PROGS) || !empty(PROGS_CXX) || !empty(SCRIPTS) +.include +.endif + +beforetest: .PHONY +.if defined(TESTSDIR) +.if ${TESTSDIR} == ${TESTSBASE} +# Forbid running from ${TESTSBASE}. It can cause false positives/negatives and +# it does not cover all the tests (e.g. it misses testing software in external). + @echo "*** Sorry, you cannot use make test from src/tests. Install the" + @echo "*** tests into their final location and run them from ${TESTSBASE}" + @false +.else + @echo "*** Using this test does not preclude you from running the tests" + @echo "*** installed in ${TESTSBASE}. This test run may raise false" + @echo "*** positives and/or false negatives." +.endif +.else + @echo "*** No TESTSDIR defined; nothing to do." + @false +.endif + @echo + +.if !target(realtest) +realtest: .PHONY + @echo "$@ not defined; skipping" +.endif + +test: .PHONY +.ORDER: beforetest realtest +test: beforetest realtest + +.if target(aftertest) +.ORDER: realtest aftertest +test: aftertest +.endif + +.include -- cgit v1.1