From: "Guo, Gua" <gua.guo@intel.com>
To: devel@edk2.groups.io
Cc: Gua Guo <gua.guo@intel.com>,
Michael D Kinney <michael.d.kinney@intel.com>,
Sean Brogan <sean.brogan@microsoft.com>,
Bret Barkelew <Bret.Barkelew@microsoft.com>,
Michael Kubacki <mikuback@linux.microsoft.com>
Subject: [PATCH v6 1/3] UnitTestFrameworkPkg: Add code coverage support for GCC
Date: Wed, 14 Dec 2022 11:19:43 +0800 [thread overview]
Message-ID: <ca5910e9f48b625cbf5c7e0e086cd3a9429d7224.1670987652.git.gua.guo@intel.com> (raw)
In-Reply-To: <cover.1670987652.git.gua.guo@intel.com>
From: Gua Guo <gua.guo@intel.com>
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.
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Michael Kubacki <mikuback@linux.microsoft.com>
Signed-off-by: Gua Guo <gua.guo@intel.com>
---
UnitTestFrameworkPkg/ReadMe.md | 45 ++++++++++++++++++-
.../UnitTestFrameworkPkg.ci.yaml | 1 +
.../UnitTestFrameworkPkgHost.dsc.inc | 3 +-
3 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/UnitTestFrameworkPkg/ReadMe.md b/UnitTestFrameworkPkg/ReadMe.md
index 9ce04b7f3e..5987385c06 100644
--- a/UnitTestFrameworkPkg/ReadMe.md
+++ b/UnitTestFrameworkPkg/ReadMe.md
@@ -115,7 +115,7 @@ you should be good to go.
See this example in 'SampleUnitTestUefiShell.inf'...
-```
+```inf
[Packages]
MdePkg/MdePkg.dec
@@ -130,7 +130,7 @@ See this example in 'SampleUnitTestUefiShell.inf'...
Also, if you want you test to automatically be picked up by the Test Runner plugin, you will need
to make sure that the module `BASE_NAME` contains the word `Test`...
-```
+```inf
[Defines]
BASE_NAME = SampleUnitTestUefiShell
```
@@ -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
--
2.31.1.windows.1
next prev parent reply other threads:[~2022-12-14 3:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-14 3:19 [PATCH v6 0/3] Add code coverage support for GCC/MSVC Guo, Gua
2022-12-14 3:19 ` Guo, Gua [this message]
2022-12-14 3:19 ` [PATCH v6 2/3] BaseTools/Plugin: Add coverage support for Unit Test Guo, Gua
2022-12-14 3:19 ` [PATCH v6 3/3] .azurepipelines: Install code coverage tool Guo, Gua
2022-12-20 21:23 ` Michael D Kinney
2022-12-21 1:32 ` Guo, Gua
2022-12-21 3:11 ` [edk2-devel] " Michael Kubacki
2022-12-21 4:20 ` Guo, Gua
2022-12-21 4:29 ` Michael Kubacki
2022-12-21 6:19 ` Guo, Gua
2022-12-21 3:17 ` Michael D Kinney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ca5910e9f48b625cbf5c7e0e086cd3a9429d7224.1670987652.git.gua.guo@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox