summaryrefslogtreecommitdiffstats
path: root/share/mk/bsd.test.mk
diff options
context:
space:
mode:
authorjmmv <jmmv@FreeBSD.org>2013-12-27 22:00:22 +0000
committerjmmv <jmmv@FreeBSD.org>2013-12-27 22:00:22 +0000
commite125f95c9c257e17bc2724cf2f7bdb2a5e1f367c (patch)
tree1119ed400ee859c1a442dea4edd3494fbc8a2f21 /share/mk/bsd.test.mk
parent33f454b5c1f0354b8354b4536b45d3d1d1cc8982 (diff)
downloadFreeBSD-src-e125f95c9c257e17bc2724cf2f7bdb2a5e1f367c.zip
FreeBSD-src-e125f95c9c257e17bc2724cf2f7bdb2a5e1f367c.tar.gz
Split and extend bsd.test.mk into {atf,plain,tap}.test.mk.
This is a MFC of: - r256761 Clearly split the logic to build ATF and plain tests apart. - r256762 Add the automatic generation of Atffile files. - r256763 Add the automatic generation of Kyuafile files. - r256764 Plug atf-run into the 'test' target. - r256765 Plug kyua into the 'test' target. - r257096 Move the TESTSBASE definition to bsd.own.mk. - r257099 Add missing plain.test.mk. - r258297 Remove registration of C++ test programs into PROGS. - r258298 Fix the build of plain test programs. - r258551 Install plain.test.mk. - r259208 Add tap.test.mk. Approved by: rpaulo (mentor)
Diffstat (limited to 'share/mk/bsd.test.mk')
-rw-r--r--share/mk/bsd.test.mk149
1 files changed, 124 insertions, 25 deletions
diff --git a/share/mk/bsd.test.mk b/share/mk/bsd.test.mk
index a75298f..8cdf914 100644
--- a/share/mk/bsd.test.mk
+++ b/share/mk/bsd.test.mk
@@ -1,33 +1,73 @@
-# $NetBSD: bsd.test.mk,v 1.21 2012/08/25 22:21:16 jmmv Exp $
# $FreeBSD$
+#
+# Generic build infrastructure for test programs.
+#
+# The code in this file is independent of the implementation of the test
+# programs being built; this file just provides generic infrastructure for the
+# build and the definition of various helper variables and targets.
+#
+# Makefiles should never include this file directly. Instead, they should
+# include one of the various *.test.mk depending on the specific test programs
+# being built.
.include <bsd.init.mk>
-.if defined(TESTS_C)
-PROGS+= ${TESTS_C}
-.for _T in ${TESTS_C}
-BINDIR.${_T}= ${TESTSDIR}
-MAN.${_T}?= # empty
-.endfor
-.endif
+# Directory in which to install tests defined by the current Makefile.
+# Makefiles have to override this to point to a subdirectory of TESTSBASE.
+TESTSDIR?= .
-.if defined(TESTS_CXX)
-PROGS_CXX+= ${TESTS_CXX}
-PROGS+= ${TESTS_CXX}
-.for _T in ${TESTS_CXX}
-BINDIR.${_T}= ${TESTSDIR}
-MAN.${_T}?= # empty
-.endfor
-.endif
+# Name of the test suite these tests belong to. Should rarely be changed for
+# Makefiles built into the FreeBSD src tree.
+TESTSUITE?= FreeBSD
-.if defined(TESTS_SH)
-SCRIPTS+= ${TESTS_SH}
-.for _T in ${TESTS_SH}
-SCRIPTSDIR_${_T}= ${TESTSDIR}
-.endfor
-.endif
+# List of subdirectories containing tests into which to recurse. This has the
+# same semantics as SUBDIR at build-time. However, the directories listed here
+# get registered into the run-time test suite definitions so that the test
+# engines know to recurse into these directories.
+#
+# In other words: list here any directories that contain test programs but use
+# SUBDIR for directories that may contain helper binaries and/or data files.
+TESTS_SUBDIRS?=
+
+# Knob to control the handling of the Kyuafile for this Makefile.
+#
+# If 'yes', a Kyuafile exists in the source tree and is installed into
+# TESTSDIR.
+#
+# If 'auto', a Kyuafile is automatically generated based on the list of test
+# programs built by the Makefile and is installed into TESTSDIR. This is the
+# default and is sufficient in the majority of the cases.
+#
+# If 'no', no Kyuafile is installed.
+KYUAFILE?= auto
+
+# List of variables to pass to the tests at run-time via the environment.
+TESTS_ENV?=
+
+# Ordered list of directories to construct the PATH for the tests.
+TESTS_PATH+= ${DESTDIR}/bin ${DESTDIR}/sbin \
+ ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin
+TESTS_ENV+= PATH=${TESTS_PATH:tW:C/ +/:/g}
-TESTSBASE?= ${DESTDIR}/usr/tests
+# Ordered list of directories to construct the LD_LIBRARY_PATH for the tests.
+TESTS_LD_LIBRARY_PATH+= ${DESTDIR}/lib ${DESTDIR}/usr/lib
+TESTS_ENV+= LD_LIBRARY_PATH=${TESTS_LD_LIBRARY_PATH:tW:C/ +/:/g}
+
+# List of all tests being built. This variable is internal should not be
+# defined by the Makefile. The various *.test.mk modules extend this variable
+# as needed.
+_TESTS?=
+
+# Path to the prefix of the installed Kyua CLI, if any.
+#
+# If kyua is installed from ports, we automatically define a realtest target
+# below to run the tests using this tool. The tools are searched for in the
+# hierarchy specified by this variable.
+KYUA_PREFIX?= /usr/local
+
+.if !empty(TESTS_SUBDIRS)
+SUBDIR+= ${TESTS_SUBDIRS}
+.endif
# it is rare for test cases to have man pages
.if !defined(MAN)
@@ -39,8 +79,57 @@ WITHOUT_MAN=yes
PROG_VARS+= BINDIR
PROGS_TARGETS+= install
-.if !empty(PROGS) || !empty(PROGS_CXX) || !empty(SCRIPTS)
-.include <bsd.progs.mk>
+.if ${KYUAFILE:tl} != "no"
+FILES+= Kyuafile
+FILESDIR_Kyuafile= ${TESTSDIR}
+
+.if ${KYUAFILE:tl} == "auto"
+CLEANFILES+= Kyuafile Kyuafile.tmp
+
+Kyuafile: Makefile
+ @{ \
+ echo '-- Automatically generated by bsd.test.mk.'; \
+ echo; \
+ echo 'syntax(2)'; \
+ echo; \
+ echo 'test_suite("${TESTSUITE}")'; \
+ echo; \
+ } >Kyuafile.tmp
+.for _T in ${_TESTS}
+ @echo "${TEST_INTERFACE.${_T}}_test_program{name=\"${_T}\"}" \
+ >>Kyuafile.tmp
+.endfor
+.for _T in ${TESTS_SUBDIRS:N.WAIT}
+ @echo "include(\"${_T}/Kyuafile\")" >>Kyuafile.tmp
+.endfor
+ @mv Kyuafile.tmp Kyuafile
+.endif
+.endif
+
+KYUA?= ${KYUA_PREFIX}/bin/kyua
+.if exists(${KYUA})
+# Definition of the "make test" target and supporting variables.
+#
+# This target, by necessity, can only work for native builds (i.e. a FreeBSD
+# host building a release for the same system). The target runs Kyua, which is
+# not in the toolchain, 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.
+realtest: .PHONY
+ @echo "*** WARNING: make test is experimental"
+ @echo "***"
+ @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."
+ @echo
+ @set -e; \
+ ${KYUA} test -k ${DESTDIR}${TESTSDIR}/Kyuafile; \
+ result=0; \
+ echo; \
+ echo "*** Once again, note that "make test" is unsupported."; \
+ test $${result} -eq 0
.endif
beforetest: .PHONY
@@ -76,4 +165,14 @@ test: beforetest realtest
test: aftertest
.endif
+.if !empty(SUBDIR)
+.include <bsd.subdir.mk>
+.endif
+
+.if !empty(PROGS) || !empty(PROGS_CXX) || !empty(SCRIPTS)
+.include <bsd.progs.mk>
+.elif !empty(FILES)
+.include <bsd.files.mk>
+.endif
+
.include <bsd.obj.mk>
OpenPOWER on IntegriCloud