Skip to content

Commit b544e0a

Browse files
jeremybettiskartben
authored andcommitted
twister: Implement coverage file merging for lcov
Instead of capturing the coverage data twice with --coverage-per-instance, just merge the lcov files in the aggregation report. Signed-off-by: Jeremy Bettis <[email protected]>
1 parent 6c7d518 commit b544e0a

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

scripts/pylib/twister/twisterlib/coverage.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,24 @@ def _generate(self, outdir, coveragelog, build_dirs=None):
279279
coveragefile = os.path.join(outdir, "coverage.info")
280280
ztestfile = os.path.join(outdir, "ztest.info")
281281

282-
cmd = ["--capture", "--directory", outdir, "--output-file", coveragefile]
282+
if build_dirs:
283+
files = []
284+
for dir_ in build_dirs:
285+
files_ = [fname for fname in
286+
[os.path.join(dir_, "coverage.info"),
287+
os.path.join(dir_, "ztest.info")]
288+
if os.path.exists(fname)]
289+
if not files_:
290+
logger.debug("Coverage merge no files in: %s", dir_)
291+
continue
292+
files += files_
293+
logger.debug("Coverage merge %d reports in %s", len(files), outdir)
294+
cmd = ["--output-file", coveragefile]
295+
for filename in files:
296+
cmd.append("--add-tracefile")
297+
cmd.append(filename)
298+
else:
299+
cmd = ["--capture", "--directory", outdir, "--output-file", coveragefile]
283300
self.run_lcov(cmd, coveragelog)
284301

285302
# We want to remove tests/* and tests/ztest/test/* but save tests/ztest

0 commit comments

Comments
 (0)