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
This commit is contained in:
Rui Paulo 2013-10-19 06:48:49 +00:00
parent 03466868c3
commit d4a14c8563
3 changed files with 67 additions and 55 deletions

View File

@ -2,7 +2,7 @@
# exercise libcrypt # exercise libcrypt
TESTS_C= crypt_tests ATF_TESTS_C= crypt_tests
CFLAGS+= -I${.CURDIR:H} CFLAGS+= -I${.CURDIR:H}
LDADD+= -L${.OBJDIR:H} -lcrypt LDADD+= -L${.OBJDIR:H} -lcrypt

View File

@ -1,49 +1,53 @@
# $NetBSD$
# $FreeBSD$ # $FreeBSD$
# #
# Logic to build and install ATF test programs; i.e. test programs linked
# against the ATF libraries.
.include <bsd.init.mk> .include <bsd.init.mk>
ATF_TESTS:= # 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 make(*test) .if !empty(ATF_TESTS_C)
TESTSDIR?= . PROGS+= ${ATF_TESTS_C}
.endif .for _T in ${ATF_TESTS_C}
BINDIR.${_T}= ${TESTSDIR}
.if defined(ATF_TESTS_SUBDIRS) MAN.${_T}?= # empty
# 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 SRCS.${_T}?= ${_T}.c
DPADD.${_T}+= ${LIBATF_C} DPADD.${_T}+= ${LIBATF_C}
LDADD.${_T}+= -latf-c LDADD.${_T}+= -latf-c
.endfor .endfor
.endif .endif
.if defined(TESTS_CXX) .if !empty(ATF_TESTS_CXX)
ATF_TESTS+= ${TESTS_CXX} PROGS_CXX+= ${ATF_TESTS_CXX}
.for _T in ${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} SRCS.${_T}?= ${_T}${CXX_SUFFIX:U.cc}
DPADD.${_T}+= ${LIBATF_CXX} ${LIBATF_C} DPADD.${_T}+= ${LIBATF_CXX} ${LIBATF_C}
LDADD.${_T}+= -latf-c++ -latf-c LDADD.${_T}+= -latf-c++ -latf-c
.endfor .endfor
.endif .endif
.if defined(TESTS_SH) .if !empty(ATF_TESTS_SH)
ATF_TESTS+= ${TESTS_SH} SCRIPTS+= ${ATF_TESTS_SH}
.for _T in ${TESTS_SH} .for _T in ${ATF_TESTS_SH}
SCRIPTSDIR_${_T}= ${TESTSDIR}
CLEANFILES+= ${_T} ${_T}.tmp CLEANFILES+= ${_T} ${_T}.tmp
TESTS_SH_SRC_${_T}?= ${_T}.sh ATF_TESTS_SH_SRC_${_T}?= ${_T}.sh
${_T}: ${TESTS_SH_SRC_${_T}} ${_T}: ${ATF_TESTS_SH_SRC_${_T}}
echo '#! /usr/bin/atf-sh' > ${.TARGET}.tmp echo '#! /usr/bin/atf-sh' > ${.TARGET}.tmp
cat ${.ALLSRC} >> ${.TARGET}.tmp cat ${.ALLSRC} >> ${.TARGET}.tmp
chmod +x ${.TARGET}.tmp chmod +x ${.TARGET}.tmp

View File

@ -1,33 +1,37 @@
# $NetBSD: bsd.test.mk,v 1.21 2012/08/25 22:21:16 jmmv Exp $
# $FreeBSD$ # $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> .include <bsd.init.mk>
.if defined(TESTS_C) # Pointer to the top directory into which tests are installed. Should not be
PROGS+= ${TESTS_C} # overriden by Makefiles, but the user may choose to set this in src.conf(5).
.for _T in ${TESTS_C} TESTSBASE?= /usr/tests
BINDIR.${_T}= ${TESTSDIR}
MAN.${_T}?= # empty
.endfor
.endif
.if defined(TESTS_CXX) # Directory in which to install tests defined by the current Makefile.
PROGS_CXX+= ${TESTS_CXX} # Makefiles have to override this to point to a subdirectory of TESTSBASE.
PROGS+= ${TESTS_CXX} TESTSDIR?= .
.for _T in ${TESTS_CXX}
BINDIR.${_T}= ${TESTSDIR}
MAN.${_T}?= # empty
.endfor
.endif
.if defined(TESTS_SH) # List of subdirectories containing tests into which to recurse. This has the
SCRIPTS+= ${TESTS_SH} # same semantics as SUBDIR at build-time. However, the directories listed here
.for _T in ${TESTS_SH} # get registered into the run-time test suite definitions so that the test
SCRIPTSDIR_${_T}= ${TESTSDIR} # engines know to recurse into these directories.
.endfor #
.endif # 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 # it is rare for test cases to have man pages
.if !defined(MAN) .if !defined(MAN)
@ -39,10 +43,6 @@ WITHOUT_MAN=yes
PROG_VARS+= BINDIR PROG_VARS+= BINDIR
PROGS_TARGETS+= install PROGS_TARGETS+= install
.if !empty(PROGS) || !empty(PROGS_CXX) || !empty(SCRIPTS)
.include <bsd.progs.mk>
.endif
beforetest: .PHONY beforetest: .PHONY
.if defined(TESTSDIR) .if defined(TESTSDIR)
.if ${TESTSDIR} == ${TESTSBASE} .if ${TESTSDIR} == ${TESTSBASE}
@ -76,4 +76,12 @@ test: beforetest realtest
test: aftertest test: aftertest
.endif .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> .include <bsd.obj.mk>