Author: sjg
Date: Wed Nov  7 22:02:02 2012
New Revision: 242711
URL: http://svnweb.freebsd.org/changeset/base/242711

Log:
  Enable ATF testing.
  
  Submitted by: Garrett Cooper
  Approved by:  marcel (mentor)

Added:
  head/share/mk/atf.test.mk   (contents, props changed)
  head/share/mk/bsd.test.mk   (contents, props changed)
Modified:
  head/share/mk/bsd.subdir.mk

Added: head/share/mk/atf.test.mk
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/share/mk/atf.test.mk   Wed Nov  7 22:02:02 2012        (r242711)
@@ -0,0 +1,148 @@
+# $NetBSD$
+# $FreeBSD$
+#
+
+.include <bsd.init.mk>
+
+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 <bsd.subdir.mk>
+.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 <bsd.test.mk>

Modified: head/share/mk/bsd.subdir.mk
==============================================================================
--- head/share/mk/bsd.subdir.mk Wed Nov  7 21:44:04 2012        (r242710)
+++ head/share/mk/bsd.subdir.mk Wed Nov  7 22:02:02 2012        (r242711)
@@ -29,6 +29,9 @@
 #      maninstall, manlint, obj, objlink, realinstall, regress, tags
 #
 
+.if !target(__<bsd.subdir.mk>__)
+__<bsd.subdir.mk>__:
+
 .include <bsd.init.mk>
 
 DISTRIBUTION?= base
@@ -92,3 +95,5 @@ afterinstall:
 install: beforeinstall realinstall afterinstall
 .ORDER: beforeinstall realinstall afterinstall
 .endif
+
+.endif

Added: head/share/mk/bsd.test.mk
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/share/mk/bsd.test.mk   Wed Nov  7 22:02:02 2012        (r242711)
@@ -0,0 +1,79 @@
+# $NetBSD: bsd.test.mk,v 1.21 2012/08/25 22:21:16 jmmv Exp $
+# $FreeBSD$
+
+.include <bsd.init.mk>
+
+.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 <bsd.progs.mk>
+.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 <bsd.obj.mk>
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to