diff options
author | Gua Guo <gua.guo@intel.com> | 2022-09-27 12:24:18 +0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2023-01-04 02:06:01 +0000 |
commit | 3701f105fadad2bed438ababe4dfb41eda478cc4 (patch) | |
tree | 4cc1be50cd06f81a5d8f75e2f614e18aa69f877c /UnitTestFrameworkPkg | |
parent | b670700ddf5eb1dd958d60eb4f2a51e0636206f9 (diff) | |
download | edk2-3701f105fadad2bed438ababe4dfb41eda478cc4.tar.gz edk2-3701f105fadad2bed438ababe4dfb41eda478cc4.tar.bz2 edk2-3701f105fadad2bed438ababe4dfb41eda478cc4.zip |
UnitTestFrameworkPkg: Add code coverage support for GCC
In order to collect code coverage after running executable
file, generate *.gcda and *.gcno file that require by lcov tool
to generate code coverage report.
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Reviewed-by: Michael Kubacki <mikuback@linux.microsoft.com>
Signed-off-by: Gua Guo <gua.guo@intel.com>
Diffstat (limited to 'UnitTestFrameworkPkg')
-rw-r--r-- | UnitTestFrameworkPkg/ReadMe.md | 41 | ||||
-rw-r--r-- | UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml | 1 | ||||
-rw-r--r-- | UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc | 3 |
3 files changed, 44 insertions, 1 deletions
diff --git a/UnitTestFrameworkPkg/ReadMe.md b/UnitTestFrameworkPkg/ReadMe.md index 9ce04b7f3e..3fa4e1910f 100644 --- a/UnitTestFrameworkPkg/ReadMe.md +++ b/UnitTestFrameworkPkg/ReadMe.md @@ -583,6 +583,47 @@ GTEST_OUTPUT=xml:<absolute or relative path to output file> This mode is used by the test running plugin to aggregate the results for CI test status reporting in the web view.
+### Code Coverage
+
+Host based Unit Tests will automatically enable coverage data.
+
+For Windows, This is primarily leverage for pipeline builds, but this can be leveraged locally using the
+OpenCppCoverage windows tool to parse coverage data to cobertura xml format.
+
+- Windows Prerequisite
+ ```bash
+ Download and install https://github.com/OpenCppCoverage/OpenCppCoverage/releases
+ python -m pip install --upgrade -r ./pip-requirements.txt
+ stuart_ci_build -c .pytool/CISettings.py -t NOOPT TOOL_CHAIN_TAG=VS2019 -p MdeModulePkg
+ Open Build/coverage.xml
+ ```
+
+ - How to see code coverage data on IDE Visual Studio
+ ```
+ Open Visual Studio VS2019 or above version
+ Click "Tools" -> "OpenCppCoverage Settings"
+ Fill your execute file into "Program to run:"
+ Click "Tools" -> "Run OpenCppCoverage"
+ ```
+
+
+For Linux, This is primarily leveraged for pipeline builds, but this can be leveraged locally using the
+lcov linux tool, and parsed using the lcov_cobertura python tool to parse it to cobertura xml format.
+
+- Linux Prerequisite
+ ```bash
+ sudo apt-get install -y lcov
+ python -m pip install --upgrade -r ./pip-requirements.txt
+ stuart_ci_build -c .pytool/CISettings.py -t NOOPT TOOL_CHAIN_TAG=GCC5 -p MdeModulePkg
+ Open Build/coverage.xml
+ ```
+ - How to see code coverage data on IDE Visual Studio Code
+ ```
+ Download plugin "Coverage Gutters"
+ Press Hot Key "Ctrl + Shift + P" and click option "Coverage Gutters: Display Coverage"
+ ```
+
+
### Important Note
This works on both Windows and Linux but is currently limited to x64 architectures. Working on getting others, but we
diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml b/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml index 072df6208c..d8f8e024c4 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml @@ -91,6 +91,7 @@ "pytools",
"NOFAILURE",
"cmockery",
+ "cobertura",
"DHAVE", # build flag for cmocka in the INF
"gtest", # file name in GoogleTestLib.inf
"corthon", # Contact GitHub account in Readme
diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc index 8009337552..7f5dfa30ed 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc @@ -27,7 +27,8 @@ GCC:*_*_*_CC_FLAGS = -D UNIT_TESTING_DEBUG=1
XCODE:*_*_*_CC_FLAGS = -D UNIT_TESTING_DEBUG=1
!endif
-
+ GCC:*_GCC5_*_CC_FLAGS = --coverage
+ GCC:*_GCC5_*_DLINK_FLAGS = --coverage
[BuildOptions.common.EDKII.HOST_APPLICATION]
#
# MSFT
|