From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=RkKt94LW; spf=pass (domain: intel.com, ip: 192.55.52.136, 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=1664502961; x=1696038961; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Rady/Yv+k/wg/hCduX2Ej6oaL5garCjKLS89j8WYtGA=; b=RkKt94LWH7KzEcwlncBA0NLW5Xz+eZD6Pp2FjhJcLtIdD4NAd3CZ5WAO UIKXJ7JfaVnngha82sQRuWvble8hLhhlKiPL/MgG1HLUN7SeBHpup+UjF yhoaLR3eVGu9HUO6NYJgULAClPydi/5+0NUnkB0+OOI3LTkSNK37xpZaC LO95KQx0rGsbw32wRyWhWHX+bw79O0gXrIImGCBkKeiekUO06OpUTdkAv 4VkgQIZM7QCy3EszCmhIU+xS9EeuM/P12CG6+3ubr42myUbndasrbP2Zs 7R8WeaffI7rvrNXVvKqSmfd3df+x/N3xTOlaGvSvOq/TLKUI7mdWX8q49 Q==; 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" 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" 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: [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> 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