Skip to content

Commit c0813ef

Browse files
JordanYatesjhedberg
authored andcommitted
scripts: twisterlib: coverage: exclude LOG_* branches
Disable the branch coverage calculations on the `LOG_*` family of macros. Branch misses are due to the implementation of `Z_LOG2` and cannot be reasonably covered in library code. The internal paths through the `Z_LOG2` macro are not of interest when inspecting files that happen to use the Zephyr logging API. Signed-off-by: Jordan Yates <[email protected]>
1 parent 37c49f2 commit c0813ef

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

scripts/pylib/twister/twisterlib/coverage.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class Lcov(CoverageTool):
144144
def __init__(self, jobs=None):
145145
super().__init__()
146146
self.ignores = []
147+
self.ignore_branch_patterns = []
147148
self.output_formats = "lcov,html"
148149
self.version = self.get_version()
149150
self.jobs = jobs
@@ -169,6 +170,9 @@ def add_ignore_file(self, pattern):
169170
def add_ignore_directory(self, pattern):
170171
self.ignores.append('*/' + pattern + '/*')
171172

173+
def add_ignore_branch_pattern(self, pattern):
174+
self.ignore_branch_patterns.append(pattern)
175+
172176
@property
173177
def is_lcov_v2(self):
174178
return self.version.startswith("2")
@@ -252,6 +256,7 @@ class Gcovr(CoverageTool):
252256
def __init__(self):
253257
super().__init__()
254258
self.ignores = []
259+
self.ignore_branch_patterns = []
255260
self.output_formats = "html"
256261
self.version = self.get_version()
257262

@@ -278,6 +283,9 @@ def add_ignore_file(self, pattern):
278283
def add_ignore_directory(self, pattern):
279284
self.ignores.append(".*/" + pattern + '/.*')
280285

286+
def add_ignore_branch_pattern(self, pattern):
287+
self.ignore_branch_patterns.append(pattern)
288+
281289
@staticmethod
282290
def _interleave_list(prefix, list):
283291
tuple_list = [(prefix, item) for item in list]
@@ -292,6 +300,7 @@ def _generate(self, outdir, coveragelog):
292300
ztestfile = os.path.join(outdir, "ztest.json")
293301

294302
excludes = Gcovr._interleave_list("-e", self.ignores)
303+
excludes += Gcovr._interleave_list("--exclude-branches-by-pattern", self.ignore_branch_patterns)
295304

296305
# Different ifdef-ed implementations of the same function should not be
297306
# in conflict treated by GCOVR as separate objects for coverage statistics.
@@ -383,5 +392,8 @@ def run_coverage(testplan, options):
383392
coverage_tool.add_ignore_file('generated')
384393
coverage_tool.add_ignore_directory('tests')
385394
coverage_tool.add_ignore_directory('samples')
395+
# Ignore branch coverage on LOG_* and LOG_HEXDUMP_* macros
396+
# Branch misses are due to the implementation of Z_LOG2 and cannot be avoided
397+
coverage_tool.add_ignore_branch_pattern(r"^\s*LOG_(?:HEXDUMP_)?(?:DBG|INF|WRN|ERR)\(.*")
386398
coverage_completed = coverage_tool.generate(options.outdir)
387399
return coverage_completed

0 commit comments

Comments
 (0)