Main Content

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

Using Polyspace® Test™, you can author C/C++ tests on your host computer and execute them on a target. You can follow one of these two possible workflows:

  • Using a Polyspace Test project — If you have a Polyspace Test project containing your source file and tests, you can run the tests on your target hardware by registering a your target board in the project. Register your target board by using a registration file, which is a MATLAB® file that sets up the connection between your target and Polyspace Test. You can execute this workflow either in the Polyspace Platform user interface or by using the Polyspace Test command line interface.

  • Without using a Polyspace Test project — If you have xUnit API-based tests, then you cross-compile your source files with the tests to create a test executable. Run the tests on your target hardware by executing the test executable on the target. This workflow does not require a Polyspace Test project.

This example shows how to execute your tests programmatically on your target hardware by using a Polyspace Test project.

Prerequisites

To perform this workflow:

Execute Tests on Target

To execute tests on a target, register the target using a registration file. A registration file for your target board helps Polyspace Test build appropriate test executables for your target, establish communication with the target, and run the executable on the target. When the target is correctly registered, Polyspace Test manages these parts of the workflow automatically.

Register Target

Register the target board by using a registration file that defines:

  • Your target and the toolchain you need for the target.

  • Communication interface between Polyspace Test and the target.

After registering a target, you can subsequently run any project on the target.

To register a target in Polyspace Test, at the command prompt, enter:

polyspace-test -manage-target-package -register-from-file <Path_to_Package.m> 
Here, <Path_to_Package.m> is the path to the registration file. After registering the target, verify that you can see your board and toolchain listed among the registered boards and toolchains:
polyspace-test -manage-target-package -list Board
polyspace-test -manage-target-package -list Toolchain
If you do not see your board or toolchain, check the registration file and see if it correctly defines your board and toolchain.

Your registration file can be a single *.m file or it might require several additional supporting .m files. Keep the supporting files in a single folder and specify this folder as the environment variable MATLABPATH. You can use the commands setenv or export in your UNIX® shell:

setenv MATLABPATH <Path_to_Package.m>
export MATLABPATH=<Path_to_Package.m>
Setting this environment variable allows Polyspace Test to access the supporting files.

Run Tests on Target

Once you register the target, you can run tests on the target. At the command line, enter:

polyspace-test -run -project <project>.psprjx -board <myBoard> -toolchain <myToolchain> -results-dir <TestResults>
Here:

  • <project.psprjx> is the Polyspace Test project that you want to run on the target.

  • <myBoard> is the name of the target board. The name is defined in the registration file.

  • <myToolchain> is the name of the toolchain required to build test executables for the target. The toolchain is defined in the registration file.

  • <TestResults> is the folder where Polyspace Test stores the results.

After running the tests on you target, verify that the *.pstestr file is stored in the TestResults folder.

Create Report

To create a human-readable HTML report based on the *.pstestr data, at the command line, enter:

polyspace-test -report -html -report-dir reportFolder TestResults
Polyspace Test creates the HTML report in reportFolder.

Unregister Target

After completing your dynamic testing, you might want to unregister the target. At the command line, enter:

 polyspace-test -manage-target-package -unregister-from-file <Path_to_Package_removal.m>
Here, <Path_to_Package_removal.m> is the MATLAB file that unregisters the registration file.

See Also

| |

Topics