From 719cea2cf25c2b3e039206541e30457b92d33be0 Mon Sep 17 00:00:00 2001 From: yshi-parasoft Date: Fri, 28 Jun 2024 11:22:21 +0800 Subject: [PATCH] Support transformation from coverage report generated by cpptest professional 2024.1 --- README.md | 65 ++++ .../cpptest-professional-make/gitlab-ci.yml | 56 +++ xsl/cpptest-professional-cobertura/README.md | 34 ++ .../cobertura.xsl | 362 ++++++++++++++++++ 4 files changed, 517 insertions(+) create mode 100644 pipelines/coverage/cpptest-professional-make/gitlab-ci.yml create mode 100644 xsl/cpptest-professional-cobertura/README.md create mode 100644 xsl/cpptest-professional-cobertura/cobertura.xsl diff --git a/README.md b/README.md index 625ecbf..003d3a6 100644 --- a/README.md +++ b/README.md @@ -322,6 +322,71 @@ cpptest-coverage: paths: - $CPPTEST_REPORTS_DIR/* ``` +##### Run code coverage analysis with C/C++test Professional for Make project +See also the example [.gitlab-ci.yml](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/pipelines/coverage/cpptest-professional-make/.gitlab-ci.yml) file. + +```yaml +# This is a basic pipeline to help you get started with C/C++test Professional integration to collect code coverage for a Make-based project. + +# Be sure to configure variables below. +variables: + CPPTEST_INSTALL_DIR: "path/to/cpptest" + CPPTEST_XSL_DIR: "path/to/xsl" + CPPTEST_SAXON_DIR: "path/to/saxon" + +stages: + - test + +# Runs code coverage analysis with C/C++test. +cpptest-coverage: + variables: + CPPTEST_ADDITIONAL_REPORTS_DIR: "reports/xtest" + + stage: test + + # See: https://docs.gitlab.com/ee/ci/testing/code_coverage.html#add-test-coverage-results-using-coverage-keyword + coverage: '/ lines \(\d+% covered\)/' + + script: + # When running on Windows with PowerShell 5.1, be sure to enforce the default file encoding: + # - $PSDefaultParameterValues['Out-File:Encoding'] = 'default' + + # Builds your Make project using 'cpptesttrace' to collect input data for code coverage analysis. + # Be sure 'cpptesttrace' is available on $PATH. + - echo "Building project..." + - cpptesttrace make clean all + + # Launches C/C++test. + - echo "Running C/C++test..." + - echo "Generating Unit Tests..." + - cpptestcli -config "builtin://Generate Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -bdf cpptestscan.bdf + - echo "Running Unit Tests..." + - cpptestcli -config "builtin://Run Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -report reports -property report.additional.report.dir=$CPPTEST_ADDITIONAL_REPORTS_DIR + + # Converts the coverage report to Cobertura format. + # + # To use Saxon for report transformation, a Java executable is required. + # C/C++test includes Java which can be used for this purpose. + # + # When running on Windows, be sure to replace backslashes: + # - $CI_PROJECT_DIR = $CI_PROJECT_DIR.Replace("\", "/") + - echo "Generating Cobertura report..." + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/cobertura.xsl" -s:"$CPPTEST_ADDITIONAL_REPORTS_DIR/coverage.xml" -o:"$CPPTEST_ADDITIONAL_REPORTS_DIR/cobertura.xml" -t pipelineBuildWorkingDirectory=$CI_PROJECT_DIR + + after_script: + # Removes the workspace folder. + - rm -rf $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID + + artifacts: + # Uploads code coverage results in the Cobertura format, so that they are displayed in GitLab. + reports: + coverage_report: + coverage_format: cobertura + path: $CPPTEST_ADDITIONAL_REPORTS_DIR/cobertura.xml + # Uploads all report files (.xml, .html) as build artifacts. + paths: + - $CPPTEST_ADDITIONAL_REPORTS_DIR/* +``` ### Reviewing Analysis Results When the pipeline triggered by a merge request completes, you can review the code coverage data collected by C/C++test in the file diff view of the GitLab Merge requests. diff --git a/pipelines/coverage/cpptest-professional-make/gitlab-ci.yml b/pipelines/coverage/cpptest-professional-make/gitlab-ci.yml new file mode 100644 index 0000000..aa02b7f --- /dev/null +++ b/pipelines/coverage/cpptest-professional-make/gitlab-ci.yml @@ -0,0 +1,56 @@ +# This is a basic pipeline to help you get started with C/C++test Professional integration to collect code coverage for a Make-based project. + +# Be sure to configure variables below. +variables: + CPPTEST_INSTALL_DIR: "path/to/cpptest" + CPPTEST_XSL_DIR: "path/to/xsl" + CPPTEST_SAXON_DIR: "path/to/saxon" + +stages: + - test + +# Runs code coverage analysis with C/C++test. +cpptest-coverage: + variables: + CPPTEST_ADDITIONAL_REPORTS_DIR: "reports/xtest" + + stage: test + + # See: https://docs.gitlab.com/ee/ci/testing/code_coverage.html#add-test-coverage-results-using-coverage-keyword + coverage: '/ lines \(\d+% covered\)/' + + script: + # When running on Windows with PowerShell 5.1, be sure to enforce the default file encoding: + # - $PSDefaultParameterValues['Out-File:Encoding'] = 'default' + + # Builds your Make project using 'cpptesttrace' to collect input data for code coverage analysis. + # Be sure 'cpptesttrace' is available on $PATH. + - echo "Building project..." + - cpptesttrace make clean all + + # Launches C/C++test. + - echo "Running C/C++test..." + - echo "Generating Unit Tests..." + - cpptestcli -config "builtin://Generate Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -bdf cpptestscan.bdf + - echo "Running Unit Tests..." + - cpptestcli -config "builtin://Run Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -report reports -property report.additional.report.dir=$CPPTEST_ADDITIONAL_REPORTS_DIR + + # Converts the coverage report to Cobertura format. + # + # To use Saxon for report transformation, a Java executable is required. + # C/C++test includes Java which can be used for this purpose. + # + # When running on Windows, be sure to replace backslashes: + # - $CI_PROJECT_DIR = $CI_PROJECT_DIR.Replace("\", "/") + - echo "Generating Cobertura report..." + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/cobertura.xsl" -s:"$CPPTEST_ADDITIONAL_REPORTS_DIR/coverage.xml" -o:"$CPPTEST_ADDITIONAL_REPORTS_DIR/cobertura.xml" -t pipelineBuildWorkingDirectory=$CI_PROJECT_DIR + + artifacts: + # Uploads code coverage results in the Cobertura format, so that they are displayed in GitLab. + reports: + coverage_report: + coverage_format: cobertura + path: $CPPTEST_ADDITIONAL_REPORTS_DIR/cobertura.xml + # Uploads all report files (.xml, .html) as build artifacts. + paths: + - $CPPTEST_ADDITIONAL_REPORTS_DIR/* diff --git a/xsl/cpptest-professional-cobertura/README.md b/xsl/cpptest-professional-cobertura/README.md new file mode 100644 index 0000000..09a9268 --- /dev/null +++ b/xsl/cpptest-professional-cobertura/README.md @@ -0,0 +1,34 @@ +# Generating a Cobertura report with C/C++test Professional + +To report Code Coverage results using Cobertura format: + +1. Copy the [`cobertura.xsl`](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/xsl/cpptest-professional-cobertura/cobertura.xsl) file into a local directory (``). +2. Copy [`Saxon`](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/xsl/saxon) files into a local directory (``). +3. Update your GitLab pipeline to convert `/coverage.xml` report into `/cobertura.xml`: + +```yaml + ... + # Converts a coverage report to Cobertura format. + # + # To use Saxon for report transformation, a Java executable is required. + # C/C++test includes Java which can be used for this purpose: + # /bin/jre/bin/java + # + # When running on Windows, be sure to replace backslashes: + # - $CI_PROJECT_DIR = $CI_PROJECT_DIR.Replace("\", "/") + - echo "Generating Cobertura report..." + - java -jar "/saxon-he-12.2.jar" -xsl:"/cobertura.xsl" -s:"/coverage.xml" -o:"/cobertura.xml" -t pipelineBuildWorkingDirectory=$CI_PROJECT_DIR + + after_script: + # Removes the workspace folder. + - rm -rf $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID + + artifacts: + # Uploads code coverage results in the Cobertura format, so that they are displayed in GitLab. + reports: + coverage_report: + coverage_format: cobertura + path: /cobertura.xml + ... +``` +4. Run your GitLab pipeline. diff --git a/xsl/cpptest-professional-cobertura/cobertura.xsl b/xsl/cpptest-professional-cobertura/cobertura.xsl new file mode 100644 index 0000000..f0d5c43 --- /dev/null +++ b/xsl/cpptest-professional-cobertura/cobertura.xsl @@ -0,0 +1,362 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- GitLab