xref: /freebsd/share/mk/atf.test.mk (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
1# $FreeBSD$
2#
3# You must include bsd.test.mk instead of this file from your Makefile.
4#
5# Logic to build and install ATF test programs; i.e. test programs linked
6# against the ATF libraries.
7
8.if !target(__<bsd.test.mk>__)
9.error atf.test.mk cannot be included directly.
10.endif
11
12# List of C, C++ and shell test programs to build.
13#
14# Programs listed here are built using PROGS, PROGS_CXX and SCRIPTS,
15# respectively, from bsd.prog.mk.  However, the build rules are tweaked to
16# require the ATF libraries.
17#
18# Test programs registered in this manner are set to be installed into TESTSDIR
19# (which should be overridden by the Makefile) and are not required to provide a
20# manpage.
21ATF_TESTS_C?=
22ATF_TESTS_CXX?=
23ATF_TESTS_SH?=
24ATF_TESTS_KSH93?=
25ATF_TESTS_PYTEST?=
26
27.if !empty(ATF_TESTS_C)
28PROGS+= ${ATF_TESTS_C}
29_TESTS+= ${ATF_TESTS_C}
30.for _T in ${ATF_TESTS_C}
31BINDIR.${_T}= ${TESTSDIR}
32MAN.${_T}?= # empty
33SRCS.${_T}?= ${_T}.c
34DPADD.${_T}+= ${LIBATF_C}
35.if empty(LDFLAGS:M-static) && empty(LDFLAGS.${_T}:M-static)
36LDADD.${_T}+= ${LDADD_atf_c}
37.else
38LDADD.${_T}+= ${LIBATF_C}
39.endif
40TEST_INTERFACE.${_T}= atf
41.endfor
42.endif
43
44.if !empty(ATF_TESTS_CXX)
45PROGS_CXX+= ${ATF_TESTS_CXX}
46_TESTS+= ${ATF_TESTS_CXX}
47.for _T in ${ATF_TESTS_CXX}
48BINDIR.${_T}= ${TESTSDIR}
49MAN.${_T}?= # empty
50SRCS.${_T}?= ${_T}${CXX_SUFFIX:U.cc}
51DPADD.${_T}+= ${LIBATF_CXX} ${LIBATF_C}
52.if empty(LDFLAGS:M-static) && empty(LDFLAGS.${_T}:M-static)
53LDADD.${_T}+= ${LDADD_atf_cxx} ${LDADD_atf_c}
54.else
55LDADD.${_T}+= ${LIBATF_CXX} ${LIBATF_C}
56.endif
57TEST_INTERFACE.${_T}= atf
58.endfor
59# Silence warnings about usage of deprecated std::auto_ptr
60CXXWARNFLAGS+=	-Wno-deprecated-declarations
61.endif
62
63.if !empty(ATF_TESTS_SH)
64SCRIPTS+= ${ATF_TESTS_SH}
65_TESTS+= ${ATF_TESTS_SH}
66.for _T in ${ATF_TESTS_SH}
67SCRIPTSDIR_${_T}= ${TESTSDIR}
68TEST_INTERFACE.${_T}= atf
69CLEANFILES+= ${_T} ${_T}.tmp
70# TODO(jmmv): It seems to me that this SED and SRC functionality should
71# exist in bsd.prog.mk along the support for SCRIPTS.  Move it there if
72# this proves to be useful within the tests.
73ATF_TESTS_SH_SED_${_T}?= # empty
74ATF_TESTS_SH_SRC_${_T}?= ${_T}.sh
75${_T}: ${ATF_TESTS_SH_SRC_${_T}}
76	echo '#! /usr/libexec/atf-sh' > ${.TARGET}.tmp
77.if empty(ATF_TESTS_SH_SED_${_T})
78	cat ${.ALLSRC:N*Makefile*} >>${.TARGET}.tmp
79.else
80	cat ${.ALLSRC:N*Makefile*} \
81	    | sed ${ATF_TESTS_SH_SED_${_T}} >>${.TARGET}.tmp
82.endif
83	chmod +x ${.TARGET}.tmp
84	mv ${.TARGET}.tmp ${.TARGET}
85.endfor
86.endif
87
88.if !empty(ATF_TESTS_KSH93)
89SCRIPTS+= ${ATF_TESTS_KSH93}
90_TESTS+= ${ATF_TESTS_KSH93}
91.for _T in ${ATF_TESTS_KSH93}
92SCRIPTSDIR_${_T}= ${TESTSDIR}
93TEST_INTERFACE.${_T}= atf
94TEST_METADATA.${_T}+= required_programs="ksh93"
95CLEANFILES+= ${_T} ${_T}.tmp
96# TODO(jmmv): It seems to me that this SED and SRC functionality should
97# exist in bsd.prog.mk along the support for SCRIPTS.  Move it there if
98# this proves to be useful within the tests.
99ATF_TESTS_KSH93_SED_${_T}?= # empty
100ATF_TESTS_KSH93_SRC_${_T}?= ${_T}.sh
101${_T}: ${ATF_TESTS_KSH93_SRC_${_T}}
102	echo '#! /usr/libexec/atf-sh -s/usr/local/bin/ksh93' > ${.TARGET}.tmp
103.if empty(ATF_TESTS_KSH93_SED_${_T})
104	cat ${.ALLSRC:N*Makefile*} >>${.TARGET}.tmp
105.else
106	cat ${.ALLSRC:N*Makefile*} \
107	    | sed ${ATF_TESTS_KSH93_SED_${_T}} >>${.TARGET}.tmp
108.endif
109	chmod +x ${.TARGET}.tmp
110	mv ${.TARGET}.tmp ${.TARGET}
111.endfor
112.endif
113
114.if !empty(ATF_TESTS_PYTEST)
115# bsd.prog.mk SCRIPTS interface removes file extension unless
116# SCRIPTSNAME is set, which is not possible to do here.
117# Workaround this by appending another extension (.xtmp) to the
118# file name. Use separate loop to avoid dealing with explicitly
119# stating expansion for each and every variable.
120#
121# ATF_TESTS_PYTEST -> contains list of files as is (test_something.py ..)
122# _ATF_TESTS_PYTEST -> (test_something.py.xtmp ..)
123#
124# Former array is iterated to construct Kyuafile, where original file
125#  names need to be written.
126# Latter array is iterated to enable bsd.prog.mk scripts framework -
127#  namely, installing scripts without .xtmp prefix. Note: this allows to
128#  not bother about the fact that make target needs to be different from
129#  the source file.
130_TESTS+= ${ATF_TESTS_PYTEST}
131_ATF_TESTS_PYTEST=
132.for _T in ${ATF_TESTS_PYTEST}
133_ATF_TESTS_PYTEST += ${_T}.xtmp
134TEST_INTERFACE.${_T}= atf
135TEST_METADATA.${_T}+= required_programs="pytest"
136.endfor
137
138SCRIPTS+= ${_ATF_TESTS_PYTEST}
139.for _T in ${_ATF_TESTS_PYTEST}
140SCRIPTSDIR_${_T}= ${TESTSDIR}
141CLEANFILES+= ${_T} ${_T}.tmp
142# TODO(jmmv): It seems to me that this SED and SRC functionality should
143# exist in bsd.prog.mk along the support for SCRIPTS.  Move it there if
144# this proves to be useful within the tests.
145ATF_TESTS_PYTEST_SED_${_T}?= # empty
146ATF_TESTS_PYTEST_SRC_${_T}?= ${.CURDIR}/${_T:S,.xtmp$,,}
147${_T}:
148	echo "#! /usr/libexec/atf_pytest_wrapper -P ${TESTSBASE}" > ${.TARGET}.tmp
149.if empty(ATF_TESTS_PYTEST_SED_${_T})
150	cat ${ATF_TESTS_PYTEST_SRC_${_T}}  >>${.TARGET}.tmp
151.else
152	cat ${ATF_TESTS_PYTEST_SRC_${_T}} \
153	    | sed ${ATF_TESTS_PYTEST_SED_${_T}} >>${.TARGET}.tmp
154.endif
155	chmod +x ${.TARGET}.tmp
156	mv ${.TARGET}.tmp ${.TARGET}
157.endfor
158.endif
159