]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - share/mk/suite.test.mk
MFC r292500,r292501,r292504,r292509:
[FreeBSD/stable/10.git] / share / mk / suite.test.mk
1 # $FreeBSD$
2 #
3 # You must include bsd.test.mk instead of this file from your Makefile.
4 #
5 # Internal glue for the build of /usr/tests/.
6
7 .if !target(__<bsd.test.mk>__)
8 .error suite.test.mk cannot be included directly.
9 .endif
10
11 # Name of the test suite these tests belong to.  Should rarely be changed for
12 # Makefiles built into the FreeBSD src tree.
13 TESTSUITE?= FreeBSD
14
15 # Knob to control the handling of the Kyuafile for this Makefile.
16 #
17 # If 'yes', a Kyuafile exists in the source tree and is installed into
18 # TESTSDIR.
19 #
20 # If 'auto', a Kyuafile is automatically generated based on the list of test
21 # programs built by the Makefile and is installed into TESTSDIR.  This is the
22 # default and is sufficient in the majority of the cases.
23 #
24 # If 'no', no Kyuafile is installed.
25 KYUAFILE?= auto
26
27 # Per-test program interface definition.
28 #
29 # The name provided here must match one of the interface names supported by
30 # Kyua as this is later encoded in the Kyuafile test program definitions.
31 #TEST_INTERFACE.<test-program>= interface-name
32
33 # Per-test program metadata properties as a list of key/value pairs.
34 #
35 # All the variables for a particular program are appended to the program's
36 # definition in the Kyuafile.  This feature can be used to avoid having to
37 # explicitly supply a Kyuafile in the source directory, allowing the caller
38 # Makefile to rely on the KYUAFILE=auto behavior defined here.
39 #TEST_METADATA.<test-program>+= key="value"
40
41 # Path to the prefix of the installed Kyua CLI, if any.
42 #
43 # If kyua is installed from ports, we automatically define a realtest target
44 # below to run the tests using this tool.  The tools are searched for in the
45 # hierarchy specified by this variable.
46 KYUA_PREFIX?= /usr/local
47
48 .if ${KYUAFILE:tl} != "no"
49 FILES+= Kyuafile
50 FILESDIR_Kyuafile= ${TESTSDIR}
51 .endif
52
53 .if ${KYUAFILE:tl} == "auto"
54 CLEANFILES+= Kyuafile Kyuafile.tmp
55 .endif
56
57 .if ${KYUAFILE:tl} == "auto"
58 Kyuafile: Makefile
59         @{ \
60             echo '-- Automatically generated by bsd.test.mk.'; \
61             echo; \
62             echo 'syntax(2)'; \
63             echo; \
64             echo 'test_suite("${TESTSUITE}")'; \
65             echo; \
66         } > ${.TARGET}.tmp
67 .for _T in ${_TESTS}
68 .if defined(.PARSEDIR)
69         @echo '${TEST_INTERFACE.${_T}}_test_program{name="${_T}"${TEST_METADATA.${_T}:C/$/,/:tW:C/^/, /W:C/,$//W}}' \
70             >>${.TARGET}.tmp
71 .else
72         @echo '${TEST_INTERFACE.${_T}}_test_program{name="${_T}"${TEST_METADATA.${_T}:C/^/, /:Q:S/\\ ,/,/g:S,\\,,g}}' \
73             >>Kyuafile.auto.tmp
74 .endif
75 .endfor
76 .for _T in ${TESTS_SUBDIRS:N.WAIT}
77         @echo "include(\"${_T}/${.TARGET}\")" >>${.TARGET}.tmp
78 .endfor
79         @mv ${.TARGET}.tmp ${.TARGET}
80 .endif
81
82 KYUA?= ${KYUA_PREFIX}/bin/kyua
83 .if exists(${KYUA})
84 # Definition of the "make test" target and supporting variables.
85 #
86 # This target, by necessity, can only work for native builds (i.e. a FreeBSD
87 # host building a release for the same system).  The target runs Kyua, which is
88 # not in the toolchain, and the tests execute code built for the target host.
89 #
90 # Due to the dependencies of the binaries built by the source tree and how they
91 # are used by tests, it is highly possible for a execution of "make test" to
92 # report bogus results unless the new binaries are put in place.
93 realtest: .PHONY
94         @echo "*** WARNING: make test is experimental"
95         @echo "***"
96         @echo "*** Using this test does not preclude you from running the tests"
97         @echo "*** installed in ${TESTSBASE}.  This test run may raise false"
98         @echo "*** positives and/or false negatives."
99         @echo
100         @set -e; \
101         ${KYUA} test -k ${DESTDIR}${TESTSDIR}/Kyuafile; \
102         result=0; \
103         echo; \
104         echo "*** Once again, note that "make test" is unsupported."; \
105         test $${result} -eq 0
106 .endif
107
108 beforetest: .PHONY
109 .if defined(TESTSDIR)
110 .if ${TESTSDIR} == ${TESTSBASE}
111 # Forbid running from ${TESTSBASE}.  It can cause false positives/negatives and
112 # it does not cover all the tests (e.g. it misses testing software in external).
113         @echo "*** Sorry, you cannot use make test from src/tests.  Install the"
114         @echo "*** tests into their final location and run them from ${TESTSBASE}"
115         @false
116 .else
117         @echo "*** Using this test does not preclude you from running the tests"
118         @echo "*** installed in ${TESTSBASE}.  This test run may raise false"
119         @echo "*** positives and/or false negatives."
120 .endif
121 .else
122         @echo "*** No TESTSDIR defined; nothing to do."
123         @false
124 .endif
125         @echo