Skip to content

Commit

Permalink
twister: Check lcov exit codes
Browse files Browse the repository at this point in the history
Don't ignore lcov exit codes, but instead log and return if one of the
lcov commands fails.

Signed-off-by: Jeremy Bettis <jbettis@google.com>
  • Loading branch information
jeremybettis committed Feb 6, 2025
1 parent c85b251 commit 565fb1c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions scripts/pylib/twister/twisterlib/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,28 +301,40 @@ def _generate(self, outdir, coveragelog, build_dirs=None):
invalid_chars = re.compile(r"[^A-Za-z0-9_]")
cmd.append("--test-name")
cmd.append(invalid_chars.sub("_", next(iter(self.instances))))
self.run_lcov(cmd, coveragelog)
ret = self.run_lcov(cmd, coveragelog)
if ret:
logger.error("LCOV capture report stage failed with %s", ret)
return ret, {}

# We want to remove tests/* and tests/ztest/test/* but save tests/ztest
cmd = ["--extract", coveragefile,
os.path.join(self.base_dir, "tests", "ztest", "*"),
"--output-file", ztestfile]
self.run_lcov(cmd, coveragelog)
ret = self.run_lcov(cmd, coveragelog)
if ret:
logger.error("LCOV extract report stage failed with %s", ret)
return ret, {}

files = []
if os.path.exists(ztestfile) and os.path.getsize(ztestfile) > 0:
cmd = ["--remove", ztestfile,
os.path.join(self.base_dir, "tests/ztest/test/*"),
"--output-file", ztestfile]
self.run_lcov(cmd, coveragelog)
ret = self.run_lcov(cmd, coveragelog)
if ret:
logger.error("LCOV remove ztest report stage failed with %s", ret)
return ret, {}

files = [coveragefile, ztestfile]
else:
files = [coveragefile]

for i in self.ignores:
cmd = ["--remove", coveragefile, i, "--output-file", coveragefile]
self.run_lcov(cmd, coveragelog)
ret = self.run_lcov(cmd, coveragelog)
if ret:
logger.error("LCOV remove ignores report stage failed with %s", ret)
return ret, {}

if 'html' not in self.output_formats.split(','):
return 0, {}
Expand All @@ -334,6 +346,8 @@ def _generate(self, outdir, coveragelog, build_dirs=None):
cmd.append("--show-details")
cmd += files
ret = self.run_command(cmd, coveragelog)
if ret:
logger.error("LCOV genhtml report stage failed with %s", ret)

# TODO: Add LCOV summary coverage report.
return ret, { 'report': coveragefile, 'ztest': ztestfile, 'summary': None }
Expand Down

0 comments on commit 565fb1c

Please sign in to comment.