Skip to content

Commit

Permalink
twister: coverage: cleanup how we set gcov tool
Browse files Browse the repository at this point in the history
Make sure we set the gcov tool in a consistent way and avoid issues
where path is set as Path instead of a string.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
  • Loading branch information
nashif authored and fabiobaltieri committed Dec 29, 2023
1 parent c05a483 commit aa44166
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions scripts/pylib/twister/twisterlib/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def _generate(self, outdir, coveragelog):
branch_coverage = "lcov_branch_coverage=1"
ignore_errors = []

cmd = ["lcov", "--gcov-tool", str(self.gcov_tool),
cmd = ["lcov", "--gcov-tool", self.gcov_tool,
"--capture", "--directory", outdir,
"--rc", branch_coverage,
"--output-file", coveragefile]
Expand Down Expand Up @@ -293,7 +293,7 @@ def _generate(self, outdir, coveragelog):
# We want to remove tests/* and tests/ztest/test/* but save tests/ztest
cmd = ["gcovr", "-r", self.base_dir,
"--gcov-ignore-parse-errors=negative_hits.warn_once_per_file",
"--gcov-executable", str(self.gcov_tool),
"--gcov-executable", self.gcov_tool,
"-e", "tests/*"]
cmd += excludes + mode_options + ["--json", "-o", coveragefile, outdir]
cmd_str = " ".join(cmd)
Expand Down Expand Up @@ -333,6 +333,7 @@ def _generate(self, outdir, coveragelog):

def run_coverage(testplan, options):
use_system_gcov = False
gcov_tool = None

for plat in options.coverage_platform:
_plat = testplan.get_platform(plat)
Expand All @@ -353,19 +354,21 @@ def run_coverage(testplan, options):
os.symlink(llvm_cov, gcov_lnk)
except OSError:
shutil.copy(llvm_cov, gcov_lnk)
options.gcov_tool = gcov_lnk
gcov_tool = gcov_lnk
elif use_system_gcov:
options.gcov_tool = "gcov"
gcov_tool = "gcov"
elif os.path.exists(zephyr_sdk_gcov_tool):
options.gcov_tool = zephyr_sdk_gcov_tool
gcov_tool = zephyr_sdk_gcov_tool
else:
logger.error(f"Can't find a suitable gcov tool. Use --gcov-tool or set ZEPHYR_SDK_INSTALL_DIR.")
sys.exit(1)
else:
gcov_tool = str(options.gcov_tool)

logger.info("Generating coverage files...")
logger.info(f"Using gcov tool: {options.gcov_tool}")
logger.info(f"Using gcov tool: {gcov_tool}")
coverage_tool = CoverageTool.factory(options.coverage_tool)
coverage_tool.gcov_tool = str(options.gcov_tool)
coverage_tool.gcov_tool = gcov_tool
coverage_tool.base_dir = os.path.abspath(options.coverage_basedir)
# Apply output format default
if options.coverage_formats is not None:
Expand Down

0 comments on commit aa44166

Please sign in to comment.