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 <jbettis@google.com>
This commit is contained in:
Jeremy Bettis 2025-02-05 16:53:46 -07:00 committed by Benjamin Cabé
commit b544e0a2b3

View file

@ -279,7 +279,24 @@ class Lcov(CoverageTool):
coveragefile = os.path.join(outdir, "coverage.info") coveragefile = os.path.join(outdir, "coverage.info")
ztestfile = os.path.join(outdir, "ztest.info") ztestfile = os.path.join(outdir, "ztest.info")
cmd = ["--capture", "--directory", outdir, "--output-file", coveragefile] if build_dirs:
files = []
for dir_ in build_dirs:
files_ = [fname for fname in
[os.path.join(dir_, "coverage.info"),
os.path.join(dir_, "ztest.info")]
if os.path.exists(fname)]
if not files_:
logger.debug("Coverage merge no files in: %s", dir_)
continue
files += files_
logger.debug("Coverage merge %d reports in %s", len(files), outdir)
cmd = ["--output-file", coveragefile]
for filename in files:
cmd.append("--add-tracefile")
cmd.append(filename)
else:
cmd = ["--capture", "--directory", outdir, "--output-file", coveragefile]
self.run_lcov(cmd, coveragelog) self.run_lcov(cmd, coveragelog)
# We want to remove tests/* and tests/ztest/test/* but save tests/ztest # We want to remove tests/* and tests/ztest/test/* but save tests/ztest