Contenuto principale

Automate C/C++ Test Execution Using Polyspace Platform Projects

You can author C/C++ tests interactively in the Polyspace® Platform user interface but build and run the tests automatically on a continuous integration (CI) server. Automated test execution helps you avoid regressions when you change your source code during software development.

This topic describes the basics of automated test execution using Polyspace Platform projects.

Build and Run Tests

Once you have added sources and tests to a Polyspace Platform project, you can build and run the tests at the command line:

  • To build the tests in a project myProject.psprjx, use this command:

    polyspace-test -build -project myProject.psprjx

  • To run the tests in a project myProject.psprjx, use this command:

    polyspace-test -run -project myProject.psprjx
    When you run tests in a project, the test execution uses build information from the previous build. If you did not build the tests beforehand, attempting to run the tests triggers a project build, followed by execution of the tests.

You can check the overall status of the test build or run by checking the exit code of the polyspace-test command. The exit code is 0 only if the build or run completes without errors.

To determine if there were test failures, you have to check the test results. Unless you specify a results file name or results folder, the test results are generated in a file ps_test.pstestr in a subfolder results in the current folder. You can review the results in the Polyspace Platform user interface or the Polyspace Access™ web interface.

Instead of running all tests in a project, you can run only tests in a specific suite. For instance, to run the test myTest in a suite mySuite, use this command:

polyspace-test -run -project myProject.psprjx -test mySuite/myTest

Upload Results to Polyspace Access

In a CI workflow, you can upload the results of test execution to a Polyspace Access web server so that multiple reviewers can review the test results in a web browser.

For example, to upload the results from a folder results in the current folder to a folder public/test_results_myProject in the Polyspace Access instance hosted on a server with hostname my-server, use this command:

 polyspace-access -upload results -host my-server -parent-project public/test_results_myProject

You can also download a result from Polyspace Access using the command polyspace-access -download. You can then open the result on your desktop in the Polyspace Platform user interface or generate reports from the results using the polyspace-test command.

See Also

| | | (Polyspace Access) | (Polyspace Access)

Topics