diff options
author | Oliver Steffen <osteffen@redhat.com> | 2024-12-04 12:10:53 +0100 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2024-12-05 00:05:47 +0000 |
commit | 47ef19787356e003042d6f37d3853b9a47cb5d9e (patch) | |
tree | 06e9bee543033ba7f05495ed00fe0cd436a893b7 /BaseTools | |
parent | 2940708eb27a6b6f6c1adc1510fbd85a9055b447 (diff) | |
download | edk2-47ef19787356e003042d6f37d3853b9a47cb5d9e.tar.gz |
BaseTools: Coverage: Detect lcov version
Detect the version of lcov and only apply
version 2 workaround when needed.
Fixes 61c714285f8c
Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Diffstat (limited to 'BaseTools')
-rw-r--r-- | BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py b/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py index 9fb8a19c6d..b7ed863203 100644 --- a/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py +++ b/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py @@ -5,6 +5,8 @@ # SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
+import io
+import re
import os
import logging
import glob
@@ -143,12 +145,28 @@ class HostBasedUnitTestRunner(IUefiBuildPlugin): 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:
@@ -157,7 +175,8 @@ class HostBasedUnitTestRunner(IUefiBuildPlugin): # 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
|