diff options
Diffstat (limited to 'BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py')
-rw-r--r-- | BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py b/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py index 31d13b2..91425f1 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
@@ -50,6 +52,12 @@ class HostBasedUnitTestRunner(IUefiBuildPlugin): failure_count = 0
+ # Do not catch exceptions in gtest so they are handled by address sanitizer
+ shell_env.set_shell_var('GTEST_CATCH_EXCEPTIONS', '0')
+
+ # Disable address sanitizer memory leak detection
+ shell_env.set_shell_var('ASAN_OPTIONS', 'detect_leaks=0')
+
# Set up the reporting type for Cmocka.
shell_env.set_shell_var('CMOCKA_MESSAGE_OUTPUT', 'xml')
@@ -143,26 +151,44 @@ 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")
+ # `--ignore-errors mismatch` needed to make lcov v2.0+/gcov work.
+ lcov_error_settings = "--ignore-errors mismatch" if lcov_version_major >= 2 else ""
+ ret = RunCmd("lcov", f"--no-external --capture --initial --directory {buildOutputBase} --output-file {buildOutputBase}/cov-base.info --rc lcov_branch_coverage=1 {lcov_error_settings}")
if ret != 0:
logging.error("UnitTest Coverage: Failed to build initial coverage data.")
return 1
# Coverage data for tested files only
- ret = RunCmd("lcov", f"--capture --directory {buildOutputBase}/ --output-file {buildOutputBase}/coverage-test.info --rc lcov_branch_coverage=1")
+ 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
# Aggregate all coverage data
- ret = RunCmd("lcov", f"--add-tracefile {buildOutputBase}/cov-base.info --add-tracefile {buildOutputBase}/coverage-test.info --output-file {buildOutputBase}/total-coverage.info --rc lcov_branch_coverage=1")
+ ret = RunCmd("lcov", f"--add-tracefile {buildOutputBase}/cov-base.info --add-tracefile {buildOutputBase}/coverage-test.info --output-file {buildOutputBase}/total-coverage.info --rc lcov_branch_coverage=1 {lcov_error_settings}")
if ret != 0:
logging.error("UnitTest Coverage: Failed to aggregate coverage data.")
return 1
@@ -185,7 +211,7 @@ class HostBasedUnitTestRunner(IUefiBuildPlugin): coverageFile = ""
for testCoverage in testCoverageList:
coverageFile += " --add-tracefile " + testCoverage
- ret = RunCmd("lcov", f"{coverageFile} --output-file {workspace}/Build/all-coverage.info --rc lcov_branch_coverage=1")
+ ret = RunCmd("lcov", f"{coverageFile} --output-file {workspace}/Build/all-coverage.info --rc lcov_branch_coverage=1 {lcov_error_settings}")
if ret != 0:
logging.error("UnitTest Coverage: Failed generate all coverage file.")
return 1
|