xref: /freebsd/share/mk/bsd.test.mk (revision 39ee7a7a6bdd1557b1c3532abf60d139798ac88b)
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# Tests install directory
14TESTSDIR?=	${TESTSBASE}/${RELDIR:H}
15
16# List of subdirectories containing tests into which to recurse.  This has the
17# same semantics as SUBDIR at build-time.  However, the directories listed here
18# get registered into the run-time test suite definitions so that the test
19# engines know to recurse into these directories.
20#
21# In other words: list here any directories that contain test programs but use
22# SUBDIR for directories that may contain helper binaries and/or data files.
23TESTS_SUBDIRS?=
24
25# If defined, indicates that the tests built by the Makefile are not part of
26# the FreeBSD Test Suite.  The implication of this is that the tests won't be
27# installed under /usr/tests/ and that Kyua won't be able to run them.
28#NOT_FOR_TEST_SUITE=
29
30# List of variables to pass to the tests at run-time via the environment.
31TESTS_ENV?=
32
33# Force all tests in a separate distribution file.
34#
35# We want this to be the case even when the distribution name is already
36# overriden.  For example: we want the tests for programs in the 'games'
37# distribution to end up in the 'tests' distribution; the test programs
38# themselves have all the necessary logic to detect that the games are not
39# installed and thus won't cause false negatives.
40DISTRIBUTION:=	tests
41
42# Ordered list of directories to construct the PATH for the tests.
43TESTS_PATH+= ${DESTDIR}/bin ${DESTDIR}/sbin \
44             ${DESTDIR}/usr/bin ${DESTDIR}/usr/sbin
45TESTS_ENV+= PATH=${TESTS_PATH:tW:C/ +/:/g}
46
47# Ordered list of directories to construct the LD_LIBRARY_PATH for the tests.
48TESTS_LD_LIBRARY_PATH+= ${DESTDIR}/lib ${DESTDIR}/usr/lib
49TESTS_ENV+= LD_LIBRARY_PATH=${TESTS_LD_LIBRARY_PATH:tW:C/ +/:/g}
50
51# List of all tests being built.  The various *.test.mk modules extend this
52# variable as needed.
53_TESTS=
54
55# Pull in the definitions of all supported test interfaces.
56.include <atf.test.mk>
57.include <plain.test.mk>
58.include <tap.test.mk>
59
60.for ts in ${TESTS_SUBDIRS}
61.if empty(SUBDIR:M${ts})
62SUBDIR+= ${ts}
63.endif
64.endfor
65
66# it is rare for test cases to have man pages
67.if !defined(MAN)
68MAN=
69.endif
70
71# tell progs.mk we might want to install things
72PROG_VARS+= BINDIR
73PROGS_TARGETS+= install
74
75.if !defined(NOT_FOR_TEST_SUITE)
76.include <suite.test.mk>
77.endif
78
79.if !target(realtest)
80realtest: .PHONY
81	@echo "$@ not defined; skipping"
82.endif
83
84test: .PHONY
85.ORDER: beforetest realtest
86test: beforetest realtest
87
88.if target(aftertest)
89.ORDER: realtest aftertest
90test: aftertest
91.endif
92
93.ifdef PROG
94# we came here via bsd.progs.mk below
95# parent will do staging.
96MK_STAGING= no
97.endif
98
99.if !empty(PROGS) || !empty(PROGS_CXX) || !empty(SCRIPTS)
100.include <bsd.progs.mk>
101.endif
102.include <bsd.files.mk>
103
104.if !defined(PROG) && ${MK_STAGING} != "no"
105.if !defined(_SKIP_BUILD)
106# this will handle staging if needed
107_SKIP_STAGING= no
108# but we don't want it to build anything
109_SKIP_BUILD=
110.endif
111.if !empty(PROGS)
112stage_files.prog: ${PROGS}
113.endif
114.include <bsd.prog.mk>
115.endif
116
117.if !target(objwarn)
118.include <bsd.obj.mk>
119.endif
120