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