From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web10.1110.1664502832031588201 for ; Thu, 29 Sep 2022 18:53:53 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=lGQvsC2L; spf=pass (domain: intel.com, ip: 134.134.136.24, 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=1664502833; x=1696038833; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Rady/Yv+k/wg/hCduX2Ej6oaL5garCjKLS89j8WYtGA=; b=lGQvsC2Ls7eOOggBu4an2xvE5ajnKM/v3QdmcEUSWov5eK433JNSissk ey+zpzpSXNFvRJUoMThUuqFiG00BxI/HEr7dFbU/7vSqi4q90gFXF2g7z 0/hZGiQ0QXBT1mHElJCZo2kfKaF3wF3en8GUzCyD3OgHXXX/bUAthd667 9rQLVCeeqHMv0Rb8F4WcZvghd7LmzFIeb6WYmcEanfk2OBpvf5xHfdKb2 KWZev/CVvY+czfJ04OXQsh50L70UKiQGsvTdOoG+CkTr/UuO5uxn58DYv rXbEoP9DCdiSG/Zsi+g+TPWuxikbHuXo7aDwCC0DKz7O3XiKngAdx1Yl5 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="302991064" X-IronPort-AV: E=Sophos;i="5.93,357,1654585200"; d="scan'208";a="302991064" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2022 18:53:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="685098063" X-IronPort-AV: E=Sophos;i="5.93,357,1654585200"; d="scan'208";a="685098063" Received: from gguo-desk.gar.corp.intel.com ([10.5.215.23]) by fmsmga008.fm.intel.com with ESMTP; 29 Sep 2022 18:53:51 -0700 From: "Guo, Gua" To: devel@edk2.groups.io Cc: Gua Guo , Michael D Kinney , Sean Brogan , Bret Barkelew , Michael Kubacki Subject: [PATCH 1/3] UnitTestFrameworkPkg: Add code coverage support for GCC Date: Fri, 30 Sep 2022 09:53:46 +0800 Message-Id: <3e761ca731604e3eb08664309a2c16a56c5e472f.1664502701.git.gua.guo@intel.com> 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 | 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. =0D See this example in 'SampleUnitTestUefiShell.inf'...=0D =0D -```=0D +```inf=0D [Packages]=0D MdePkg/MdePkg.dec=0D =0D @@ -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=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 @@ -361,7 +361,7 @@ RUNNING TEST SUITE: Int Safe Conversions Test Suite ```=0D =0D You can also, if you are so inclined, read the output from the exact insta= nce of the test that was run during=0D -`stuart_ci_build`. The ouput file can be found on a path that looks like:= =0D +`stuart_ci_build`. The output file can be found on a path that looks like:= =0D =0D `Build//HostTest//...result.= xml`=0D =0D @@ -399,6 +399,37 @@ CMOCKA_XML_FILE=3D =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, and pycobertura is used to covert this cover= age data to a human readable HTML=0D +file. These tools must be installed to parse code coverage.=0D +=0D +- Windows Prerequisite=0D + ```bash=0D + Download and install https://github.com/OpenCppCoverage/OpenCppCoverage/= tags=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.html=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. pycobert= ura is used to=0D +covert this coverage data to a human readable HTML file. These tools must = be installed=0D +to parse code coverage.=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.html=0D + ```=0D +=0D +=0D ### Important Note=0D =0D This works on both Windows and Linux, but is currently limited to x64 arch= itectures. Working on getting others, but we=0D 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",=0D "NOFAILURE",=0D "cmockery",=0D + "cobertura",=0D + "pycobertura",=0D "DHAVE", # build flag for cmocka in the INF=0D "corthon", # Contact GitHub account in Readme=0D "mdkinney", # Contact GitHub account in Readme=0D 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=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