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:56 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=egU31APy; 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=1664502836; x=1696038836; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BdTAkJH1k0VKzHJVVZGCv8DtaMwR/pBntLBNMFs0CfY=; b=egU31APyIcJY6ntmJ4q1Xfj2Z/Ve7orBJRAH6kj+0+EdvDuUODuVDeho LUce0ZQyhkBX0Ys4bU9SogKCMYi/5heTjhOp7M0WSrTcGBbuQC97DzLpL 2ayhvRI6X76LSQuGsC5k/ZHSRbuW+dlOckHB43M87DCGZwd/cJibBpYec JlCkRAxUfPp08QQFAFvsoT+l/NLaUSFNk7lW0ZvCIJdYJHw/ZasGZSLCI aPhGdB/AKHbN6U9CStVAFW2a42ZZJ5epC4IOR5fofCb0rrgME5L07chLO RZxmf4esBCFrSXpQxbAloV4VIEgOd5DAGY1GljPttf2dLfr+O9wkkESxf Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="302991080" X-IronPort-AV: E=Sophos;i="5.93,357,1654585200"; d="scan'208";a="302991080" 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:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="685098075" X-IronPort-AV: E=Sophos;i="5.93,357,1654585200"; d="scan'208";a="685098075" Received: from gguo-desk.gar.corp.intel.com ([10.5.215.23]) by fmsmga008.fm.intel.com with ESMTP; 29 Sep 2022 18:53:54 -0700 From: "Guo, Gua" To: devel@edk2.groups.io Cc: Gua Guo , Sean Brogan , Bret Barkelew , Michael D Kinney , Liming Gao Subject: [PATCH 3/3] .azurepipelines: Install code coverage tool Date: Fri, 30 Sep 2022 09:53:48 +0800 Message-Id: <4640dcd72927df92d5304411c9a872acd97bf76c.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 For Windows add below tool for code coverage 1. OpenCppCoverage: parsing pdb file to generate coverage data 2. pycobertura: show up html format data for coverage data For Linux add below tool for code coverage 1. lcov: parsing gcda gcno file to generate coverage data 2. lcov-cobertura: convert coverage data to cobertura format 3. pycobertura: show up html format data for coverage data Cc: Sean Brogan Cc: Bret Barkelew Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Gua Guo --- .azurepipelines/Ubuntu-GCC5.yml | 5 ++++- .azurepipelines/Windows-VS2019.yml | 5 +++++ .azurepipelines/templates/pr-gate-build-job.yml | 2 ++ .azurepipelines/templates/pr-gate-steps.yml | 5 +++++ .../HostBasedUnitTestRunner.py | 12 ++++++------ pip-requirements.txt | 3 +++ 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.azurepipelines/Ubuntu-GCC5.yml b/.azurepipelines/Ubuntu-GCC5.= yml index 3760c6efe1..9d53528063 100644 --- a/.azurepipelines/Ubuntu-GCC5.yml +++ b/.azurepipelines/Ubuntu-GCC5.yml @@ -18,4 +18,7 @@ jobs: tool_chain_tag: 'GCC5'=0D vm_image: 'ubuntu-latest'=0D arch_list: "IA32,X64,ARM,AARCH64,RISCV64"=0D -=0D + extra_install_step:=0D + - bash: sudo apt-get install -y lcov=0D + displayName: Install Code Coverage Tools=0D + condition: and(gt(variables.pkg_count, 0), succeeded())=0D diff --git a/.azurepipelines/Windows-VS2019.yml b/.azurepipelines/Windows-V= S2019.yml index e4bd4b1d22..c07e5bb434 100644 --- a/.azurepipelines/Windows-VS2019.yml +++ b/.azurepipelines/Windows-VS2019.yml @@ -18,3 +18,8 @@ jobs: tool_chain_tag: 'VS2019'=0D vm_image: 'windows-2019'=0D arch_list: "IA32,X64"=0D + extra_install_step:=0D + - powershell: choco install opencppcoverage; Write-Host "##vso[task.pr= ependpath]C:\Program Files\OpenCppCoverage"=0D + displayName: Install Code Coverage Tool=0D + condition: and(gt(variables.pkg_count, 0), succeeded())=0D +=0D diff --git a/.azurepipelines/templates/pr-gate-build-job.yml b/.azurepipeli= nes/templates/pr-gate-build-job.yml index 0e4ad019bf..0162ea97cb 100644 --- a/.azurepipelines/templates/pr-gate-build-job.yml +++ b/.azurepipelines/templates/pr-gate-build-job.yml @@ -12,6 +12,7 @@ parameters: tool_chain_tag: ''=0D vm_image: ''=0D arch_list: ''=0D + extra_install_step: []=0D =0D # Build step=0D jobs:=0D @@ -70,3 +71,4 @@ jobs: build_pkgs: $(Build.Pkgs)=0D build_targets: $(Build.Targets)=0D build_archs: ${{ parameters.arch_list }}=0D + extra_install_step: ${{ parameters.extra_install_step }}=0D diff --git a/.azurepipelines/templates/pr-gate-steps.yml b/.azurepipelines/= templates/pr-gate-steps.yml index cb431e53fc..0568941399 100644 --- a/.azurepipelines/templates/pr-gate-steps.yml +++ b/.azurepipelines/templates/pr-gate-steps.yml @@ -12,6 +12,7 @@ parameters: build_pkgs: ''=0D build_targets: ''=0D build_archs: ''=0D + extra_install_step: []=0D =0D steps:=0D - checkout: self=0D @@ -37,6 +38,8 @@ steps: displayName: fetch target branch=0D condition: eq(variables['Build.Reason'], 'PullRequest')=0D =0D +- ${{ parameters.extra_install_step }}=0D +=0D # trim the package list if this is a PR=0D - task: CmdLine@1=0D displayName: Check if ${{ parameters.build_pkgs }} need testing=0D @@ -125,6 +128,8 @@ steps: TestSuites.xml=0D **/BUILD_TOOLS_REPORT.html=0D **/OVERRIDELOG.TXT=0D + coverage.xml=0D + coverage.html=0D flattenFolders: true=0D condition: succeededOrFailed()=0D =0D diff --git a/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunn= er.py b/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py index d92de236dc..c2821cde7d 100644 --- a/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py +++ b/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py @@ -194,7 +194,7 @@ class HostBasedUnitTestRunner(IUefiBuildPlugin): buildOutputBase =3D thebuilder.env.GetValue("BUILD_OUTPUT_BASE")=0D testList =3D glob.glob(os.path.join(buildOutputBase, "**","*Test*.= exe"), recursive=3DTrue)=0D workspace =3D thebuilder.env.GetValue("WORKSPACE")=0D -=0D + workspace =3D (workspace + os.sep) if workspace[-1] !=3D os.sep el= se workspace=0D # Generate coverage file=0D coverageFile =3D ""=0D for testFile in testList:=0D @@ -204,13 +204,14 @@ class HostBasedUnitTestRunner(IUefiBuildPlugin): logging.error("UnitTest Coverage: Failed to collect covera= ge data.")=0D return 1=0D =0D + DiskName =3D workspace[:workspace.find (":\\") + 2]=0D # Generate and HTML file if requested.by each package=0D - ret =3D RunCmd("OpenCppCoverage", f"--export_type cobertura:{build= OutputBase}/coverage.xml --working_dir=3D{workspace}/Build {coverageFile}")= =0D + ret =3D RunCmd("OpenCppCoverage", f"--export_type cobertura:{build= OutputBase}/coverage.xml --working_dir=3D{workspace}Build {coverageFile}")= =0D if(ret !=3D 0):=0D logging.error("UnitTest Coverage: Failed to generate cobertura= format xml in single package.")=0D return 1=0D =0D - ret =3D RunCmd("pycobertura", f"show --format html --output {build= OutputBase}/cverage.html {buildOutputBase}/coverage.xml --source {workspace= }")=0D + ret =3D RunCmd("pycobertura", f"show --format html --output {build= OutputBase}/coverage.html {buildOutputBase}/coverage.xml --source {DiskName= }")=0D if(ret !=3D 0):=0D logging.error("UnitTest Coverage: Failed to generate HTML in s= ingle package.")=0D return 1=0D @@ -221,12 +222,11 @@ class HostBasedUnitTestRunner(IUefiBuildPlugin): for testCoverage in testCoverageList:=0D coverageFile +=3D " --input_coverage=3D" + testCoverage=0D =0D - ret =3D RunCmd("OpenCppCoverage", f"--export_type cobertura:{works= pace}/Build/coverage.xml --working_dir=3D{workspace}/Build {coverageFile}")= =0D + ret =3D RunCmd("OpenCppCoverage", f"--export_type cobertura:{works= pace}Build/coverage.xml --working_dir=3D{workspace}Build {coverageFile}")=0D if(ret !=3D 0):=0D logging.error("UnitTest Coverage: Failed to generate cobertura= format xml.")=0D return 1=0D -=0D - ret =3D RunCmd("pycobertura", f"show --format html --output {works= pace}/Build/coverage.html {workspace}/Build/coverage.xml --source {workspac= e}")=0D + ret =3D RunCmd("pycobertura", f"show --format html --output {works= pace}Build/coverage.html {workspace}Build/coverage.xml --source {DiskName}"= )=0D if(ret !=3D 0):=0D logging.error("UnitTest Coverage: Failed to generate HTML.")=0D return 1=0D diff --git a/pip-requirements.txt b/pip-requirements.txt index 967da7cb37..18f5afb9c5 100644 --- a/pip-requirements.txt +++ b/pip-requirements.txt @@ -16,3 +16,6 @@ edk2-pytool-library=3D=3D0.11.2 edk2-pytool-extensions~=3D0.16.0=0D edk2-basetools=3D=3D0.1.29=0D antlr4-python3-runtime=3D=3D4.7.1=0D +pycobertura=3D=3D2.1.0=0D +lcov-cobertura=3D=3D2.0.2=0D +=0D --=20 2.31.1.windows.1