主要内容

polyspace-test -report

(System Command) Generate reports from test or code profiling results

Since R2023b

Description

The system command polyspace-test -report generates XML or HTML reports from C/C++ test or code profiling results.

polyspace-test -report -report-dir <reportFolder> -xml <testResults> [-omit-passed-assessments] generates an XML report from the test result files specified by <testResults>. You can optionally omit passed assessments from the report. If the test results are associated with code profiling results, separate reports are generated for the profiling results too.

example

polyspace-test -report -report-dir <reportFolder> -html <testResults> [-generate-test-spec-report] [-omit-passed-assessments] generates HTML reports from the test result files in <testResults>. You can optionally report the test specifications in addition to the test results or omit passed assessments from the report. If the test results are associated with code profiling results, separate reports are generated for the profiling results too.

example

polyspace-test -report -report-dir <reportFolder> -html <testResults> -report-options <reportCustomizationFile> generates HTML reports from test results by using a JSON file <reportCustomizationFile> that contains report customization options.

example

polyspace-test -report -report-dir <reportFolder> -xml <profilingResults> [-filter-files <filterFiles>] generates an XML report from the code profiling result files in <profilingResults>. You can optionally provide paths to filter files that apply justifications to the code profiling results.

example

polyspace-test -report -report-dir <reportFolder> -html <profilingResults> [-filter-files <filterFiles>] generates HTML reports from the code profiling result files in <profilingResults>.

polyspace-test -report -report-dir <reportFolder> -html <profilingResults> -report-options <reportCustomizationFile> [-filter-files <filterFiles>] generates HTML reports from code profiling results using a JSON file <reportCustomizationFile> that contains report customization options..

polyspace-test -report -options-file <optionsFile> generates reports using the options specified in <optionsFile>.

Examples

collapse all

Automate the building and running of the tests in a Polyspace® project file by using the polyspace-test command.

For an example of creating a project and adding sources and tests, see Write C/C++ Unit Tests in Polyspace Platform User Interface.

  1. Build a test executable to run all the tests included in a project file projectName.psprjx.

    polyspace-test -build -project projectName.psprjx

    The command generates the test executable and other artifacts and stores them in folder polyspace_artifacts.

  2. Run the tests and generate a results file.

    polyspace-test -run -project projectName.psprjx -results-dir resultsFolder

    The command runs all the tests and generates a .pstestr results file which is stored in the folder resultsFolder. When you use the -run command, if a test executable does not already exist, the software builds the tests and then runs them.

  3. Generate an XML report to capture a snapshot of the testing status.

    polyspace-test -report -report-dir reportFolder -xml resultsFolder
    The generated report is stored in a subfolder of the reportFolder folder.

Report test results in a format that provides detailed information only for assessments that did not pass.

You can specify report generation options either at the command line or using a report customization file in JSON format:

  • To specify the omission of passed assessments at the command line, enter this command:

    polyspace-test -report -report-dir reportFolder -html resultsFolder -omit-passed-assessments

  • To specify the omission of passed assessments in a report customization file:

    1. Enter this content in a JSON file reportCustomizations.json:

      {
          "test_results_report": {
              "report_passed_assessments": false
          }
      }

    2. Specify the options file in the polyspace-test -report command:

      polyspace-test -report -report-dir reportFolder -html resultsFolder -report-options reportCustomizations.json

      Here, resultsFolder is the folder containing test results and reportFolder is the folder where generated reports are stored.

