Generate Reports of C/C++ Test Results Using Python API for Polyspace
You can generate reports at various points during your development cycle to capture a snapshot of your project for archiving or certification purposes. The reports summarize the results in an easy to parse HTML format, or in an XML format that you can then pass to other tools for further processing.
Prerequisites
Make sure you are using a supported Python® version and you are able to import the polyspace.project and polyspace.test
Python modules without errors. For more information, see Set Up Python API for Polyspace.
Import Modules
Import the modules polyspace.project and polyspace.test:
import polyspace.project
import polyspace.test
import osCreate Project and Add Files
To create a project, use the polyspace.project module.
examples_path = os.path.join(polyspace.__install_path__, "polyspace",
"examples", "pstest", "Getting_Started_Example")
polyspaceProject = polyspace.project.Project("getStarted")
polyspace.project.Project object polyspaceProject and a project file getStarted.psprjx in the current folder.Use the properties of polyspaceProject to add source and xUnit test files to the project.
# Add source code files
polyspaceProject.Code.Files.add(os.path.join(examples_path, "sources", "utils.c"))
polyspaceProject.IncludePaths.add(os.path.join(examples_path, "includes"))
# Add test file
polyspaceProject.Tests.Files.add(os.path.join(examples_path, "tests", "test.c"))Build and Run Tests
To build and run the tests in the project, use the polyspace.test.run() method.
res = polyspace.test.run(polyspaceProject)polyspace.test.run() method runs the executable without rebuilding first.Generate Reports from Test Results
Create a report from the generated results. Specify during report generation that only failed assessments must be reported and test specifications must be reported along with test results.
res.generateHTMLReport("path/to/reports", ReportPassedAssessments=False, GenerateSpecificationReport=True)generateHTMLReport() method. To generate an XML report instead, use the generateXMLReport() method. For more information on the reporting methods and associated reporting options, see the public methods of the polyspace.test.TestResults class.Note that report generation can lead to several HTML files being produced, one for each test suite. Each HTML is named after the test suite that was executed. To avoid confusion with reports from previous runs, select a location that does not already have existing HTML files.
For more information on the contents of the report, see Structure of HTML Reports Generated from C/C++ Test Results.
See Also
polyspace.test.run | polyspace.test.build | polyspace.project.Project | polyspace.project.OwnedBuildConfiguration | polyspace.project.OwnedStaticAnalysisConfiguration | polyspace.project.OwnedTestConfiguration | polyspace.test.TestResults