From nobody Sun Feb 8 22:22:24 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+97836+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+97836+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1672658710; cv=none; d=zohomail.com; s=zohoarc; b=GrzB45FJqHbIXs7XFRLePKuuwbNt/URnCyOoUQl1/I+hs7kNQXsgsoF4QoBXWDIGh8MtW7JVgQw3ixuLFt6XonTq+Tlqohbswa8k4iM9SYCABKbSowZVFu1YhHB8pQPNxIu+p36HHZpBaIbeSPtl6C8/xiC/9qDy/WA3+OCoInM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1672658710; 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=C/1ZtrkSa8VudEGi3MyeW6Gay5dbIXXoa6dIbDYSLHk=; b=PBl3sbBxVl4injeXDR4Sr4f1gvHMwIPjvxt44qecDMSwHlvh/y8EkqccU1n1eWux9pABTeXdJYqV0Hq6gI4qt5eakM1ITkUAhAkE32TummOgSagtaVfgIHNBaCsKPyovxvQw8FPOQsjwltlxdU5FYfC4CY0bwZEgD+5W5NalQp0= 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+97836+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 16726587103450.6239543868862256; Mon, 2 Jan 2023 03:25:10 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id JoXQYY1788612xZp4yykkb0E; Mon, 02 Jan 2023 03:25:10 -0800 X-Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web11.33334.1672658709147793323 for ; Mon, 02 Jan 2023 03:25:09 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10577"; a="385903967" X-IronPort-AV: E=Sophos;i="5.96,293,1665471600"; d="scan'208";a="385903967" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jan 2023 03:25:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10577"; a="656454233" X-IronPort-AV: E=Sophos;i="5.96,293,1665471600"; d="scan'208";a="656454233" X-Received: from gguo-desk.gar.corp.intel.com ([10.5.215.23]) by fmsmga007.fm.intel.com with ESMTP; 02 Jan 2023 03:25:07 -0800 From: "Guo, Gua" To: devel@edk2.groups.io Cc: Gua Guo , Michael D Kinney , Sean Brogan , Bret Barkelew , Michael Kubacki Subject: [edk2-devel] [PATCH v8 1/3] UnitTestFrameworkPkg: Add code coverage support for GCC Date: Mon, 2 Jan 2023 19:25:00 +0800 Message-Id: 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: gqRtYYHm1SaAsupZIT9rBhwox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1672658710; bh=FpLwhh4OM2DEg8+T1OkRas2RnJWuDqIk/x977wEbNlk=; h=Cc:Date:From:Reply-To:Subject:To; b=Iax768qBFa9V8i7Dem/vlMk3e8x/ZwpygppaHQX8GE9oQNH5DfPzlihczwHAoqEOpJp +X9cmepgWYPlRbV5a9JEXfUULhcvcuvzMvXYAB4raP+Q+y5F0pTcejhmn1PXzeAG6RxQK VFTbqV5sDEMipEh+FiSf6nPxBGVoTMVJzN0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1672658710828100004 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 | 41 +++++++++++++++++++ .../UnitTestFrameworkPkg.ci.yaml | 1 + .../UnitTestFrameworkPkgHost.dsc.inc | 3 +- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/UnitTestFrameworkPkg/ReadMe.md b/UnitTestFrameworkPkg/ReadMe.md index 9ce04b7f3e..3fa4e1910f 100644 --- a/UnitTestFrameworkPkg/ReadMe.md +++ b/UnitTestFrameworkPkg/ReadMe.md @@ -583,6 +583,47 @@ GTEST_OUTPUT=3Dxml: =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 to parse coverage data to cobertura xml forma= t. + +- 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=3DVS20= 19 -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 b= e 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=3DGCC5= -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: D= isplay Coverage" + ``` + + ### Important Note =20 This works on both Windows and Linux but is currently limited to x64 archi= tectures. Working on getting others, but we diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml b/UnitTestFr= ameworkPkg/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/UnitTe= stFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc index 8009337552..7f5dfa30ed 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc @@ -27,7 +27,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 (#97836): https://edk2.groups.io/g/devel/message/97836 Mute This Topic: https://groups.io/mt/96004851/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-