Add a custom header and footer to reports generated from test or code profiling results.

  1. Enter the header content in a file headerInfo.html:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Division Info</title>
    </head>
    <body>
        <p>Code Quality Group Report</p>
    </body>
    </html>
    You will enter the footer content directly as text in the report options file.

    In a CSS file reportStyles.css, enter the styling that you want to apply to the above header HTML. For example, to add a margin between the top of the page and the header, you can add this styling:

    header {
        margin-top: 20px;
    }

  2. Create a report options file reportCustomizations.json that refers to the previously created header HTML and CSS:

    {
        "header": {
            "file": "headerInfo.html"
        },
        "footer": {
            "text": "For internal audit only. Not for distribution."
        },
        "style": {
            "link": "reportStyles.css"
        }
    }
    You can also refer to the HTML and CSS file by using an absolute path.

  3. Generate test reports from the test results in the folder resultsFolder using the report options file reportCustomizations.json. Save the reports in the folder reportFolder.

    polyspace-test -report -report-dir reportFolder -html resultsFolder -report-options reportCustomizations.json

  4. Open the generated HTML report from reportFolder\ps_test\pstunit.

    The custom header and footer text appear in the report, and the HTML page source includes this line:

    <link rel="stylesheet" type="text/css" href="reportStyles.css"/>
    If you specified an absolute path to the CSS file, you see a margin between the top of the report and the header. If you specified just the file name, copy the CSS file into the same folder as the HTML report files for the styles to be applied.

Add a custom section to reports generated from test or code profiling results. The section can contain text such as the project name and version number.

  1. Create a new report section in the HTML file versionNumber.html:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Version Number</title>
    </head>
    <body>
        <p>This report contains test results for version <span class="versionNumber">23</span> of the project <span class="projectName">My_project</span>.</p>
    </body>
    </html>
    In a CSS file reportStyles.css, enter the styling that you want to apply to the above HTML. For instance, if you want contents of HTML elements with classes versionNumber and projectName to appear in blue, you can create the following CSS:
    .versionNumber,
    .projectName {
        color: blue;
    }

  2. Create a report customization JSON file reportCustomizations.json that refers to the HTML and CSS file created in the previous step:

    {
        "custom_sections": {
            "VERSION": {
                "file": "<versionNumber>.html",
                "title": "Version History"
            }
        },
        "style": {
            "link": "<reportStyles>.css"
        },
        "test_results_report": {
            "sections_order": {
                "main_report": "main_report": [
                                   "PROJECTINFO",
                                   "VERSION", 
                                   "ENVIRONMENTINFO", 
                                   "SUMMARY", 
                                   "SUITESSUMMARY", 
                                   "MESSAGES"],
                "test_specification_report": ["VERSION", "SUITESSUMMARY"]
            }
        }
    }
    You can also refer to the HTML and CSS file by using an absolute path.

  3. Generate test reports from the test results in the folder resultsFolder using the report options file reportCustomizations.json. Save the reports in the folder reportFolder.

    polyspace-test -report -report-dir reportFolder -html resultsFolder -report-options reportCustomizations.json

  4. Open the generated HTML report from reportFolder\ps_test\pstunit. The custom section appears in the report with the style applied from the CSS:

    Version History
    This report contains test results for version 23 of the project My_project.

    If you specified an absolute path to the CSS file, the CSS style is applied automatically. If you specified just the file name, copy the CSS file into the same folder as the HTML report files for the style to be applied.

Input Arguments

collapse all

Path to the report folder:

  • If you generate a report from test results, the report is stored in a subfolder ps_test in the report folder.

  • If you generate a report from code profiling results, the report is stored in a subfolder ps_profiling in the report folder.

One or more space separated paths. You can specify paths to test result files (.pstestr files) or folders containing test result files. If you specify a folder, the command looks for test result files only at the top level of the folder and not in subfolders.

One or more space separated paths. You can specify code profiling result files (.psprof files) or folders containing code profiling result files. If you specify a folder, the command looks for code profiling result files only at the top level of the folder and not in subfolders.

One or more space separated paths to code profiling filter files (.psprof.filter files).

Path to JSON file containing report customization options.

For more information on report customization JSON files, see Customize Content and Style of Polyspace Test Reports.

Path to text file containing options to use with the polyspace-test -report command. The file must contain one option per line.

Tips

If you want test results from Polyspace Test™ to appear in an external interface, you can parse the XML reports generated from the test results. For more information on the XML structure, see the XSD file PolyspaceTestResults.xsd in polyspaceroot\polyspace\resources\polyspace_test_results. Here, polyspaceroot is the Polyspace installation folder, for instance, C:\Program Files\Polyspace\R2026a.

Version History

Introduced in R2023b

expand all