Repository navigation
Expand file tree
/
Copy pathcoverage-report.mk
More file actions
76 lines (69 loc) · 3.93 KB
/
Copy pathcoverage-report.mk
File metadata and controls
76 lines (69 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright(c) 2026 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
# Dir holding this file, i.e. the repository root. Captured before the include
# below appends to MAKEFILE_LIST.
COV_MK_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
include $(COV_MK_DIR)/coverage.mk
# Only what this directory built: a sibling component's leftover .gcda would
# otherwise be captured here too and inflate the report.
COV_CAPTURE ?= $(CURDIR)
# Repo root, so genhtml shows repo-relative paths for sources kept elsewhere.
COV_ROOT ?= $(COV_MK_DIR)
# Under CURDIR, not COV_ROOT: CI collects <dir>/build/coverage from the same
# directory it ran `make coverage` in.
COV_PATH ?= $(CURDIR)/build/coverage
COV_BASE := $(COV_PATH)/baseline.info
COV_RUN := $(COV_PATH)/run.info
COV_MERGED := $(COV_PATH)/merged.info
COV_FILTERED := $(COV_PATH)/filtered.info
# What to build instrumented. A repository root aggregates packaging targets
# that have nothing to do with the measurement, so it overrides this.
COV_GOALS ?= all
# Directories owning unit tests, discovered rather than listed: a component
# keeps its `test` target next to the sources it covers. Only tracked files
# count -- a build drops third-party trees into the workspace (DCAP's sgxssl)
# carrying a `test` target of their own that drives real SGX hardware.
# /dev/null stops grep reading stdin when the file list comes back empty.
# Lazily expanded, so a component including this file never pays for the grep.
UT_FOUND = $(sort $(patsubst %/Makefile,%,$(shell cd $(COV_ROOT) && \
git ls-files -z '*Makefile' | xargs -0 grep -lE '^test:' /dev/null)))
# The root Makefile matches the grep and would recurse forever. Submodules carry
# their own CI, and the index leaves their contents out anyway.
UT_KEPT = $(filter-out Makefile external/%,$(UT_FOUND))
# An aggregator only forwards `test` downwards; running it as well would execute
# the same tests twice.
UT_DIRS = $(foreach d,$(UT_KEPT),$(if $(filter $(d)/%,$(UT_KEPT)),,$(d)))
# A submodule is a separate repository reporting its own rate; a build drags its
# sources in, but they do not belong to this component's measurement.
COV_SUBMODULES = $(shell cd $(COV_ROOT) && git config -f .gitmodules \
--get-regexp '^submodule\..*\.path$$' 2>/dev/null | awk '{print $$2}')
COV_SUB_GLOBS = $(foreach p,$(COV_SUBMODULES),'$(COV_ROOT)/$(p)/*')
.PHONY: coverage
coverage:
@command -v $(LCOV) >/dev/null || { echo "lcov not found; install lcov"; exit 1; }
@command -v $(GENHTML) >/dev/null || { echo "genhtml not found; install lcov"; exit 1; }
# From scratch: objects built without the flags would silently contribute no
# counters, and a cmake-driven component caches its flags between runs.
$(MAKE) clean
$(MAKE) COVERAGE=1 $(COV_GOALS)
$(MAKE) COVERAGE=1 test
@mkdir -p $(COV_PATH)
# --initial is what puts the sources no test links into the denominator; they
# would otherwise vanish from the report instead of counting as uncovered.
$(LCOV) $(LCOV_RC) $(LCOV_IGN) --capture --initial \
--directory $(COV_CAPTURE) --output-file $(COV_BASE)
$(LCOV) $(LCOV_RC) $(LCOV_IGN) --capture \
--directory $(COV_CAPTURE) --output-file $(COV_RUN)
$(LCOV) $(LCOV_RC) $(LCOV_IGN) --add-tracefile $(COV_BASE) \
--add-tracefile $(COV_RUN) --output-file $(COV_MERGED)
# external/ is anchored at the repository root: DCAP is checked out under an
# external/ directory of its own, and an unanchored pattern would drop it whole.
$(LCOV) $(LCOV_RC) $(LCOV_IGN) --remove $(COV_MERGED) \
'*/test/*' '*/Test/*' '*/tests/*' '$(COV_ROOT)/external/*' '*/gtest/*' '*/gmock/*' \
'/usr/*' '*_u.c' '*_t.c' '*.pb.cc' '*/CMakeFiles/*' $(COV_SUB_GLOBS) \
--output-file $(COV_FILTERED)
$(GENHTML) $(LCOV_RC) $(LCOV_IGN) --branch-coverage --legend --demangle-cpp \
--prefix $(COV_ROOT) --output-directory $(COV_PATH)/html $(COV_FILTERED)
@echo
@$(LCOV) $(LCOV_RC) $(LCOV_IGN) --summary $(COV_FILTERED)
@echo "HTML report: $(COV_PATH)/html/index.html"