From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.92.18.90]) by mx.groups.io with SMTP id smtpd.web09.1165.1663118254519420264 for ; Tue, 13 Sep 2022 18:17:34 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@outlook.com header.s=selector1 header.b=cPJkAOP8; spf=pass (domain: outlook.com, ip: 40.92.18.90, mailfrom: spbrogan@outlook.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V1Zbe7y9xJpmdIT2z96Px/3Fzb6SCYVbSUlgklUXh1KvRZSqxLO79vDPKRMLXFwHZ2w1EMlN5mAIOGybfSt+srBP6bRLCAD91GAJqUlhD4NOV2LOWGAbO/8eEyb0xVbXr//9bKjPAGGVvxX+/0ZUzIVb8ZNxiSBY1JC6BS9m9qXyq/IiGsMA+WouFHQWXmitMhhQ1yz7f0FfmTZyA4ltLborw8d3qj40h72GSQw4Sh4Rf5k8ghxSD1OImYRZr8dLn8IhZYgrZOi8/z5YkfWUWzTkJgs1zu0Xu2cmb4Dg0fpIu+hSlKNHQVvezMv3jxVN+jOChjfNoGZ2jTy41Vad6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Atct/LEMVBFndVt+OPSN6g5RhVYEN7Z4/It87gUcY4w=; b=iJrNoZA7r6SdVnnSNXeSuilILAwoo1MvnLcBPKYk/h9YqeT3FXN2tCDD6DNc7Wh9irbBPYT98Nz+RT7jRjR70vLCPiSbioHM4eO7zZU9aVrSATE9qj/UKYZ7/kACO/8xLHXmku5bNwI/DNO04GDhfvQvm5M/2wszVVK3GmDKqvUzQm48/OdOmgclBiyKEFe0NTqqWVK+2yRFp0V+bC3PuqowQ6Y8l597NDWb0DMK5PiwtBaTsX+llWmeoX1NK7Myx37R1j4DmCok2fwqrs+YX48vSehJeGOYdCWmBphAjVwrwZEPVEbG7S7nzVctQLvaqQ7uKXcX1UXad4BzVTYisg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Atct/LEMVBFndVt+OPSN6g5RhVYEN7Z4/It87gUcY4w=; b=cPJkAOP8ZvnB9QXQJTd4jXC1utGVg+JTgEU7u5dxDfh0DRBkcsA9Fp9ufCqyhxF0i9KK5UWBksgoVx91j8vGyrhJYXg0Alawc5WyrmPsg7v4iWYOeqKdsc6F3B7GFonKB26c+HqFcMb2S3i7VUVXD7K2bjLMgVeuJCVhtq8sTSmf3PAVTZhVjt96qEvA9g981qqso/1TgWbkkkGXY8oKCxSaJa2tK/rQ0+st31Pyjo/Io0UPKbxr+8t7cF0GYMUBp+1wpo0O16Ou3G5+06Va8aBV1hHPkucE7SlJJHXvw+P6cjCgzNpDOLYO1/jdW6V8MBdspj/IuSO1ww39lxvqCQ== Received: from BY3PR19MB4900.namprd19.prod.outlook.com (2603:10b6:a03:354::11) by PH0PR19MB5396.namprd19.prod.outlook.com (2603:10b6:510:fa::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.22; Wed, 14 Sep 2022 01:17:32 +0000 Received: from BY3PR19MB4900.namprd19.prod.outlook.com ([fe80::5db6:2c20:44c4:42bc]) by BY3PR19MB4900.namprd19.prod.outlook.com ([fe80::5db6:2c20:44c4:42bc%2]) with mapi id 15.20.5612.022; Wed, 14 Sep 2022 01:17:32 +0000 Message-ID: Date: Tue, 13 Sep 2022 18:17:30 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [edk2-devel] [PATCH v2] UnitTestFrameworkPkg: Add code coverage support for GCC To: devel@edk2.groups.io, gua.guo@intel.com Cc: Michael D Kinney , Sean Brogan , Michael Kubacki References: <20220914010118.1643-1-gua.guo@intel.com> From: "Sean" In-Reply-To: <20220914010118.1643-1-gua.guo@intel.com> X-TMN: [ijvQ245Y2XhRt6A527j4kd8NdGwcTtVq] X-ClientProxiedBy: MW4PR03CA0293.namprd03.prod.outlook.com (2603:10b6:303:b5::28) To BY3PR19MB4900.namprd19.prod.outlook.com (2603:10b6:a03:354::11) Return-Path: spbrogan@outlook.com X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY3PR19MB4900:EE_|PH0PR19MB5396:EE_ X-MS-Office365-Filtering-Correlation-Id: 931b502d-59c8-49cb-7e0b-08da95eee5db X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gbX//O6+GFk30bW84hco3pNJwN1/Zi+p6HYCHjPl3M5pjG3xe+fB5hNdWwELmKvE7/MItnR0ilzyJlexkO7e3dGKaHQnaA3gDIAsf0/50sSgX4k4j16WuYQukxj3YXJ5/Hzzyqge4ItJlQ/CEvhSfYIqqC6vLGuMe4bjaUPxUr3X4+WszZVpuMTkxCC0F/hruKvdmpURkLWScExorXPyfm6ad/V1aNyThRQFNkuaDhVgYzFevSnRD2Fc/lYMVPPDPJQVh422ZzBt3TEqg4uA8p8W6Yu/0zs5wNDDwhBxjPytNTD4OPW3l5pdjymp/uZIKbgXzOGQJUcjNn7wn3C/2C2rWfvvgFdFLA9u35VwLoKHwi+lXHXVQw3mb9NWzD2O+FZjxxHJNLokzVVbyBb7+K5Pt7i9aJ47ha6kX5ckYwLppyZb70sBHtJgwMkr5UZT+Fcm+GnsgPXG6PPNKX0GnG+6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ObWZlVEFSUTdJWVg5a0pKTVVReDVIWUNQdGRXS1Jw?= =?utf-8?B?OXU5ZzRseC90UEU3K0FvSzIwY0lIVVN0SkdLV2RXNjlQN1FzaVZQVlZ2QWJH?= =?utf-8?B?VzNNa0JpMWp2aW9uSThMSXhORVhCSlpkZytEWmM2THZXRnoyVHFtNmErRCt3?= =?utf-8?B?WHRFSjVCS1o3RFpPNlkyNGxRanNwa2p1S2kzUThmQ2FOME5oMXZZU0lRPT0=?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 931b502d-59c8-49cb-7e0b-08da95eee5db X-MS-Exchange-CrossTenant-AuthSource: BY3PR19MB4900.namprd19.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Sep 2022 01:17:32.2167 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR19MB5396 Content-Type: multipart/alternative; boundary="------------spe7acU3XwkhF2cx0A8FATe3" Content-Language: en-US --------------spe7acU3XwkhF2cx0A8FATe3 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Gua Guo, I would propose that we make this easier for both the local user and the CI system to get coverage metrics. Can you review this commit as it uses the same Edk2 plugins but adds code coverage support with GCC5: Merged PR 5008: Initial implementation or code coverage on basecore u… · microsoft/mu_basecore@f6af51f (github.com) Thanks Sean On 9/13/2022 6:01 PM, Guo, Gua wrote: > From: Gua Guo > > 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 > Cc: Sean Brogan > Cc: Bret Barkelew > Cc: Michael Kubacki > Signed-off-by: Gua Guo > --- > UnitTestFrameworkPkg/ReadMe.md | 116 +++++++++++++++++++- > UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc | 2 +- > 2 files changed, 116 insertions(+), 2 deletions(-) > > diff --git a/UnitTestFrameworkPkg/ReadMe.md b/UnitTestFrameworkPkg/ReadMe.md > index e696412cb3..93fdacfc4a 100644 > --- a/UnitTestFrameworkPkg/ReadMe.md > +++ b/UnitTestFrameworkPkg/ReadMe.md > @@ -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//HostTest//...result.xml` > > > > @@ -399,6 +399,120 @@ CMOCKA_XML_FILE= > > > This mode is used by the test running plugin to aggregate the results for CI test status reporting in the web view. > > > > +### Enable Code Coverage for GCC host-based tests > > + > > +LCOV is an extension of GCOV, a GNU tool which provides information about what parts of a program are actually executed (i.e. "covered") while running a particular test case. The extension consists of a set of scripts which build on the textual GCOV output to implement it. > > + > > +Documentation for LCOV can be found here: > > +https://lcov.readthedocs.io/ > > + > > +You can follow below steps to generate your code coverage report. > > + > > + > > + > > +```bash > > +user@linux_machine:~/_uefi$stuart_ci_build -c .pytool/CISettings.py TOOL_CHAIN_TAG=GCC5 -p MdePkg -t NOOPT > > +... > > +user@linux_machine:~/_uefi$lcov -c --rc lcov_branch_coverage=1 -o UnitTest.info -d Build/MdePkg/HostTest/NOOPT_GCC5/X64/MdePkg/ > > +Capturing coverage data from Build/MdePkg/HostTest/NOOPT_GCC5/X64/MdePkg/ > > +Found gcov version: 9.4.0 > > +Using intermediate gcov format > > +Scanning Build/MdePkg/HostTest/NOOPT_GCC5/X64/MdePkg/ for .gcda files ... > > +Found 38 data files in Build/MdePkg/HostTest/NOOPT_GCC5/X64/MdePkg/ > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/RShiftU64.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/Math64.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/SafeString.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/SwapBytes32.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/CpuDeadLoop.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/MultU64x64.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/LongJump.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/SetJump.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/BitField.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/String.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/DivU64x32Remainder.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/X64/GccInline.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/MultU64x32.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/MultS64x64.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/LinkedList.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/LShiftU64.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/DivU64x32.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/SwapBytes16.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/Unaligned.gcda > > +Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/CheckSum.gcda > > +Processing Library/BaseMemoryLib/BaseMemoryLib/OUTPUT/CopyMem.gcda > > +Processing Library/BaseMemoryLib/BaseMemoryLib/OUTPUT/MemLibGuid.gcda > > +Processing Library/BaseMemoryLib/BaseMemoryLib/OUTPUT/CompareMemWrapper.gcda > > +Processing Library/BaseMemoryLib/BaseMemoryLib/OUTPUT/SetMemWrapper.gcda > > +Processing Library/BaseMemoryLib/BaseMemoryLib/OUTPUT/SetMem64Wrapper.gcda > > +Processing Library/BaseMemoryLib/BaseMemoryLib/OUTPUT/MemLibGeneric.gcda > > +Processing Library/BaseMemoryLib/BaseMemoryLib/OUTPUT/CopyMemWrapper.gcda > > +Processing Library/BaseMemoryLib/BaseMemoryLib/OUTPUT/SetMem.gcda > > +Processing Library/BaseMemoryLib/BaseMemoryLib/OUTPUT/ZeroMemWrapper.gcda > > +Processing Library/BasePrintLib/BasePrintLib/OUTPUT/PrintLibInternal.gcda > > +Processing Library/BasePrintLib/BasePrintLib/OUTPUT/PrintLib.gcda > > +Processing Library/BaseSafeIntLib/BaseSafeIntLib/OUTPUT/SafeIntLib64.gcda > > +Processing Library/BaseSafeIntLib/BaseSafeIntLib/OUTPUT/SafeIntLib.gcda > > +Processing Test/UnitTest/Library/BaseLib/BaseLibUnitTestsHost/OUTPUT/Base64UnitTest.gcda > > +Processing Test/UnitTest/Library/BaseLib/BaseLibUnitTestsHost/OUTPUT/AutoGen.gcda > > +Processing Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLibHost/OUTPUT/SafeIntLibUintnIntnUnitTests64.gcda > > +Processing Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLibHost/OUTPUT/TestBaseSafeIntLib.gcda > > +Processing Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLibHost/OUTPUT/AutoGen.gcda > > + > > +user@linux_machine:~/_uefi$genhtml UnitTest.info --branch-coverage -o Build/UnitTestReport > > + > > +Reading data file UnitTest.info > > +Found 38 entries. > > +Found common filename prefix "~/_uefi/MdePkg/Library" > > +Writing .css and .png files. > > +Generating output. > > +Processing file ~/_uefi/Build/MdePkg/HostTest/NOOPT_GCC5/X64/MdePkg/Test/UnitTest/Library/BaseLib/BaseLibUnitTestsHost/DEBUG/AutoGen.c > > +Processing file ~/_uefi/Build/MdePkg/HostTest/NOOPT_GCC5/X64/MdePkg/Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLibHost/DEBUG/AutoGen.c > > +Processing file BaseLib/Unaligned.c > > +Processing file BaseLib/CheckSum.c > > +Processing file BaseLib/BitField.c > > +Processing file BaseLib/DivU64x32.c > > +Processing file BaseLib/CpuDeadLoop.c > > +Processing file BaseLib/LongJump.c > > +Processing file BaseLib/MultU64x64.c > > +Processing file BaseLib/RShiftU64.c > > +Processing file BaseLib/SwapBytes32.c > > +Processing file BaseLib/SwapBytes16.c > > +Processing file BaseLib/SetJump.c > > +Processing file BaseLib/LinkedList.c > > +Processing file BaseLib/LShiftU64.c > > +Processing file BaseLib/SafeString.c > > +Processing file BaseLib/String.c > > +Processing file BaseLib/DivU64x32Remainder.c > > +Processing file BaseLib/MultS64x64.c > > +Processing file BaseLib/MultU64x32.c > > +Processing file BaseLib/Math64.c > > +Processing file BaseLib/X64/GccInline.c > > +Processing file BaseMemoryLib/SetMemWrapper.c > > +Processing file BaseMemoryLib/CompareMemWrapper.c > > +Processing file BaseMemoryLib/SetMem64Wrapper.c > > +Processing file BaseMemoryLib/ZeroMemWrapper.c > > +Processing file BaseMemoryLib/CopyMemWrapper.c > > +Processing file BaseMemoryLib/CopyMem.c > > +Processing file BaseMemoryLib/SetMem.c > > +Processing file BaseMemoryLib/MemLibGuid.c > > +Processing file BaseMemoryLib/MemLibGeneric.c > > +Processing file BasePrintLib/PrintLib.c > > +Processing file BasePrintLib/PrintLibInternal.c > > +Processing file BaseSafeIntLib/SafeIntLib64.c > > +Processing file BaseSafeIntLib/SafeIntLib.c > > +Processing file ~/_uefi/MdePkg/Test/UnitTest/Library/BaseLib/Base64UnitTest.c > > +Processing file ~/_uefi/MdePkg/Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c > > +Processing file ~/_uefi/MdePkg/Test/UnitTest/Library/BaseSafeIntLib/SafeIntLibUintnIntnUnitTests64.c > > +Writing directory view page. > > +Overall coverage rate: > > + lines......: 58.6% (2688 of 4589 lines) > > + functions..: 57.1% (249 of 436 functions) > > + branches...: 25.3% (1062 of 4195 branches) > > + > > +... > > + > > +``` > > + > > ### 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/UnitTestFrameworkPkgHost.dsc.inc b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc > index 4dd8d4ac67..8623aecb33 100644 > --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc > +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc > @@ -19,7 +19,7 @@ > MemoryAllocationLib|UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.inf > > > > [BuildOptions] > > - GCC:*_*_*_CC_FLAGS = -fno-pie > > + GCC:*_*_*_CC_FLAGS = -fno-pie -ftest-coverage -fprofile-arcs > > !ifdef $(UNIT_TESTING_DEBUG) > > MSFT:*_*_*_CC_FLAGS = -D UNIT_TESTING_DEBUG=1 > > GCC:*_*_*_CC_FLAGS = -D UNIT_TESTING_DEBUG=1 > --------------spe7acU3XwkhF2cx0A8FATe3 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Hi Gua Guo,

I would propose that we make this easier for both the local user and the CI system to get coverage metrics. 

Can you review this commit as it uses the same Edk2 plugins but adds code coverage support with GCC5:

Merged PR 5008: Initial implementation or code coverage on basecore u… · microsoft/mu_basecore@f6af51f (github.com)


Thanks

Sean


 

On 9/13/2022 6:01 PM, Guo, Gua wrote:
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                        | 116 +++++++++++++++++++-
 UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc |   2 +-
 2 files changed, 116 insertions(+), 2 deletions(-)

diff --git a/UnitTestFrameworkPkg/ReadMe.md b/UnitTestFrameworkPkg/ReadMe.md
index e696412cb3..93fdacfc4a 100644
--- a/UnitTestFrameworkPkg/ReadMe.md
+++ b/UnitTestFrameworkPkg/ReadMe.md
@@ -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,120 @@ 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.

 

+### Enable Code Coverage for GCC host-based tests

+

+LCOV is an extension of GCOV, a GNU tool which provides information about what parts of a program are actually executed (i.e. "covered") while running a particular test case. The extension consists of a set of scripts which build on the textual GCOV output to implement it.

+

+Documentation for LCOV can be found here:

+https://lcov.readthedocs.io/

+

+You can follow below steps to generate your code coverage report.

+

+

+

+```bash

+user@linux_machine:~/_uefi$stuart_ci_build -c .pytool/CISettings.py TOOL_CHAIN_TAG=GCC5 -p MdePkg -t NOOPT

+...

+user@linux_machine:~/_uefi$lcov -c --rc lcov_branch_coverage=1 -o UnitTest.info -d Build/MdePkg/HostTest/NOOPT_GCC5/X64/MdePkg/

+Capturing coverage data from Build/MdePkg/HostTest/NOOPT_GCC5/X64/MdePkg/

+Found gcov version: 9.4.0

+Using intermediate gcov format

+Scanning Build/MdePkg/HostTest/NOOPT_GCC5/X64/MdePkg/ for .gcda files ...

+Found 38 data files in Build/MdePkg/HostTest/NOOPT_GCC5/X64/MdePkg/

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/RShiftU64.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/Math64.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/SafeString.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/SwapBytes32.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/CpuDeadLoop.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/MultU64x64.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/LongJump.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/SetJump.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/BitField.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/String.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/DivU64x32Remainder.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/X64/GccInline.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/MultU64x32.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/MultS64x64.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/LinkedList.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/LShiftU64.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/DivU64x32.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/SwapBytes16.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/Unaligned.gcda

+Processing Library/BaseLib/UnitTestHostBaseLib/OUTPUT/CheckSum.gcda

+Processing Library/BaseMemoryLib/BaseMemoryLib/OUTPUT/CopyMem.gcda

+Processing Library/BaseMemoryLib/BaseMemoryLib/OUTPUT/MemLibGuid.gcda

+Processing Library/BaseMemoryLib/BaseMemoryLib/OUTPUT/CompareMemWrapper.gcda

+Processing Library/BaseMemoryLib/BaseMemoryLib/OUTPUT/SetMemWrapper.gcda

+Processing Library/BaseMemoryLib/BaseMemoryLib/OUTPUT/SetMem64Wrapper.gcda

+Processing Library/BaseMemoryLib/BaseMemoryLib/OUTPUT/MemLibGeneric.gcda

+Processing Library/BaseMemoryLib/BaseMemoryLib/OUTPUT/CopyMemWrapper.gcda

+Processing Library/BaseMemoryLib/BaseMemoryLib/OUTPUT/SetMem.gcda

+Processing Library/BaseMemoryLib/BaseMemoryLib/OUTPUT/ZeroMemWrapper.gcda

+Processing Library/BasePrintLib/BasePrintLib/OUTPUT/PrintLibInternal.gcda

+Processing Library/BasePrintLib/BasePrintLib/OUTPUT/PrintLib.gcda

+Processing Library/BaseSafeIntLib/BaseSafeIntLib/OUTPUT/SafeIntLib64.gcda

+Processing Library/BaseSafeIntLib/BaseSafeIntLib/OUTPUT/SafeIntLib.gcda

+Processing Test/UnitTest/Library/BaseLib/BaseLibUnitTestsHost/OUTPUT/Base64UnitTest.gcda

+Processing Test/UnitTest/Library/BaseLib/BaseLibUnitTestsHost/OUTPUT/AutoGen.gcda

+Processing Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLibHost/OUTPUT/SafeIntLibUintnIntnUnitTests64.gcda

+Processing Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLibHost/OUTPUT/TestBaseSafeIntLib.gcda

+Processing Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLibHost/OUTPUT/AutoGen.gcda

+

+user@linux_machine:~/_uefi$genhtml UnitTest.info --branch-coverage -o Build/UnitTestReport

+

+Reading data file UnitTest.info

+Found 38 entries.

+Found common filename prefix "~/_uefi/MdePkg/Library"

+Writing .css and .png files.

+Generating output.

+Processing file ~/_uefi/Build/MdePkg/HostTest/NOOPT_GCC5/X64/MdePkg/Test/UnitTest/Library/BaseLib/BaseLibUnitTestsHost/DEBUG/AutoGen.c

+Processing file ~/_uefi/Build/MdePkg/HostTest/NOOPT_GCC5/X64/MdePkg/Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLibHost/DEBUG/AutoGen.c

+Processing file BaseLib/Unaligned.c

+Processing file BaseLib/CheckSum.c

+Processing file BaseLib/BitField.c

+Processing file BaseLib/DivU64x32.c

+Processing file BaseLib/CpuDeadLoop.c

+Processing file BaseLib/LongJump.c

+Processing file BaseLib/MultU64x64.c

+Processing file BaseLib/RShiftU64.c

+Processing file BaseLib/SwapBytes32.c

+Processing file BaseLib/SwapBytes16.c

+Processing file BaseLib/SetJump.c

+Processing file BaseLib/LinkedList.c

+Processing file BaseLib/LShiftU64.c

+Processing file BaseLib/SafeString.c

+Processing file BaseLib/String.c

+Processing file BaseLib/DivU64x32Remainder.c

+Processing file BaseLib/MultS64x64.c

+Processing file BaseLib/MultU64x32.c

+Processing file BaseLib/Math64.c

+Processing file BaseLib/X64/GccInline.c

+Processing file BaseMemoryLib/SetMemWrapper.c

+Processing file BaseMemoryLib/CompareMemWrapper.c

+Processing file BaseMemoryLib/SetMem64Wrapper.c

+Processing file BaseMemoryLib/ZeroMemWrapper.c

+Processing file BaseMemoryLib/CopyMemWrapper.c

+Processing file BaseMemoryLib/CopyMem.c

+Processing file BaseMemoryLib/SetMem.c

+Processing file BaseMemoryLib/MemLibGuid.c

+Processing file BaseMemoryLib/MemLibGeneric.c

+Processing file BasePrintLib/PrintLib.c

+Processing file BasePrintLib/PrintLibInternal.c

+Processing file BaseSafeIntLib/SafeIntLib64.c

+Processing file BaseSafeIntLib/SafeIntLib.c

+Processing file ~/_uefi/MdePkg/Test/UnitTest/Library/BaseLib/Base64UnitTest.c

+Processing file ~/_uefi/MdePkg/Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c

+Processing file ~/_uefi/MdePkg/Test/UnitTest/Library/BaseSafeIntLib/SafeIntLibUintnIntnUnitTests64.c

+Writing directory view page.

+Overall coverage rate:

+  lines......: 58.6% (2688 of 4589 lines)

+  functions..: 57.1% (249 of 436 functions)

+  branches...: 25.3% (1062 of 4195 branches)

+

+...

+

+```

+

 ### 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/UnitTestFrameworkPkgHost.dsc.inc b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
index 4dd8d4ac67..8623aecb33 100644
--- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
+++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
@@ -19,7 +19,7 @@
   MemoryAllocationLib|UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.inf

 

 [BuildOptions]

-  GCC:*_*_*_CC_FLAGS = -fno-pie

+  GCC:*_*_*_CC_FLAGS = -fno-pie -ftest-coverage -fprofile-arcs

 !ifdef $(UNIT_TESTING_DEBUG)

   MSFT:*_*_*_CC_FLAGS  = -D UNIT_TESTING_DEBUG=1

   GCC:*_*_*_CC_FLAGS   = -D UNIT_TESTING_DEBUG=1

--------------spe7acU3XwkhF2cx0A8FATe3--