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 v3 1/2] UnitTestFrameworkPkg: Add code coverage support for GCC
Date: Thu, 22 Sep 2022 15:09:04 +0800 [thread overview]
Message-ID: <3a060305c0eaf9a996043795744c4ada4f83914b.1663830230.git.gua.guo@intel.com> (raw)
In-Reply-To: <cover.1663830230.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 | 42 +++++++++++++++++--
.../UnitTestFrameworkPkg.ci.yaml | 2 +
.../UnitTestFrameworkPkgHost.dsc.inc | 3 +-
3 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/UnitTestFrameworkPkg/ReadMe.md b/UnitTestFrameworkPkg/ReadMe.md
index e696412cb3..3c69cfdd97 100644
--- a/UnitTestFrameworkPkg/ReadMe.md
+++ b/UnitTestFrameworkPkg/ReadMe.md
@@ -60,7 +60,7 @@ you should be good to go.
See this example in 'SampleUnitTestUefiShell.inf'...
-```
+```inf
[Packages]
MdePkg/MdePkg.dec
@@ -75,7 +75,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
```
@@ -361,7 +361,7 @@ RUNNING TEST SUITE: Int Safe Conversions Test Suite
```
You can also, if you are so inclined, read the output from the exact instance of the test that was run during
-`stuart_ci_build`. The ouput file can be found on a path that looks like:
+`stuart_ci_build`. The output file can be found on a path that looks like:
`Build/<Package>/HostTest/<Arch>/<TestName>.<TestSuiteName>.<Arch>.result.xml`
@@ -399,6 +399,42 @@ CMOCKA_XML_FILE=<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 i enable coverage data.
+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. pycobertura is used to
+covert this coverage data to a human readable HTML file. These tools must be installed
+to parse code coverage.
+
+- Windows Prerequisite
+ ```bash
+ Download and install https://github.com/OpenCppCoverage/OpenCppCoverage/tags
+ pip install pycobertura
+ ```
+
+- Linux Prerequisite
+ ```bash
+ sudo apt-get install -y lcov
+ pip install lcov_cobertura
+ pip install pycobertura
+ ```
+
+During CI builds, use the ```CODE_COVERAGE=TRUE``` flag to generate the code coverage XML files,
+and additionally use the ```CC_HTML=TRUE``` flag to generate the HTML file. This will be generated
+in Build/coverage.html.
+
+There is currently no official guidance or support for code coverage when compiling
+in Visual Studio at this time.
+During CI builds, use the ```CODE_COVERAGE=TRUE``` flag to generate the code coverage XML files,
+and additionally use the ```CC_HTML=TRUE``` flag to generate the HTML file. This will be generated
+in Build/coverage.html.
+
+Example
+```bash
+ stuart_ci_build -c .pytool/CISettings.py -t NOOPT TOOL_CHAIN_TAG=VS2019 -p MdeModulePkg CC_HTML=TRUE CODE_COVERAGE=TRUE
+ ```
+
### 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 77d51e1348..f68882e1cf 100644
--- a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml
+++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml
@@ -90,6 +90,8 @@
"pytools",
"NOFAILURE",
"cmockery",
+ "cobertura",
+ "pycobertura",
"DHAVE", # build flag for cmocka in the INF
"corthon", # Contact GitHub account in Readme
"mdkinney", # Contact GitHub account in Readme
diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
index 4dd8d4ac67..ca46b8513a 100644
--- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
+++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
@@ -25,7 +25,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-09-22 7:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-22 7:09 [PATCH v3 0/2] UnitTestFrameworkPkg: Add code coverage support for GCC Guo, Gua
2022-09-22 7:09 ` Guo, Gua [this message]
2022-09-22 7:09 ` [PATCH v3 2/2] BaseTools/Plugin: Add coverage support for Unit Test Guo, Gua
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=3a060305c0eaf9a996043795744c4ada4f83914b.1663830230.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