From nobody Wed Dec 17 07:28:28 2025 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+97832+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+97832+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1672658289; cv=none; d=zohomail.com; s=zohoarc; b=W/rz3sdSwWaGMWfIScKyh/G6VzS4ku0qCvnG8I5awMG1VFiI3frHvJX+x56HoyTyajX1MCcl5ZXJGKKMVjyC1fCvx7sARz2SqBohTYKyRGYAND7cdAh3r+0zgK6ZjeCHxxYYHpW/gwzgSYE7EkMf9dcLqeyv9A6nvljeROYa8Z4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1672658289; 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=0ieu4Cjz4U1Qh+TlC83zCX5+UuYoBhj1hVDW5zXKnYE=; b=GpMQmmZbFox5tqpyoau8ls9jLpO2Eyrhr1oXtOky2mhjof0hzo/a20FvDiRLtF7Ka3MFqsldulQXCowG7A8L/9lUwyaW7i0Eg1v0MWXLgcW8YjfI8VgLL+AEy8Gb1VJGuahD/tdMQmBbYwhpV/P2Gb5hKUfg+aAweoSOaXzDaqo= 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+97832+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 1672658289776870.2277279259367; Mon, 2 Jan 2023 03:18:09 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id m1WHYY1788612xRCCyVmUKsE; Mon, 02 Jan 2023 03:18:09 -0800 X-Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web11.33235.1672658287716569998 for ; Mon, 02 Jan 2023 03:18:09 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10577"; a="407727630" X-IronPort-AV: E=Sophos;i="5.96,293,1665471600"; d="scan'208";a="407727630" X-Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jan 2023 03:18:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10577"; a="654471748" X-IronPort-AV: E=Sophos;i="5.96,293,1665471600"; d="scan'208";a="654471748" X-Received: from gguo-desk.gar.corp.intel.com ([10.5.215.23]) by orsmga002.jf.intel.com with ESMTP; 02 Jan 2023 03:18: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 v7 1/3] UnitTestFrameworkPkg: Add code coverage support for GCC Date: Mon, 2 Jan 2023 19:18: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: Z9idloDJQQuauYKAkEOMWenix1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1672658289; bh=NMPY0ELe6VeZFAgdNKxXrkaDumeM8k8Rm2huoO6UPIQ=; h=Cc:Date:From:Reply-To:Subject:To; b=ZrQBQqn9P7hlNERJL4FpA5Y9/I2RpgcoKACPky+rtCJQBeXVBGGrfRTWRLV1iKDBzP7 xdV14jhTpdXfm6EG2eubwkblsP+6IgjxdjLIxLbXVtc5blKQrY/41cCJIo0Eka4rQXItR nBKxwjjYM7tz25PEk8fEl6GMsU2f0dCVZhE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1672658290625100002 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 (#97832): https://edk2.groups.io/g/devel/message/97832 Mute This Topic: https://groups.io/mt/96004771/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-