Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect test names in lcov reports #84106

Merged
merged 4 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions scripts/pylib/twister/twisterlib/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,37 +279,75 @@ def _generate(self, outdir, coveragelog, build_dirs=None):
coveragefile = os.path.join(outdir, "coverage.info")
ztestfile = os.path.join(outdir, "ztest.info")

cmd = ["--capture", "--directory", outdir, "--output-file", coveragefile]
self.run_lcov(cmd, coveragelog)
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]
if self.coverage_per_instance and len(self.instances) == 1:
invalid_chars = re.compile(r"[^A-Za-z0-9_]")
cmd.append("--test-name")
cmd.append(invalid_chars.sub("_", next(iter(self.instances))))
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)
jeremybettis marked this conversation as resolved.
Show resolved Hide resolved
return ret, {}

if 'html' not in self.output_formats.split(','):
return 0, {}

cmd = ["genhtml", "--legend", "--branch-coverage",
"--prefix", self.base_dir,
"-output-directory", os.path.join(outdir, "coverage")] + files
"-output-directory", os.path.join(outdir, "coverage")]
if self.coverage_per_instance:
cmd.append("--show-details")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps genhtml also needs --description-file generated with a summary for test names and descriptions to show it in the report.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the tests have descriptions?

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
4 changes: 2 additions & 2 deletions scripts/pylib/twister/twisterlib/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ def add_parse_arguments(parser = None) -> argparse.ArgumentParser:
action="store_true", default=False,
help="""Don't aggregate coverage report statistics for all the test suites
selected to run with enabled coverage. Requires another reporting mode to be
active (`--coverage-split`) to have at least one of these reporting modes.
Default: %(default)s""")
active (`--coverage-per-instance`) to have at least one of these reporting
modes. Default: %(default)s""")

parser.add_argument(
"--test-config",
Expand Down
Loading