From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web10.11061.1671594150149366696 for ; Tue, 20 Dec 2022 19:42:30 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=hn/3Jq1V; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from [192.168.4.22] (unknown [47.201.8.94]) by linux.microsoft.com (Postfix) with ESMTPSA id 13DDE20C3360; Tue, 20 Dec 2022 19:42:26 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 13DDE20C3360 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1671594147; bh=V9OIQtMlzCxQrWV2J9D7mYaSnF50qr/KXPkbMMtY3TE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=hn/3Jq1VFf+iHwcgm1qpa+B3gCuhe5DOUJFjBA13vYTA6TdmNwkEWhyKXpcGUs6yU Pm5QDfHuwknR5fEGvMpb6MK++yd2CrgebCZ2HY/hNhjeuawVlP5r7/70ZwdOoXsrey x8B81vloxn+uuD9aFGg3XawMgmZ7aS2Y4Zelvnn8= Message-ID: <0d3fe4ee-b975-3714-34fc-dd4a809791ce@linux.microsoft.com> Date: Tue, 20 Dec 2022 22:42:25 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.13.1 Subject: Re: [edk2-devel] [PATCH 3/3] .azurepipelines: Install code coverage tool To: devel@edk2.groups.io, gua.guo@intel.com Cc: Sean Brogan , Bret Barkelew , Michael D Kinney , Liming Gao References: <4640dcd72927df92d5304411c9a872acd97bf76c.1664502701.git.gua.guo@intel.com> From: "Michael Kubacki" In-Reply-To: <4640dcd72927df92d5304411c9a872acd97bf76c.1664502701.git.gua.guo@intel.com> Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit The "DiskName" variable in this line does not appear to be used (in gen_code_coverage_msvc()): DiskName = workspace[:workspace.find (":\\") + 2] --- Can you move the HostBasedUnitRunner changes to patch 2? That was scoped for BaseTools and this patch is scoped for .azurepipelines. On 9/29/2022 9:53 PM, Guo, Gua wrote: > 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' > > vm_image: 'ubuntu-latest' > > arch_list: "IA32,X64,ARM,AARCH64,RISCV64" > > - > > + extra_install_step: > > + - bash: sudo apt-get install -y lcov > > + displayName: Install Code Coverage Tools > > + condition: and(gt(variables.pkg_count, 0), succeeded()) > > diff --git a/.azurepipelines/Windows-VS2019.yml b/.azurepipelines/Windows-VS2019.yml > index e4bd4b1d22..c07e5bb434 100644 > --- a/.azurepipelines/Windows-VS2019.yml > +++ b/.azurepipelines/Windows-VS2019.yml > @@ -18,3 +18,8 @@ jobs: > tool_chain_tag: 'VS2019' > > vm_image: 'windows-2019' > > arch_list: "IA32,X64" > > + extra_install_step: > > + - powershell: choco install opencppcoverage; Write-Host "##vso[task.prependpath]C:\Program Files\OpenCppCoverage" > > + displayName: Install Code Coverage Tool > > + condition: and(gt(variables.pkg_count, 0), succeeded()) > > + > > diff --git a/.azurepipelines/templates/pr-gate-build-job.yml b/.azurepipelines/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: '' > > vm_image: '' > > arch_list: '' > > + extra_install_step: [] > > > > # Build step > > jobs: > > @@ -70,3 +71,4 @@ jobs: > build_pkgs: $(Build.Pkgs) > > build_targets: $(Build.Targets) > > build_archs: ${{ parameters.arch_list }} > > + extra_install_step: ${{ parameters.extra_install_step }} > > 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: '' > > build_targets: '' > > build_archs: '' > > + extra_install_step: [] > > > > steps: > > - checkout: self > > @@ -37,6 +38,8 @@ steps: > displayName: fetch target branch > > condition: eq(variables['Build.Reason'], 'PullRequest') > > > > +- ${{ parameters.extra_install_step }} > > + > > # trim the package list if this is a PR > > - task: CmdLine@1 > > displayName: Check if ${{ parameters.build_pkgs }} need testing > > @@ -125,6 +128,8 @@ steps: > TestSuites.xml > > **/BUILD_TOOLS_REPORT.html > > **/OVERRIDELOG.TXT > > + coverage.xml > > + coverage.html > > flattenFolders: true > > condition: succeededOrFailed() > > > > diff --git a/BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.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 = thebuilder.env.GetValue("BUILD_OUTPUT_BASE") > > testList = glob.glob(os.path.join(buildOutputBase, "**","*Test*.exe"), recursive=True) > > workspace = thebuilder.env.GetValue("WORKSPACE") > > - > > + workspace = (workspace + os.sep) if workspace[-1] != os.sep else workspace > > # Generate coverage file > > coverageFile = "" > > for testFile in testList: > > @@ -204,13 +204,14 @@ class HostBasedUnitTestRunner(IUefiBuildPlugin): > logging.error("UnitTest Coverage: Failed to collect coverage data.") > > return 1 > > > > + DiskName = workspace[:workspace.find (":\\") + 2] > > # Generate and HTML file if requested.by each package > > - ret = RunCmd("OpenCppCoverage", f"--export_type cobertura:{buildOutputBase}/coverage.xml --working_dir={workspace}/Build {coverageFile}") > > + ret = RunCmd("OpenCppCoverage", f"--export_type cobertura:{buildOutputBase}/coverage.xml --working_dir={workspace}Build {coverageFile}") > > if(ret != 0): > > logging.error("UnitTest Coverage: Failed to generate cobertura format xml in single package.") > > return 1 > > > > - ret = RunCmd("pycobertura", f"show --format html --output {buildOutputBase}/cverage.html {buildOutputBase}/coverage.xml --source {workspace}") > > + ret = RunCmd("pycobertura", f"show --format html --output {buildOutputBase}/coverage.html {buildOutputBase}/coverage.xml --source {DiskName}") > > if(ret != 0): > > logging.error("UnitTest Coverage: Failed to generate HTML in single package.") > > return 1 > > @@ -221,12 +222,11 @@ class HostBasedUnitTestRunner(IUefiBuildPlugin): > for testCoverage in testCoverageList: > > coverageFile += " --input_coverage=" + testCoverage > > > > - ret = RunCmd("OpenCppCoverage", f"--export_type cobertura:{workspace}/Build/coverage.xml --working_dir={workspace}/Build {coverageFile}") > > + ret = RunCmd("OpenCppCoverage", f"--export_type cobertura:{workspace}Build/coverage.xml --working_dir={workspace}Build {coverageFile}") > > if(ret != 0): > > logging.error("UnitTest Coverage: Failed to generate cobertura format xml.") > > return 1 > > - > > - ret = RunCmd("pycobertura", f"show --format html --output {workspace}/Build/coverage.html {workspace}/Build/coverage.xml --source {workspace}") > > + ret = RunCmd("pycobertura", f"show --format html --output {workspace}Build/coverage.html {workspace}Build/coverage.xml --source {DiskName}") > > if(ret != 0): > > logging.error("UnitTest Coverage: Failed to generate HTML.") > > return 1 > > 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==0.11.2 > edk2-pytool-extensions~=0.16.0 > > edk2-basetools==0.1.29 > > antlr4-python3-runtime==4.7.1 > > +pycobertura==2.1.0 > > +lcov-cobertura==2.0.2 > > + >