summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrpaulo <rpaulo@FreeBSD.org>2013-10-19 06:48:49 +0000
committerrpaulo <rpaulo@FreeBSD.org>2013-10-19 06:48:49 +0000
commitcfe21388ca160ef60459717a04f446474687e81c (patch)
treeb75acb04faf3a592bbc877762f093885c7b3fc8e
parentfa957a569b51703a1b35abaabfeab9c428b5be5e (diff)
downloadFreeBSD-src-cfe21388ca160ef60459717a04f446474687e81c.zip
FreeBSD-src-cfe21388ca160ef60459717a04f446474687e81c.tar.gz
Clearly split the logic to build ATF and plain tests apart.
This change introduces a new plain.test.mk file that provides the build infrastructure to build test programs that don't use any framework. Most of the code previously in bsd.test.mk moves to plain.test.mk and atf.test.mk is extended with the missing pieces. In doing so, this change pushes all test program building logic to the various *.test.mk files instead of trying to reuse some tiny bits. In fact, this attempt to reuse some definitions makes the code harder to read and harder to extend. The clear benefit of this is that the interface of bsd.test.mk is now clearly delimited. Submitted by: Julio Merino jmmv google.com MFC after: 2 weeks
-rw-r--r--lib/libcrypt/tests/Makefile2
-rw-r--r--share/mk/atf.test.mk60
-rw-r--r--share/mk/bsd.test.mk62
3 files changed, 68 insertions, 56 deletions
diff --git a/lib/libcrypt/tests/Makefile b/lib/libcrypt/tests/Makefile
index 3190dbe..8c818bd 100644
--- a/lib/libcrypt/tests/Makefile
+++ b/lib/libcrypt/tests/Makefile
@@ -2,7 +2,7 @@
# exercise libcrypt
-TESTS_C= crypt_tests
+ATF_TESTS_C= crypt_tests
CFLAGS+= -I${.CURDIR:H}
LDADD+= -L${.OBJDIR:H} -lcrypt
diff --git a/share/mk/atf.test.mk b/share/mk/atf.test.mk
index da4d12f..85ddfa5 100644
--- a/share/mk/atf.test.mk
+++ b/share/mk/atf.test.mk
@@ -1,49 +1,53 @@
-# $NetBSD$
# $FreeBSD$
#
+# Logic to build and install ATF test programs; i.e. test programs linked
+# against the ATF libraries.
.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}
+# List of C, C++ and shell test programs to build.
+#
+# Programs listed here are built using PROGS, PROGS_CXX and SCRIPTS,
+# respectively, from bsd.prog.mk. However, the build rules are tweaked to
+# require the ATF libraries.
+#
+# Test programs registered in this manner are set to be installed into TESTSDIR
+# (which should be overriden by the Makefile) and are not required to provide a
+# manpage.
+ATF_TESTS_C?=
+ATF_TESTS_CXX?=
+ATF_TESTS_SH?=
+
+.if !empty(ATF_TESTS_C)
+PROGS+= ${ATF_TESTS_C}
+.for _T in ${ATF_TESTS_C}
+BINDIR.${_T}= ${TESTSDIR}
+MAN.${_T}?= # empty
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}
+.if !empty(ATF_TESTS_CXX)
+PROGS_CXX+= ${ATF_TESTS_CXX}
+PROGS+= ${ATF_TESTS_CXX}
+.for _T in ${ATF_TESTS_CXX}
+BINDIR.${_T}= ${TESTSDIR}
+MAN.${_T}?= # empty
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}
+.if !empty(ATF_TESTS_SH)
+SCRIPTS+= ${ATF_TESTS_SH}
+.for _T in ${ATF_TESTS_SH}
+SCRIPTSDIR_${_T}= ${TESTSDIR}
CLEANFILES+= ${_T} ${_T}.tmp
-TESTS_SH_SRC_${_T}?= ${_T}.sh
-${_T}: ${TESTS_SH_SRC_${_T}}
+ATF_TESTS_SH_SRC_${_T}?= ${_T}.sh
+${_T}: ${ATF_TESTS_SH_SRC_${_T}}
echo '#! /usr/bin/atf-sh' > ${.TARGET}.tmp
cat ${.ALLSRC} >> ${.TARGET}.tmp
chmod +x ${.TARGET}.tmp
diff --git a/share/mk/bsd.test.mk b/share/mk/bsd.test.mk
index a75298f..60993b9 100644
--- a/share/mk/bsd.test.mk
+++ b/share/mk/bsd.test.mk
@@ -1,33 +1,37 @@
-# $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
+# Pointer to the top directory into which tests are installed. Should not be
+# overriden by Makefiles, but the user may choose to set this in src.conf(5).
+TESTSBASE?= /usr/tests
-.if defined(TESTS_CXX)
-PROGS_CXX+= ${TESTS_CXX}
-PROGS+= ${TESTS_CXX}
-.for _T in ${TESTS_CXX}
-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_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?=
-TESTSBASE?= ${DESTDIR}/usr/tests
+.if !empty(TESTS_SUBDIRS)
+SUBDIR+= ${TESTS_SUBDIRS}
+.endif
# it is rare for test cases to have man pages
.if !defined(MAN)
@@ -39,10 +43,6 @@ WITHOUT_MAN=yes
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}
@@ -76,4 +76,12 @@ 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>
+.endif
+
.include <bsd.obj.mk>
OpenPOWER on IntegriCloud