From nobody Mon Feb 9 01:01:45 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+94551+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+94551+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1664502962; cv=none; d=zohomail.com; s=zohoarc; b=F9llmnPeEPQ1Rnuf/uz7w9sjaLd1DstbNKHf4bNqTp10hLn1kKIk/tjB+Rd5YSrCKyxjRo2j8ZXWp9JzkJeWvA6rlki4HknnRAzAq3PHlPJchWqFQAul0NRaSbO1wOPsDyMu3zUm4+g+aqrjf/E4BN/0/C1k2uSkOEw8K70KhkQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664502962; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=xBiH/V2320pPwg+lsh96Ghbcsbs060EV/8jgvhZAU9k=; b=WnLE2qFNKLhgDDvFobdsVj+4C1PfHEUzrutepG81xvY+7dGQOGFQDd5wW6jgF6PpYqk4L+CrkaYz4uIdI9ZPOFYoh08sx/DTZ+/UgOJSobdRQaxmC/d2OP8JxcYZhe/QyYFG63kEbKAh0gI3BOqmJmYCdRBoOsDF2ED6WVC+mr0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+94551+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1664502962973603.5512187711305; Thu, 29 Sep 2022 18:56:02 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id EOYFYY1788612xD3zXcxFiE8; Thu, 29 Sep 2022 18:56:01 -0700 X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.1156.1664502959898933557 for ; Thu, 29 Sep 2022 18:56:01 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="281788289" X-IronPort-AV: E=Sophos;i="5.93,357,1654585200"; d="scan'208";a="281788289" X-Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2022 18:56:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="726671306" X-IronPort-AV: E=Sophos;i="5.93,357,1654585200"; d="scan'208";a="726671306" X-Received: from gguo-desk.gar.corp.intel.com ([10.5.215.23]) by fmsmga002.fm.intel.com with ESMTP; 29 Sep 2022 18:55:59 -0700 From: "Guo, Gua" To: devel@edk2.groups.io Cc: Gua Guo , Michael D Kinney , Sean Brogan , Bret Barkelew , Michael Kubacki Subject: [edk2-devel] [PATCH v5 1/3] UnitTestFrameworkPkg: Add code coverage support for GCC Date: Fri, 30 Sep 2022 09:55:54 +0800 Message-Id: <3e761ca731604e3eb08664309a2c16a56c5e472f.1664502910.git.gua.guo@intel.com> In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gua.guo@intel.com X-Gm-Message-State: gewx8qjx8XYlhLLPYHACBoVhx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1664502961; bh=DWMzncA++4ImDk33SwC7ZmMTKtMpgE0pseOBoK3oFqc=; h=Cc:Date:From:Reply-To:Subject:To; b=TtGWCSFNMRGPjTGY4Nt2Yi3vMo8tORt2iulV2vYru7DRm4ctmbVM/b3I3r720aF0/+e AxCJwqcLF3sQF5QIHnkZjXC3OF5Gx1Kwsy2uiz5m9tawP6BHEG2p3gYfTlHJVGGHpktLI Qk3UdyFNylfmIz70iRlvo8p15rvIGi5fVBQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1664502963264100005 Content-Type: text/plain; charset="utf-8" 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 | 37 +++++++++++++++++-- .../UnitTestFrameworkPkg.ci.yaml | 2 + .../UnitTestFrameworkPkgHost.dsc.inc | 3 +- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/UnitTestFrameworkPkg/ReadMe.md b/UnitTestFrameworkPkg/ReadMe.md index e696412cb3..c00e2411f8 100644 --- a/UnitTestFrameworkPkg/ReadMe.md +++ b/UnitTestFrameworkPkg/ReadMe.md @@ -60,7 +60,7 @@ you should be good to go. =20 See this example in 'SampleUnitTestUefiShell.inf'... =20 -``` +```inf [Packages] MdePkg/MdePkg.dec =20 @@ -75,7 +75,7 @@ See this example in 'SampleUnitTestUefiShell.inf'... Also, if you want you test to automatically be picked up by the Test Runne= r plugin, you will need to make sure that the module `BASE_NAME` contains the word `Test`... =20 -``` +```inf [Defines] BASE_NAME =3D SampleUnitTestUefiShell ``` @@ -361,7 +361,7 @@ RUNNING TEST SUITE: Int Safe Conversions Test Suite ``` =20 You can also, if you are so inclined, read the output from the exact insta= nce 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: =20 `Build//HostTest//...result.= xml` =20 @@ -399,6 +399,37 @@ CMOCKA_XML_FILE=3D =20 This mode is used by the test running plugin to aggregate the results for = CI test status reporting in the web view. =20 +### 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, and pycobertura is used to covert this cover= age 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 + python -m pip install --upgrade -r ./pip-requirements.txt + stuart_ci_build -c .pytool/CISettings.py -t NOOPT TOOL_CHAIN_TAG=3DVS20= 19 -p MdeModulePkg + Open Build/coverage.html + ``` + + +For Linux, This is primarily leveraged for pipeline builds, but this can b= e leveraged locally using the +lcov linux tool, and parsed using the lcov_cobertura python tool. pycobert= ura is used to +covert this coverage data to a human readable HTML file. These tools must = be installed +to parse code coverage. + +- 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=3DGCC5= -p MdeModulePkg + Open Build/coverage.html + ``` + + ### Important Note =20 This works on both Windows and Linux, but is currently limited to x64 arch= itectures. Working on getting others, but we diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml b/UnitTestFr= ameworkPkg/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/UnitTe= stFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc index 4dd8d4ac67..ca46b8513a 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc @@ -25,7 +25,8 @@ GCC:*_*_*_CC_FLAGS =3D -D UNIT_TESTING_DEBUG=3D1 XCODE:*_*_*_CC_FLAGS =3D -D UNIT_TESTING_DEBUG=3D1 !endif - + GCC:*_GCC5_*_CC_FLAGS =3D --coverage + GCC:*_GCC5_*_DLINK_FLAGS =3D --coverage [BuildOptions.common.EDKII.HOST_APPLICATION] # # MSFT --=20 2.31.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#94551): https://edk2.groups.io/g/devel/message/94551 Mute This Topic: https://groups.io/mt/94008742/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-