coverage.mk 2.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
# Measure code coverage using luacov and gcov
# C and Lua code is measured separately and resutls are combined together
# Define COVERAGE=1 during build *and* test runs to enable measurement.
#
# Beware: Tests are typically run in parallel and neither luacov not gcov
# support that, so we have to store results from each run separatelly
# and combine them.

coverage-c-combine-gcda:
	@# combine trees of gcda files into one info file per tree
11 12
	@mkdir -p '$(COVERAGE_STATSDIR)/tmp.c'
	@LCOV=$(LCOV) ./scripts/coverage_c_combine.sh '$(TOPSRCDIR)' '$(COVERAGE_STATSDIR)' '$(COVERAGE_STATSDIR)/tmp.c'
13 14 15

coverage-c: coverage-c-combine-gcda
	@# combine info files for each tree into resulting c.info file
16 17
	@$(LCOV) -q $(addprefix --add-tracefile ,$(wildcard $(COVERAGE_STATSDIR)/tmp.c/*.info)) --output-file '$(COVERAGE_STAGE).c.info'
	@$(RM) -r '$(COVERAGE_STATSDIR)/tmp.c'
18

19
LUA_STATS_OUT := $(shell find '$(COVERAGE_STATSDIR)' -type f -name 'luacov.stats.out' 2> /dev/null)
20 21 22
LUA_INFOS_OUT := $(patsubst %.stats.out,%.lua.info,$(LUA_STATS_OUT))

coverage-lua-fix-paths: $(LUA_STATS_OUT)
23 24 25
	@# map Lua install paths to source paths
	@$(MAKE) PREFIX=$(PREFIX) install --dry-run --always-make | scripts/map_install_src.lua --sed > .luacov_path_map
	@sed -i -f .luacov_path_map $^
26
	@$(RM) .luacov_path_map
27

28 29
luacov.empty_stats.out:
	@# generate list of all Lua files to fill holes in luacov stats
30
	@$(MAKE) PREFIX=$(PREFIX) install --dry-run --always-make | scripts/map_install_src.lua | cut -f 2 | grep '\.lua$$' | scripts/luacov_gen_empty.sh > luacov.empty_stats.out
31 32 33 34 35 36 37 38 39 40 41

%.lua.info: %.stats.out coverage-lua-fix-paths
	@scripts/luacov_to_info.lua $*.stats.out > $@

coverage-lua: $(LUA_INFOS_OUT) luacov.empty_stats.out
	@echo '# Lua coverage in $(COVERAGE_STAGE).lua.info'
	@# add missing files to luacov stats
	@scripts/luacov_to_info.lua luacov.empty_stats.out > luacov.empty_stats.lua.info
	@# combine info files for each tree into resulting lua.info file
	@$(LCOV) -q $(addprefix --add-tracefile ,$(LUA_INFOS_OUT)) --add-tracefile luacov.empty_stats.lua.info --output-file '$(COVERAGE_STAGE).lua.info'
	@$(RM) luacov.empty_stats.out luacov.empty_stats.lua.info
42 43 44

coverage:
	@$(LCOV) $(addprefix --add-tracefile ,$(wildcard $(COVERAGE_STAGE)*.info)) --output-file coverage.info
45
	@$(GENHTML) --no-function-coverage --no-branch-coverage -q -o coverage -p '$(realpath $(CURDIR))' -t 'Knot Resolver $(VERSION)-$(PLATFORM) coverage report' --legend coverage.info
46 47

coverage-clean:
48
	@$(RM) -rf '$(COVERAGE_STATSDIR)'
49 50 51 52 53 54 55

.PHONY: coverage-c-combine-gcda coverage-c coverage-lua-fix-paths coverage-lua coverage coverage-clean

# Options
ifdef COVERAGE
BUILD_CFLAGS += --coverage
endif