]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UnitTestFrameworkPkg: Add code coverage support for GCC
authorGua Guo <gua.guo@intel.com>
Tue, 27 Sep 2022 04:24:18 +0000 (12:24 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 4 Jan 2023 02:06:01 +0000 (02:06 +0000)
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>
UnitTestFrameworkPkg/ReadMe.md
UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml
UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc

index 9ce04b7f3eb6f0b34065271bfc9a7057580a806d..3fa4e1910f71683954d314442bdf68cc71184d73 100644 (file)
@@ -583,6 +583,47 @@ GTEST_OUTPUT=xml:<absolute or relative path to output file>
 \r
 This mode is used by the test running plugin to aggregate the results for CI test status reporting in the web view.\r
 \r
+### Code Coverage\r
+\r
+Host based Unit Tests will automatically enable coverage data.\r
+\r
+For Windows, This is primarily leverage for pipeline builds, but this can be leveraged locally using the\r
+OpenCppCoverage windows tool to parse coverage data to cobertura xml format.\r
+\r
+- Windows Prerequisite\r
+  ```bash\r
+  Download and install https://github.com/OpenCppCoverage/OpenCppCoverage/releases\r
+  python -m pip install --upgrade -r ./pip-requirements.txt\r
+  stuart_ci_build -c .pytool/CISettings.py  -t NOOPT TOOL_CHAIN_TAG=VS2019 -p MdeModulePkg\r
+  Open Build/coverage.xml\r
+  ```\r
+\r
+  - How to see code coverage data on IDE Visual Studio\r
+    ```\r
+    Open Visual Studio VS2019 or above version\r
+    Click "Tools" -> "OpenCppCoverage Settings"\r
+    Fill your execute file into "Program to run:"\r
+    Click "Tools" -> "Run OpenCppCoverage"\r
+    ```\r
+\r
+\r
+For Linux, This is primarily leveraged for pipeline builds, but this can be leveraged locally using the\r
+lcov linux tool, and parsed using the lcov_cobertura python tool to parse it to cobertura xml format.\r
+\r
+- Linux Prerequisite\r
+  ```bash\r
+  sudo apt-get install -y lcov\r
+  python -m pip install --upgrade -r ./pip-requirements.txt\r
+  stuart_ci_build -c .pytool/CISettings.py  -t NOOPT TOOL_CHAIN_TAG=GCC5 -p MdeModulePkg\r
+  Open Build/coverage.xml\r
+  ```\r
+  - How to see code coverage data on IDE Visual Studio Code\r
+    ```\r
+    Download plugin "Coverage Gutters"\r
+    Press Hot Key "Ctrl + Shift + P" and click option "Coverage Gutters: Display Coverage"\r
+    ```\r
+\r
+\r
 ### Important Note\r
 \r
 This works on both Windows and Linux but is currently limited to x64 architectures. Working on getting others, but we\r
index 072df6208c926f6ef29a4ae35ce9c78e51ce5cdd..d8f8e024c4764b4bd08bd5ac38db40ec4afd6702 100644 (file)
@@ -91,6 +91,7 @@
             "pytools",\r
             "NOFAILURE",\r
             "cmockery",\r
+            "cobertura",\r
             "DHAVE", # build flag for cmocka in the INF\r
             "gtest", # file name in GoogleTestLib.inf\r
             "corthon",      # Contact GitHub account in Readme\r
index 8009337552cc4205e73b162c265a4997e263b9e8..7f5dfa30ed60461345b7812d6400bce4e7d3d2de 100644 (file)
@@ -27,7 +27,8 @@
   GCC:*_*_*_CC_FLAGS   = -D UNIT_TESTING_DEBUG=1\r
   XCODE:*_*_*_CC_FLAGS = -D UNIT_TESTING_DEBUG=1\r
 !endif\r
-\r
+  GCC:*_GCC5_*_CC_FLAGS = --coverage\r
+  GCC:*_GCC5_*_DLINK_FLAGS = --coverage\r
 [BuildOptions.common.EDKII.HOST_APPLICATION]\r
   #\r
   # MSFT\r