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