From f551a334b5ee99258ed2d0dae9e9ae92ac3a7dea Mon Sep 17 00:00:00 2001 From: yshi-parasoft Date: Tue, 23 Jul 2024 21:25:06 +0800 Subject: [PATCH 1/3] Support transformation from unit test reports to xUnit report and additional coverage report generated by cpptest professional 2024.1 --- README.md | 227 ++++++- .../cpptest-professional-make/gitlab-ci.yml | 56 ++ .../cpptest-professional-make/.gitlab-ci.yml | 62 ++ .../cpptest-standard-cmake/.gitlab-ci.yml | 51 ++ xsl/cpptest-professional-cobertura/README.md | 34 + .../cobertura.xsl | 362 +++++++++++ xsl/cpptest-professional-xunit/README.md | 23 + xsl/cpptest-professional-xunit/xunit.xsl | 598 ++++++++++++++++++ xsl/cpptest-standard-xunit/README.md | 23 + xsl/cpptest-standard-xunit/xunit.xsl | 598 ++++++++++++++++++ 10 files changed, 2033 insertions(+), 1 deletion(-) create mode 100644 pipelines/coverage/cpptest-professional-make/gitlab-ci.yml create mode 100644 pipelines/unit/cpptest-professional-make/.gitlab-ci.yml create mode 100644 pipelines/unit/cpptest-standard-cmake/.gitlab-ci.yml create mode 100644 xsl/cpptest-professional-cobertura/README.md create mode 100644 xsl/cpptest-professional-cobertura/cobertura.xsl create mode 100644 xsl/cpptest-professional-xunit/README.md create mode 100644 xsl/cpptest-professional-xunit/xunit.xsl create mode 100644 xsl/cpptest-standard-xunit/README.md create mode 100644 xsl/cpptest-standard-xunit/xunit.xsl diff --git a/README.md b/README.md index 625ecbf..c03b998 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ Please visit the [official Parasoft website](http://www.parasoft.com) for more i - [Quick start](#quick-start-sa) - [Example Pipelines](#example-pipelines-sa) - [Reviewing Analysis Results](#reviewing-analysis-results-sa) +- [Unit Tests](#unit-tests) + - [Quick start](#quick-start-ut) + - [Example Pipelines](#example-pipelines-ut) + - [Reviewing Test Results](#reviewing-test-results-ut) - [Code Coverage](#code-coverage) - [Quick start](#quick-start-cc) - [Example Pipelines](#example-pipelines-cc) @@ -226,6 +230,162 @@ You can define a merge request policy for your integration branch that will bloc 1. In the **Policy details** section, define a rule for Static Application Security Testing (select “IF SAST…”). Configure additional options, if needed. +## Unit Tests +### Quick start +To collect test executions results for your code with Parasoft C/C++test and review test results in GitLab, you need to customize your pipeline to include a job that will: + - build your project with unit tests instrumentation enabled. + - execute the instrumented application. + - generate C/C++test unit tests reports. + - convert C/C++test unit tests report to xUnit format (using Saxon). + - upload the xUnit report. + +#### Prerequisites +* This extension requires Parasoft C/C++test 2021.2 (or newer) with a valid Parasoft license. +* We recommend that you execute the pipeline on a GitLab runner with the following components installed and configured on the runner: + - C/C++ build toolchain + - Parasoft C/C++test 2021.2 (or newer) + - On Windows, we recommend that you use PowerShell Core 6 or later. If you use Windows PowerShell 5.1, you must ensure the correct file encoding - see the example pipelines for details. + +* To support xUnit format, you need the following files to be accessible on a GitLab runner: + - Saxon-HE, which you can copy the folder from [here](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/xsl/saxon) or download from [Saxonica](https://www.saxonica.com/download/java.xml). + - [XSLT file](xsl/cpptest-professional-xunit/xunit.xsl) for transforming C/C++test Professional unit tests report to xUnit report. + - [XSLT file](xsl/cpptest-standard-xunit/xunit.xsl) for transforming C/C++test Standard unit tests report to xUnit report. + +### Example Pipelines +The following examples show simple pipelines for Make and CMake-based projects. The examples assume that C/C++test is run on a GitLab runner and the path to the `cpptestcli` executable is available on `$PATH`. + + +##### Run C/C++test Standard with CMake project +For details on how to configure project for unit tests, see [Integrating with CppUnit and CppUtest](https://docs.parasoft.com/display/CPPTEST20232/Integrating+with+CppUnit+and+CppUtest). +See also the example [.gitlab-ci.yml](pipelines/unit/cpptest-standard-cmake/.gitlab-ci.yml) file. +```yaml +# This is a basic pipeline to help you get started with C/C++test integration to collect unit tests results for a CMake-based project. + +# Be sure to configure variables below. +variables: + CMAKE_APP_NAME: "app-executable" + CPPTEST_UT_LOG_FILE: "path/to/cpptest-ut-log-file" + CPPTEST_INSTALL_DIR: "path/to/cpptest" + CPPTEST_XSL_DIR: "path/to/xsl" + CPPTEST_SAXON_DIR: "path/to/saxon" + +stages: + - test + +# Runs unit tests with C/C++test. +cpptest-unit-tests: + variables: + CPPTEST_REPORTS_DIR: "path/to/reports" + + stage: test + + script: + # When running on Windows with PowerShell 5.1, be sure to enforce the default file encoding: + # - $PSDefaultParameterValues['Out-File:Encoding'] = 'default' + + # Configures your CMake project. + - echo "Configuring project..." + - cmake -S . -B build + + # Builds your CMake project. + - echo "Building project" + - cmake --build build + + # Run the instrumented application to generate unit tests log file (.utlog). + - echo "Run the instrumented application" + - build/$CMAKE_APP_NAME + + # Generate unit tests report + - echo "Generating unit tests report" + - cpptestcli -config "builtin://Unit Testing" -input $CPPTEST_UT_LOG_FILE -report $CPPTEST_REPORTS_DIR + + # Converts the unit tests report to xUnit format. + # + # To use Saxon for report transformation, a Java executable is required. + # C/C++test includes Java which can be used for this purpose. + - echo "Generating xUnit report..." + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/xunit.xsl" -s:"$CPPTEST_REPORTS_DIR/report.xml" -o:"$CPPTEST_REPORTS_DIR/report-xunit.xml" + + artifacts: + # Uploads test results in the xUnit format, so that they are displayed in GitLab + reports: + junit: $CPPTEST_REPORTS_DIR/report-xunit.xml +``` + +##### Run C/C++test Professional with Make project +For details on how to configure project for unit tests, see [Testing from the Command Line Interface](https://docs.parasoft.com/display/CPPTESTPROVS20232/Testing+from+the+Command+Line+Interface). +See also the example [.gitlab-ci.yml](pipelines/unit/cpptest-professional-make/.gitlab-ci.yml) file. + +```yaml +# This is a basic pipeline to help you get started with C/C++test integration to collect unit tests results for a Make-based project. + +# Be sure to configure variables below. +variables: + CPPTEST_XSL_DIR: "path/to/xsl" + CPPTEST_SAXON_DIR: "path/to/saxon" + CPPTEST_INSTALL_DIR: "path/to/cpptest" + +stages: + - build + - test + +build-make: + stage: build + script: + # Builds your Make project using 'cpptesttrace' to collect input data for handle test executions results. + # Be sure 'cpptesttrace' is available on $PATH. + - echo "Building project..." + - cpptesttrace make clean all + artifacts: + # Archives cpptestscan.bdf so that it can be used in the 'test' stage. + paths: + - cpptestscan.bdf + +# Runs unit test with C/C++test. +cpptest-unit-tests: + variables: + CPPTEST_REPORTS_DIR: "path/to/reports" + RESOURCE_PROJECT_FOLDER_NAME: "resource project folder name" + LOCALSETTINGS_FILE_PATH: "path/to/localsettings/properties/file" + + stage: test + script: + # When running on Windows with PowerShell 5.1, be sure to enforce the default file encoding: + # - $PSDefaultParameterValues['Out-File:Encoding'] = 'default' + + # Launches C/C++test. + - echo "Running C/C++test..." + # Generate unit tests + - echo "Generate unit tests" + - cpptestcli -config "builtin://Generate Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -localsettings $LOCALSETTINGS_FILE_PATH -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -bdf cpptestscan.bdf + # Run unit tests + - echo "Run unit tests" + # Use the following command line when using cpptest professional prior to v2024.1 + # - cpptestcli -config "builtin://Run Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -localsettings $LOCALSETTINGS_FILE_PATH -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -bdf cpptestscan.bdf -report $CPPTEST_REPORTS_DIR + + # Use the following command line when using cpptest professional v2024.1 + - cpptestcli -config "builtin://Run Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -localsettings $LOCALSETTINGS_FILE_PATH -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -bdf cpptestscan.bdf -property report.additional.report.dir=$CPPTEST_REPORTS_DIR + + # Converts the unit tests report to xUnit format. + # + # To use Saxon for report transformation, a Java executable is required. + # C/C++test includes Java which can be used for this purpose. + - echo "Generating xUnit report..." + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/xunit.xsl" -s:"$CPPTEST_REPORTS_DIR/report.xml" -o:"$CPPTEST_REPORTS_DIR/report-xunit.xml" + after_script: + # Removes the workspace folder. + - rm -rf $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID + + artifacts: + # Uploads test results in the xUnit format, so that they are displayed in GitLab + reports: + junit: $CPPTEST_REPORTS_DIR/report-xunit.xml +``` + +### Reviewing Test Results +When the pipeline completes, you can review the test results collected by C/C++test in the *Tests* tab of the GitLab pipeline. + + ## Code Coverage ### Quick start @@ -245,7 +405,7 @@ To collect code coverage with Parasoft C/C++test Standard and review coverage re - Parasoft C/C++test Standard 2021.2 (or newer) - On Windows, we recommend that you use PowerShell Core 6 or later. If you use Windows PowerShell 5.1, you must ensure the correct file encoding - see the example pipelines for details. * To support Cobertura format, you need the following files to be accessible on a GitLab runner: - - Saxon-HE, which you can copy from [here](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/xsl/saxon) or download from [Saxonica](https://www.saxonica.com/download/java.xml). + - Saxon-HE, which you can copy the folder from [here](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/xsl/saxon) or download from [Saxonica](https://www.saxonica.com/download/java.xml). - [XSLT file](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/xsl/cpptest-standard-cobertura/cobertura.xsl) for transforming C/C++test coverage report to Cobertura report. ### Example Pipelines @@ -322,6 +482,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/pipelines/unit/cpptest-professional-make/.gitlab-ci.yml b/pipelines/unit/cpptest-professional-make/.gitlab-ci.yml new file mode 100644 index 0000000..71770e5 --- /dev/null +++ b/pipelines/unit/cpptest-professional-make/.gitlab-ci.yml @@ -0,0 +1,62 @@ +# This is a basic pipeline to help you get started with C/C++test integration to collect unit tests results for a Make-based project. + +# Be sure to configure variables below. +variables: + CPPTEST_XSL_DIR: "path/to/xsl" + CPPTEST_SAXON_DIR: "path/to/saxon" + CPPTEST_INSTALL_DIR: "path/to/cpptest" + +stages: + - build + - test + +build-make: + stage: build + script: + # Builds your Make project using 'cpptesttrace' to collect input data for handle test executions results. + # Be sure 'cpptesttrace' is available on $PATH. + - echo "Building project..." + - cpptesttrace make clean all + artifacts: + # Archives cpptestscan.bdf so that it can be used in the 'test' stage. + paths: + - cpptestscan.bdf + +# Runs unit test with C/C++test. +cpptest-unit-tests: + variables: + CPPTEST_REPORTS_DIR: "path/to/reports" + RESOURCE_PROJECT_FOLDER_NAME: "resource project folder name" + LOCALSETTINGS_FILE_PATH: "path/to/localsettings/properties/file" + + stage: test + script: + # When running on Windows with PowerShell 5.1, be sure to enforce the default file encoding: + # - $PSDefaultParameterValues['Out-File:Encoding'] = 'default' + + # Launches C/C++test. + - echo "Running C/C++test..." + # Generate unit tests + - echo "Generate unit tests" + - cpptestcli -config "builtin://Generate Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -localsettings $LOCALSETTINGS_FILE_PATH -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -bdf cpptestscan.bdf + # Run unit tests + - echo "Run unit tests" + # Use the following command line when using cpptest professional prior to v2024.1 + # - cpptestcli -config "builtin://Run Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -localsettings $LOCALSETTINGS_FILE_PATH -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -bdf cpptestscan.bdf -report $CPPTEST_REPORTS_DIR + # Use the following command line when using cpptest professional v2024.1 + - cpptestcli -config "builtin://Run Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -localsettings $LOCALSETTINGS_FILE_PATH -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -bdf cpptestscan.bdf -property report.additional.report.dir=$CPPTEST_REPORTS_DIR + + # Converts the unit tests report to xUnit format. + # + # To use Saxon for report transformation, a Java executable is required. + # C/C++test includes Java which can be used for this purpose. + - echo "Generating xUnit report..." + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/xunit.xsl" -s:"$CPPTEST_REPORTS_DIR/report.xml" -o:"$CPPTEST_REPORTS_DIR/report-xunit.xml" + after_script: + # Removes the workspace folder. + - rm -rf $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID + + artifacts: + # Uploads test results in the xUnit format, so that they are displayed in GitLab + reports: + junit: $CPPTEST_REPORTS_DIR/report-xunit.xml \ No newline at end of file diff --git a/pipelines/unit/cpptest-standard-cmake/.gitlab-ci.yml b/pipelines/unit/cpptest-standard-cmake/.gitlab-ci.yml new file mode 100644 index 0000000..b431df6 --- /dev/null +++ b/pipelines/unit/cpptest-standard-cmake/.gitlab-ci.yml @@ -0,0 +1,51 @@ +# This is a basic pipeline to help you get started with C/C++test integration to collect unit tests results for a CMake-based project. + +# Be sure to configure variables below. +variables: + CMAKE_APP_NAME: "app-executable" + CPPTEST_UT_LOG_FILE: "path/to/cpptest-ut-log-file" + CPPTEST_INSTALL_DIR: "path/to/cpptest" + CPPTEST_XSL_DIR: "path/to/xsl" + CPPTEST_SAXON_DIR: "path/to/saxon" + +stages: + - test + +# Runs unit tests with C/C++test. +cpptest-unit-tests: + variables: + CPPTEST_REPORTS_DIR: "path/to/reports" + + stage: test + + script: + # When running on Windows with PowerShell 5.1, be sure to enforce the default file encoding: + # - $PSDefaultParameterValues['Out-File:Encoding'] = 'default' + + # Configures your CMake project. + - echo "Configuring project..." + - cmake -S . -B build + + # Builds your CMake project. + - echo "Building project" + - cmake --build build + + # Run the instrumented application to generate unit tests log file (.utlog). + - echo "Run the instrumented application" + - build/$CMAKE_APP_NAME + + # Generate unit tests report + - echo "Generating unit tests report" + - cpptestcli -config "builtin://Unit Testing" -input $CPPTEST_UT_LOG_FILE -report $CPPTEST_REPORTS_DIR + + # Converts the unit tests report to xUnit format. + # + # To use Saxon for report transformation, a Java executable is required. + # C/C++test includes Java which can be used for this purpose. + - echo "Generating xUnit report..." + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/xunit.xsl" -s:"$CPPTEST_REPORTS_DIR/report.xml" -o:"$CPPTEST_REPORTS_DIR/report-xunit.xml" + + artifacts: + # Uploads test results in the xUnit format, so that they are displayed in GitLab + reports: + junit: $CPPTEST_REPORTS_DIR/report-xunit.xml \ No newline at end of file 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 diff --git a/xsl/cpptest-professional-xunit/README.md b/xsl/cpptest-professional-xunit/README.md new file mode 100644 index 0000000..4cc3a16 --- /dev/null +++ b/xsl/cpptest-professional-xunit/README.md @@ -0,0 +1,23 @@ +# Generating a xUnit report with C/C++test Professional + +To report unit tests results using xUnit format: + +1. Copy the [`xunit.xsl`](xunit.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 `/report.xml` report into `/report-xunit.xml`: + +```yaml + ... + # Converts the unit tests report to xUnit format. + # + # To use Saxon for report transformation, a Java executable is required. + # C/C++test includes Java which can be used for this purpose. + - echo "Generating xUnit report..." + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/xunit.xsl" -s:"$CPPTEST_REPORTS_DIR/report.xml" -o:"$CPPTEST_REPORTS_DIR/report-xunit.xml" + + artifacts: + # Uploads test results in the xUnit format, so that they are displayed in GitLab + reports: + junit: $CPPTEST_REPORTS_DIR/report-xunit.xml +``` +4. Run your GitLab pipeline. diff --git a/xsl/cpptest-professional-xunit/xunit.xsl b/xsl/cpptest-professional-xunit/xunit.xsl new file mode 100644 index 0000000..b79de62 --- /dev/null +++ b/xsl/cpptest-professional-xunit/xunit.xsl @@ -0,0 +1,598 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Caused by: + + + + + + at + + + + + + + + + + + + + + + + + + + + + Multiple errors reported + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + err + fail + pass + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Caused by: + + + + + + at + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + . + + + / + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xsl/cpptest-standard-xunit/README.md b/xsl/cpptest-standard-xunit/README.md new file mode 100644 index 0000000..53176dd --- /dev/null +++ b/xsl/cpptest-standard-xunit/README.md @@ -0,0 +1,23 @@ +# Generating a xUnit report with C/C++test Standard + +To report unit tests results using xUnit format: + +1. Copy the [`xunit.xsl`](xunit.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 `/report.xml` report into `/report-xunit.xml`: + +```yaml + ... + # Converts the unit tests report to xUnit format. + # + # To use Saxon for report transformation, a Java executable is required. + # C/C++test includes Java which can be used for this purpose. + - echo "Generating xUnit report..." + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/xunit.xsl" -s:"$CPPTEST_REPORTS_DIR/report.xml" -o:"$CPPTEST_REPORTS_DIR/report-xunit.xml" + + artifacts: + # Uploads test results in the xUnit format, so that they are displayed in GitLab + reports: + junit: $CPPTEST_REPORTS_DIR/report-xunit.xml +``` +4. Run your GitLab pipeline. diff --git a/xsl/cpptest-standard-xunit/xunit.xsl b/xsl/cpptest-standard-xunit/xunit.xsl new file mode 100644 index 0000000..b79de62 --- /dev/null +++ b/xsl/cpptest-standard-xunit/xunit.xsl @@ -0,0 +1,598 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Caused by: + + + + + + at + + + + + + + + + + + + + + + + + + + + + Multiple errors reported + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + err + fail + pass + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Caused by: + + + + + + at + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + . + + + / + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- GitLab From 04ab34943e44b33f06caf4405a9b95d60b473170 Mon Sep 17 00:00:00 2001 From: yshi-parasoft Date: Wed, 24 Jul 2024 11:40:32 +0800 Subject: [PATCH 2/3] Update xsl to the latest across all platforms and update readme --- README.md | 29 ++++++------ .../cpptest-professional-make/gitlab-ci.yml | 14 ++++-- .../cpptest-professional-make/.gitlab-ci.yml | 3 -- xsl/cpptest-professional-cobertura/README.md | 15 ++---- .../cobertura.xsl | 41 ++++++++++++++--- xsl/cpptest-professional-xunit/xunit.xsl | 46 ++++++++----------- xsl/cpptest-standard-cobertura/README.md | 9 ++-- xsl/cpptest-standard-cobertura/cobertura.xsl | 41 ++++++++++++++--- xsl/cpptest-standard-xunit/README.md | 12 ++--- xsl/cpptest-standard-xunit/xunit.xsl | 46 ++++++++----------- 10 files changed, 146 insertions(+), 110 deletions(-) diff --git a/README.md b/README.md index c03b998..bdd23ed 100644 --- a/README.md +++ b/README.md @@ -240,16 +240,16 @@ To collect test executions results for your code with Parasoft C/C++test and rev - upload the xUnit report. #### Prerequisites -* This extension requires Parasoft C/C++test 2021.2 (or newer) with a valid Parasoft license. +* This extension requires Parasoft C/C++test 2020.2 (or newer) with a valid Parasoft license. * We recommend that you execute the pipeline on a GitLab runner with the following components installed and configured on the runner: - C/C++ build toolchain - - Parasoft C/C++test 2021.2 (or newer) + - Parasoft C/C++test 2020.2 (or newer) - On Windows, we recommend that you use PowerShell Core 6 or later. If you use Windows PowerShell 5.1, you must ensure the correct file encoding - see the example pipelines for details. * To support xUnit format, you need the following files to be accessible on a GitLab runner: - Saxon-HE, which you can copy the folder from [here](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/xsl/saxon) or download from [Saxonica](https://www.saxonica.com/download/java.xml). - - [XSLT file](xsl/cpptest-professional-xunit/xunit.xsl) for transforming C/C++test Professional unit tests report to xUnit report. - [XSLT file](xsl/cpptest-standard-xunit/xunit.xsl) for transforming C/C++test Standard unit tests report to xUnit report. + - [XSLT file](xsl/cpptest-professional-xunit/xunit.xsl) for transforming C/C++test Professional unit tests report to xUnit report. ### Example Pipelines The following examples show simple pipelines for Make and CMake-based projects. The examples assume that C/C++test is run on a GitLab runner and the path to the `cpptestcli` executable is available on `$PATH`. @@ -301,7 +301,7 @@ cpptest-unit-tests: # Converts the unit tests report to xUnit format. # - # To use Saxon for report transformation, a Java executable is required. + # To use Saxon for report transformation, a Java executable is required. # C/C++test includes Java which can be used for this purpose. - echo "Generating xUnit report..." - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/xunit.xsl" -s:"$CPPTEST_REPORTS_DIR/report.xml" -o:"$CPPTEST_REPORTS_DIR/report-xunit.xml" @@ -389,9 +389,7 @@ When the pipeline completes, you can review the test results collected by C/C++t ## Code Coverage ### Quick start -To collect code coverage with Parasoft C/C++test Standard and review coverage results in GitLab, you need to: -* Integrate C/C++test with your C/C++ build to enable code coverage instrumentation. See also [Collecting Code Coverage](https://docs.parasoft.com/display/CPPTEST20231/Collecting+Code+Coverage). -* Customize your pipeline to include a job that will: +To collect code coverage with Parasoft C/C++test and review coverage results in GitLab, you need to customize your pipeline to include a job that will: - build your project with code coverage instrumentation enabled. - execute the instrumented application. - generate C/C++test coverage reports. @@ -399,14 +397,15 @@ To collect code coverage with Parasoft C/C++test Standard and review coverage re - upload the coverage reports. #### Prerequisites -* This extension requires Parasoft C/C++test Standard 2021.2 (or newer) with a valid Parasoft license. +* This extension requires Parasoft C/C++test 2020.2 (or newer) with a valid Parasoft license. * We recommend that you execute the pipeline on a GitLab runner with the following components installed and configured on the runner: - C/C++ build toolchain - - Parasoft C/C++test Standard 2021.2 (or newer) + - Parasoft C/C++test 2020.2 (or newer) - On Windows, we recommend that you use PowerShell Core 6 or later. If you use Windows PowerShell 5.1, you must ensure the correct file encoding - see the example pipelines for details. * To support Cobertura format, you need the following files to be accessible on a GitLab runner: - Saxon-HE, which you can copy the folder from [here](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/xsl/saxon) or download from [Saxonica](https://www.saxonica.com/download/java.xml). - - [XSLT file](https://gitlab.com/parasoft/cpptest-gitlab/-/blob/master/xsl/cpptest-standard-cobertura/cobertura.xsl) for transforming C/C++test coverage report to Cobertura report. + - [XSLT file](xsl/cpptest-standard-cobertura/cobertura.xsl) for transforming C/C++test Standard coverage report to Cobertura report. + - [XSLT file](xsl/cpptest-professional-cobertura/cobertura.xsl) for transforming C/C++test Professional coverage report to Cobertura report. ### Example Pipelines ##### Run code coverage analysis with C/C++test Standard for CMake project @@ -500,7 +499,7 @@ stages: # Runs code coverage analysis with C/C++test. cpptest-coverage: variables: - CPPTEST_ADDITIONAL_REPORTS_DIR: "reports/xtest" + CPPTEST_REPORTS_DIR: "path/to/reports" stage: test @@ -521,7 +520,7 @@ cpptest-coverage: - 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 + - cpptestcli -config "builtin://Run Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -property report.additional.report.dir=$CPPTEST_REPORTS_DIR # Converts the coverage report to Cobertura format. # @@ -531,7 +530,7 @@ cpptest-coverage: # 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 + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/cobertura.xsl" -s:"$CPPTEST_REPORTS_DIR/coverage.xml" -o:"$CPPTEST_REPORTS_DIR/cobertura.xml" -t pipelineBuildWorkingDirectory=$CI_PROJECT_DIR after_script: # Removes the workspace folder. @@ -542,10 +541,10 @@ cpptest-coverage: reports: coverage_report: coverage_format: cobertura - path: $CPPTEST_ADDITIONAL_REPORTS_DIR/cobertura.xml + path: $CPPTEST_REPORTS_DIR/cobertura.xml # Uploads all report files (.xml, .html) as build artifacts. paths: - - $CPPTEST_ADDITIONAL_REPORTS_DIR/* + - $CPPTEST_REPORTS_DIR/* ``` ### Reviewing Analysis Results diff --git a/pipelines/coverage/cpptest-professional-make/gitlab-ci.yml b/pipelines/coverage/cpptest-professional-make/gitlab-ci.yml index aa02b7f..5ef07f6 100644 --- a/pipelines/coverage/cpptest-professional-make/gitlab-ci.yml +++ b/pipelines/coverage/cpptest-professional-make/gitlab-ci.yml @@ -12,7 +12,7 @@ stages: # Runs code coverage analysis with C/C++test. cpptest-coverage: variables: - CPPTEST_ADDITIONAL_REPORTS_DIR: "reports/xtest" + CPPTEST_REPORTS_DIR: "path/to/reports" stage: test @@ -33,7 +33,7 @@ cpptest-coverage: - 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 + - cpptestcli -config "builtin://Run Unit Tests" -resource $RESOURCE_PROJECT_FOLDER_NAME -data $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID -property report.additional.report.dir=$CPPTEST_REPORTS_DIR # Converts the coverage report to Cobertura format. # @@ -43,14 +43,18 @@ cpptest-coverage: # 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 + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/cobertura.xsl" -s:"$CPPTEST_REPORTS_DIR/coverage.xml" -o:"$CPPTEST_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 + path: $CPPTEST_REPORTS_DIR/cobertura.xml # Uploads all report files (.xml, .html) as build artifacts. paths: - - $CPPTEST_ADDITIONAL_REPORTS_DIR/* + - $CPPTEST_REPORTS_DIR/* diff --git a/pipelines/unit/cpptest-professional-make/.gitlab-ci.yml b/pipelines/unit/cpptest-professional-make/.gitlab-ci.yml index 71770e5..8a283fd 100644 --- a/pipelines/unit/cpptest-professional-make/.gitlab-ci.yml +++ b/pipelines/unit/cpptest-professional-make/.gitlab-ci.yml @@ -52,9 +52,6 @@ cpptest-unit-tests: # C/C++test includes Java which can be used for this purpose. - echo "Generating xUnit report..." - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/xunit.xsl" -s:"$CPPTEST_REPORTS_DIR/report.xml" -o:"$CPPTEST_REPORTS_DIR/report-xunit.xml" - after_script: - # Removes the workspace folder. - - rm -rf $CI_BUILDS_DIR/cpptest-workspace-$CI_PIPELINE_ID artifacts: # Uploads test results in the xUnit format, so that they are displayed in GitLab diff --git a/xsl/cpptest-professional-cobertura/README.md b/xsl/cpptest-professional-cobertura/README.md index 09a9268..b387a60 100644 --- a/xsl/cpptest-professional-cobertura/README.md +++ b/xsl/cpptest-professional-cobertura/README.md @@ -4,31 +4,26 @@ 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`: +3. Update your GitLab pipeline to convert `/coverage.xml` report into `/cobertura.xml`: ```yaml ... - # Converts a coverage report to Cobertura format. + # 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: - # /bin/jre/bin/java + # 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..." - - 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 + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/cobertura.xsl" -s:"$CPPTEST_REPORTS_DIR/coverage.xml" -o:"$CPPTEST_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: /cobertura.xml + path: $CPPTEST_REPORTS_DIR/cobertura.xml ... ``` 4. Run your GitLab pipeline. diff --git a/xsl/cpptest-professional-cobertura/cobertura.xsl b/xsl/cpptest-professional-cobertura/cobertura.xsl index f0d5c43..86fb974 100644 --- a/xsl/cpptest-professional-cobertura/cobertura.xsl +++ b/xsl/cpptest-professional-cobertura/cobertura.xsl @@ -56,7 +56,7 @@ - + @@ -65,7 +65,7 @@ - + @@ -268,19 +268,19 @@ - + - + - + @@ -295,6 +295,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -332,6 +358,9 @@ + + + @@ -355,7 +384,7 @@ - + diff --git a/xsl/cpptest-professional-xunit/xunit.xsl b/xsl/cpptest-professional-xunit/xunit.xsl index b79de62..50993c2 100644 --- a/xsl/cpptest-professional-xunit/xunit.xsl +++ b/xsl/cpptest-professional-xunit/xunit.xsl @@ -6,11 +6,6 @@ - - - - - @@ -435,28 +430,25 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/xsl/cpptest-standard-cobertura/README.md b/xsl/cpptest-standard-cobertura/README.md index c80314c..fc79db3 100644 --- a/xsl/cpptest-standard-cobertura/README.md +++ b/xsl/cpptest-standard-cobertura/README.md @@ -8,23 +8,22 @@ To report Code Coverage results using Cobertura format: ```yaml ... - # Converts a coverage report to Cobertura format. + # 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: - # /bin/jre/bin/java + # 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..." - - java -jar "/saxon-he-12.2.jar" -xsl:"/cobertura.xsl" -s:"/coverage.xml" -o:"/cobertura.xml" -t pipelineBuildWorkingDirectory=$CI_PROJECT_DIR + - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/cobertura.xsl" -s:"$CPPTEST_REPORTS_DIR/coverage.xml" -o:"$CPPTEST_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: /cobertura.xml + path: $CPPTEST_REPORTS_DIR/cobertura.xml ... ``` 4. Run your GitLab pipeline. diff --git a/xsl/cpptest-standard-cobertura/cobertura.xsl b/xsl/cpptest-standard-cobertura/cobertura.xsl index da2414a..7106635 100644 --- a/xsl/cpptest-standard-cobertura/cobertura.xsl +++ b/xsl/cpptest-standard-cobertura/cobertura.xsl @@ -56,7 +56,7 @@ - + @@ -65,7 +65,7 @@ - + @@ -268,19 +268,19 @@ - + - + - + @@ -295,6 +295,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -332,6 +358,9 @@ + + + @@ -355,7 +384,7 @@ - + diff --git a/xsl/cpptest-standard-xunit/README.md b/xsl/cpptest-standard-xunit/README.md index 53176dd..1dd3012 100644 --- a/xsl/cpptest-standard-xunit/README.md +++ b/xsl/cpptest-standard-xunit/README.md @@ -10,14 +10,14 @@ To report unit tests results using xUnit format: ... # Converts the unit tests report to xUnit format. # - # To use Saxon for report transformation, a Java executable is required. + # To use Saxon for report transformation, a Java executable is required. # C/C++test includes Java which can be used for this purpose. - echo "Generating xUnit report..." - $CPPTEST_INSTALL_DIR/bin/jre/bin/java -jar "$CPPTEST_SAXON_DIR/saxon-he-12.2.jar" -xsl:"$CPPTEST_XSL_DIR/xunit.xsl" -s:"$CPPTEST_REPORTS_DIR/report.xml" -o:"$CPPTEST_REPORTS_DIR/report-xunit.xml" - - artifacts: - # Uploads test results in the xUnit format, so that they are displayed in GitLab - reports: - junit: $CPPTEST_REPORTS_DIR/report-xunit.xml + + artifacts: + # Uploads test results in the xUnit format, so that they are displayed in GitLab + reports: + junit: $CPPTEST_REPORTS_DIR/report-xunit.xml ``` 4. Run your GitLab pipeline. diff --git a/xsl/cpptest-standard-xunit/xunit.xsl b/xsl/cpptest-standard-xunit/xunit.xsl index b79de62..50993c2 100644 --- a/xsl/cpptest-standard-xunit/xunit.xsl +++ b/xsl/cpptest-standard-xunit/xunit.xsl @@ -6,11 +6,6 @@ - - - - - @@ -435,28 +430,25 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + -- GitLab From b010354c9875ba9dc583841dc09692496862ba61 Mon Sep 17 00:00:00 2001 From: yshi-parasoft Date: Fri, 8 Nov 2024 09:57:27 -0800 Subject: [PATCH 3/3] Updated cobertura.xsl to be consistent with other platforms --- .../cobertura.xsl | 88 +- xsl/cpptest-standard-cobertura/cobertura.xsl | 840 ++++++++++-------- 2 files changed, 524 insertions(+), 404 deletions(-) diff --git a/xsl/cpptest-professional-cobertura/cobertura.xsl b/xsl/cpptest-professional-cobertura/cobertura.xsl index 86fb974..086b5f8 100644 --- a/xsl/cpptest-professional-cobertura/cobertura.xsl +++ b/xsl/cpptest-professional-cobertura/cobertura.xsl @@ -1,12 +1,59 @@ + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:map="http://www.w3.org/2005/xpath-functions/map"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -40,8 +87,13 @@ - + + + + + + @@ -55,18 +107,18 @@ - + - + - + @@ -79,13 +131,13 @@ - + - + @@ -98,14 +150,21 @@ + + + + + - + + - - + + + @@ -217,7 +276,7 @@ - + @@ -239,7 +298,8 @@ - + + diff --git a/xsl/cpptest-standard-cobertura/cobertura.xsl b/xsl/cpptest-standard-cobertura/cobertura.xsl index 7106635..086b5f8 100644 --- a/xsl/cpptest-standard-cobertura/cobertura.xsl +++ b/xsl/cpptest-standard-cobertura/cobertura.xsl @@ -1,391 +1,451 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- GitLab