Skip to content

Commit

Permalink
BaseTools: Coverage: Detect lcov version
Browse files Browse the repository at this point in the history
Detect the version of lcov and only apply
version 2 workaround when needed.

Fixes 61c7142

Signed-off-by: Oliver Steffen <[email protected]>
  • Loading branch information
osteffenrh authored and mergify[bot] committed Dec 5, 2024
1 parent 2940708 commit 47ef197
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
import io
import re
import os
import logging
import glob
Expand Down Expand Up @@ -143,12 +145,28 @@ def do_post_build(self, thebuilder):

return failure_count

def get_lcov_version(self):
"""Get lcov version number"""
lcov_ver = io.StringIO()
ret = RunCmd("lcov", "--version", outstream=lcov_ver)
if ret != 0:
return None
(major, _minor) = re.search(r"version (\d+)\.(\d+)", lcov_ver.getvalue()).groups()
return int(major)


def gen_code_coverage_gcc(self, thebuilder):
logging.info("Generating UnitTest code coverage")

buildOutputBase = thebuilder.env.GetValue("BUILD_OUTPUT_BASE")
workspace = thebuilder.env.GetValue("WORKSPACE")

lcov_version_major = self.get_lcov_version()
if not lcov_version_major:
logging.error("UnitTest Coverage: Failed to determine lcov version")
return 1
logging.info(f"Got lcov version {lcov_version_major}")

# Generate base code coverage for all source files
ret = RunCmd("lcov", f"--no-external --capture --initial --directory {buildOutputBase} --output-file {buildOutputBase}/cov-base.info --rc lcov_branch_coverage=1")
if ret != 0:
Expand All @@ -157,7 +175,8 @@ def gen_code_coverage_gcc(self, thebuilder):

# Coverage data for tested files only
# `--ignore-errors mismatch` needed to make lcov v2.0+/gcov work.
ret = RunCmd("lcov", f"--capture --directory {buildOutputBase}/ --output-file {buildOutputBase}/coverage-test.info --rc lcov_branch_coverage=1 --ignore-errors mismatch")
lcov_error_settings = "--ignore-errors mismatch" if lcov_version_major >= 2 else ""
ret = RunCmd("lcov", f"--capture --directory {buildOutputBase}/ --output-file {buildOutputBase}/coverage-test.info --rc lcov_branch_coverage=1 {lcov_error_settings}")
if ret != 0:
logging.error("UnitTest Coverage: Failed to build coverage data for tested files.")
return 1
Expand Down

0 comments on commit 47ef197

Please sign in to comment.