xref: /freebsd/sys/contrib/openzfs/tests/unit/Makefile.am (revision d9497217456002b0ddad3cd319570d0b098daa29)
1# SPDX-License-Identifier: CDDL-1.0
2
3# libunit.la includes munit and any additional tools that apply to all tests
4libunit_la_CFLAGS = $(AM_CFLAGS)
5
6noinst_LTLIBRARIES += libunit.la
7libunit_la_SOURCES = \
8	%D%/mock_dmu.c \
9	%D%/mock_dmu.h \
10	%D%/munit.c \
11	%D%/munit.h \
12	%D%/unit.c \
13	%D%/unit.h
14
15
16# all test binaries
17UNIT_TESTS = \
18	%D%/test_zap
19noinst_PROGRAMS = $(UNIT_TESTS)
20
21
22%C%_test_zap_CFLAGS = $(AM_CFLAGS)
23
24nodist_%C%_test_zap_SOURCES = \
25	module/zfs/zap.c \
26	module/zfs/zap_fat.c \
27	module/zfs/zap_impl.c \
28	module/zfs/zap_micro.c \
29	module/zfs/zap_leaf.c \
30	module/zfs/u8_textprep.c
31
32%C%_test_zap_SOURCES = \
33	%D%/test_zap.c
34
35%C%_test_zap_LDADD = \
36	libspl.la \
37	libbtree.la \
38	libunit.la
39
40
41# test run and coverage targets below
42PHONY += unit unit-coverage unit-coverage-html
43
44_unit_run_%: %D%/%
45	@echo "  UNITTEST $<" ; $< $(TOPT)
46
47# note: any changes in switches to lcov or genhtml must be carefully checked
48#       on 1.x and 2.x; the current option set is carefully chosen to allow
49#       both to work sensibly
50
51# .info is marked PRECIOUS, because its usually only created as an intermediate
52# from one of the unit phony targets, but once it exists there's no point
53# remaking it until and unless the test binary itself changes
54.PRECIOUS: %D%/%.info
55%D%/%.info: %D%/%
56	@-${RM} $@
57	@${LCOV} --quiet --quiet --zerocounters --directory $(top_srcdir)
58	@echo "  UNITTEST $<" ; $< $(TOPT)
59	@${LCOV} --quiet --quiet --capture  \
60		--test-name $(notdir $<) \
61		--directory $(top_srcdir) \
62		--output-file $@ \
63		--rc lcov_branch_coverage=1 \
64		--rc geninfo_unexecuted_blocks=1 \
65		$(addprefix --include $(abs_top_builddir)/, $(call \
66		    $(join $(join nodist_%C%_, $(notdir $<)), _SOURCES))) \
67		2>/dev/null
68
69_unit_coverage_%: %D%/%.info
70	@scripts/coverage_report.pl $<
71
72_unit_coverage_html_%: %D%/%.info
73	@-${RM} -r $(subst .info,_coverage, $<)
74	@${GENHTML} --quiet -quiet \
75		--rc lcov_branch_coverage=1 \
76		--rc check_data_consistency=0 \
77		--output-directory $(subst .info,_coverage, $<) \
78		$< \
79		2>/dev/null
80	@echo "coverage results:" \
81		"file://$(realpath %D%)/$(subst .info,_coverage,$(notdir $<))/index.html"
82
83CLEAN_LOCAL += unit-clean-local
84unit-clean-local:
85	-${RM} -r %D%/*.info %D%/*_coverage/
86
87_UNIT_ALL_TARGETS = $(notdir $(UNIT_TESTS))
88_UNIT_FIND_TARGET = \
89	$(foreach cmd, $(UNIT_TESTS), \
90		$(if $(filter $(join test_, $(1)), $(notdir $(cmd))), \
91			$(notdir $(cmd))))
92
93_UNIT_TARGETS = $(if $(T), \
94	$(call _UNIT_FIND_TARGET, $(T)), $(call _UNIT_ALL_TARGETS))
95
96unit: $(addprefix _unit_run_, $(_UNIT_TARGETS))
97	@$(if $^, true, echo "ERROR: couldn't find unit test: $(T)" && false)
98
99if CODE_COVERAGE_ENABLED
100unit-coverage: $(addprefix _unit_coverage_, $(_UNIT_TARGETS))
101	@$(if $^, true, echo "ERROR: couldn't find unit test: $(T)" && false)
102unit-coverage-html: $(addprefix _unit_coverage_html_, $(_UNIT_TARGETS))
103	@$(if $^, true, echo "ERROR: couldn't find unit test: $(T)" && false)
104else
105unit-coverage:
106	@echo "unit test coverage not enabled."
107	@echo "re-run configure with --enable-code-coverage"
108	@false
109unit-coverage-html: unit-coverage
110endif
111