xref: /freebsd/share/mk/bsd.test.mk (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
1#
2# Generic build infrastructure for test programs.
3#
4# This is the only public file that should be included by Makefiles when
5# tests are to be built.  All other *.test.mk files are internal and not
6# to be included directly.
7
8.include <bsd.init.mk>
9
10__<bsd.test.mk>__:
11
12# Third-party software (kyua, etc) prefix.
13LOCALBASE?=	/usr/local
14
15# Tests install directory
16TESTSDIR?=	${TESTSBASE}/${RELDIR:H}
17
18PACKAGE?=	tests
19
20FILESGROUPS+=	${PACKAGE}FILES
21${PACKAGE}FILESPACKAGE=	${PACKAGE}
22${PACKAGE}FILESDIR=	${TESTSDIR}
23
24# List of subdirectories containing tests into which to recurse.  This has the
25# same semantics as SUBDIR at build-time.  However, the directories listed here
26# get registered into the run-time test suite definitions so that the test
27# engines know to recurse into these directories.
28#
29# In other words: list here any directories that contain test programs but use
30# SUBDIR for directories that may contain helper binaries and/or data files.
31TESTS_SUBDIRS?=
32
33# If defined, indicates that the tests built by the Makefile are not part of
34# the FreeBSD Test Suite.  The implication of this is that the tests won't be
35# installed under /usr/tests/ and that Kyua won't be able to run them.
36#NOT_FOR_TEST_SUITE=
37
38# List of variables to pass to the tests at run-time via the environment.
39TESTS_ENV?=
40
41# Force all tests in a separate distribution file.
42#
43# We want this to be the case even when the distribution name is already
44# overridden.  For example: we want the tests for programs in the 'games'
45# distribution to end up in the 'tests' distribution; the test programs
46# themselves have all the necessary logic to detect that the games are not
47# installed and thus won't cause false negatives.
48DISTRIBUTION:=	tests
49
50# Ordered list of directories to construct the PATH for the tests.
51TESTS_PATH+= ${DESTDIR}/bin ${DESTDIR}/sbin \
52             ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin
53TESTS_ENV+= PATH=${TESTS_PATH:tW:C/ +/:/g}
54
55# Ordered list of directories to construct the LD_LIBRARY_PATH for the tests.
56TESTS_LD_LIBRARY_PATH+= ${DESTDIR}/lib ${DESTDIR}/usr/lib
57TESTS_ENV+= LD_LIBRARY_PATH=${TESTS_LD_LIBRARY_PATH:tW:C/ +/:/g}
58
59# List of all tests being built.  The various *.test.mk modules extend this
60# variable as needed.
61_TESTS=
62
63# Pull in the definitions of all supported test interfaces.
64.include <googletest.test.mk>
65.include <plain.test.mk>
66.include <tap.test.mk>
67# Include atf last to let other test framework use it
68.include <atf.test.mk>
69
70# Sort the tests alphabetically, so the results are deterministically formed
71# across runs.
72_TESTS:=	${_TESTS:O}
73
74# kyua automatically descends directories; only run make check on the
75# top-level directory
76.if !make(check)
77.for ts in ${TESTS_SUBDIRS}
78.if empty(SUBDIR:M${ts})
79SUBDIR+= ${ts}
80.endif
81.endfor
82SUBDIR_PARALLEL= t
83.endif
84
85# it is rare for test cases to have man pages
86.if !defined(MAN)
87MAN=
88.endif
89
90.if !defined(NOT_FOR_TEST_SUITE)
91.include <suite.test.mk>
92.endif
93
94.if !target(realcheck)
95realcheck: .PHONY
96	@echo "$@ not defined; skipping"
97.endif
98
99beforecheck realcheck aftercheck check: .PHONY
100.ORDER: beforecheck realcheck aftercheck
101check: beforecheck realcheck aftercheck
102
103.include <bsd.progs.mk>
104