From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web10.94050.1670987992757650940 for ; Tue, 13 Dec 2022 19:19:53 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=oI4lGpGO; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: gua.guo@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670987993; x=1702523993; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=z9Gcxn6yDNtCfzk1qj/b9jrmPCcLe/8crEuaremVKno=; b=oI4lGpGO/10ymAdXAXBTrB9qQZ0RKbz0wALK5iYYZBL8dvAwa1fkJ7CP e2iSb+2hV9SXS+Z7PZB89Ddsizqv/Lj9uimxQOPwu8QAeYQHCJ52Y4cQk 35oDCQZbH5Ko7XNqFhXjuMyU5QgC7yQPfQtG+oiyoQSYoRINP5JruZlBP qGOHQI102x2vAw6msI3Q7qHp1rQU4WErq5eM1Co4oz2cbmFGJxi4BJHeN AvGmWDR895FhDzPflSlxNNY35p4iZG+JdfI+IfltveUketfvaZrnAh5fi 4KTz64aSvZjIDqtfUKJpkOg0c4FJXVkP8gJuch6Mt2DDgHALWtZ46jy3p Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10560"; a="318342285" X-IronPort-AV: E=Sophos;i="5.96,243,1665471600"; d="scan'208";a="318342285" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2022 19:19:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10560"; a="823110066" X-IronPort-AV: E=Sophos;i="5.96,243,1665471600"; d="scan'208";a="823110066" Received: from gguo-desk.gar.corp.intel.com ([10.5.215.23]) by orsmga005.jf.intel.com with ESMTP; 13 Dec 2022 19:19:50 -0800 From: "Guo, Gua" To: devel@edk2.groups.io Cc: Gua Guo , Michael D Kinney , Sean Brogan , Bret Barkelew , Michael Kubacki Subject: [PATCH v6 1/3] UnitTestFrameworkPkg: Add code coverage support for GCC Date: Wed, 14 Dec 2022 11:19:43 +0800 Message-Id: X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 | 45 ++++++++++++++++++- .../UnitTestFrameworkPkg.ci.yaml | 1 + .../UnitTestFrameworkPkgHost.dsc.inc | 3 +- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/UnitTestFrameworkPkg/ReadMe.md b/UnitTestFrameworkPkg/ReadMe.md index 9ce04b7f3e..5987385c06 100644 --- a/UnitTestFrameworkPkg/ReadMe.md +++ b/UnitTestFrameworkPkg/ReadMe.md @@ -115,7 +115,7 @@ you should be good to go. =0D See this example in 'SampleUnitTestUefiShell.inf'...=0D =0D -```=0D +```inf=0D [Packages]=0D MdePkg/MdePkg.dec=0D =0D @@ -130,7 +130,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=0D to make sure that the module `BASE_NAME` contains the word `Test`...=0D =0D -```=0D +```inf=0D [Defines]=0D BASE_NAME =3D SampleUnitTestUefiShell=0D ```=0D @@ -583,6 +583,47 @@ GTEST_OUTPUT=3Dxml: =0D This mode is used by the test running plugin to aggregate the results for = CI test status reporting in the web view.=0D =0D +### Code Coverage=0D +=0D +Host based Unit Tests will automatically enable coverage data.=0D +=0D +For Windows, This is primarily leverage for pipeline builds, but this can = be leveraged locally using the=0D +OpenCppCoverage windows tool to parse coverage data to cobertura xml forma= t.=0D +=0D +- Windows Prerequisite=0D + ```bash=0D + Download and install https://github.com/OpenCppCoverage/OpenCppCoverage/= releases=0D + python -m pip install --upgrade -r ./pip-requirements.txt=0D + stuart_ci_build -c .pytool/CISettings.py -t NOOPT TOOL_CHAIN_TAG=3DVS20= 19 -p MdeModulePkg=0D + Open Build/coverage.xml=0D + ```=0D +=0D + - How to see code coverage data on IDE Visual Studio=0D + ```=0D + Open Visual Studio VS2019 or above version=0D + Click "Tools" -> "OpenCppCoverage Settings"=0D + Fill your execute file into "Program to run:"=0D + Click "Tools" -> "Run OpenCppCoverage"=0D + ```=0D +=0D +=0D +For Linux, This is primarily leveraged for pipeline builds, but this can b= e leveraged locally using the=0D +lcov linux tool, and parsed using the lcov_cobertura python tool to parse = it to cobertura xml format.=0D +=0D +- Linux Prerequisite=0D + ```bash=0D + sudo apt-get install -y lcov=0D + python -m pip install --upgrade -r ./pip-requirements.txt=0D + stuart_ci_build -c .pytool/CISettings.py -t NOOPT TOOL_CHAIN_TAG=3DGCC5= -p MdeModulePkg=0D + Open Build/coverage.xml=0D + ```=0D + - How to see code coverage data on IDE Visual Studio Code=0D + ```=0D + Download plugin "Coverage Gutters"=0D + Press Hot Key "Ctrl + Shift + P" and click option "Coverage Gutters: D= isplay Coverage"=0D + ```=0D +=0D +=0D ### Important Note=0D =0D This works on both Windows and Linux but is currently limited to x64 archi= tectures. Working on getting others, but we=0D 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",=0D "NOFAILURE",=0D "cmockery",=0D + "cobertura",=0D "DHAVE", # build flag for cmocka in the INF=0D "gtest", # file name in GoogleTestLib.inf=0D "corthon", # Contact GitHub account in Readme=0D 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=0D XCODE:*_*_*_CC_FLAGS =3D -D UNIT_TESTING_DEBUG=3D1=0D !endif=0D -=0D + GCC:*_GCC5_*_CC_FLAGS =3D --coverage=0D + GCC:*_GCC5_*_DLINK_FLAGS =3D --coverage=0D [BuildOptions.common.EDKII.HOST_APPLICATION]=0D #=0D # MSFT=0D --=20 2.31.1.windows.1