Get Started with C/C++ Test Execution on Target
In context of test execution in Polyspace® Test™, the word target refers to embedded systems with specific processor architecture, cross-compilation tools, and channels for communication with a host computer.
You can run tests both graphical and xUnit tests added to a Polyspace Platform project on a custom target. The steps to execute tests on targets are similar to test execution on host. However, you must perform a one-time setup to register your target in the Polyspace Platform user interface. Registering a target involves writing a custom target registration file that defines one or more of the following:
Toolchain: Cross-compiler, build tool, and so on.
Board and processor: Board/processor name, data type support, timer functions, and so on.
Communication specifics: Channel, protocol, and so on.
This example demonstrates the workflow for running graphically authored tests on a target by using a Polyspace Platform project. The example defines a custom target that has the same architecture as the host computer and uses a GCC-based toolchain. You can extend the example to the specifics of your own target board.
Example Files
To follow this example, copy the content of the folder to a writable location. Here, polyspaceroot\polyspace\examples\doc_pstest\execute_on_target is the Polyspace installation folder, for instance, polyspacerootC:\Program Files\Polyspace\R2026a.
Register Target
This example defines a fake target board myTarget by copying the processor characteristics of your host computer. The target board is defined using classes from the Target Framework MATLAB® API. Though the target registration file uses MATLAB code, you can view or modify this file in any text editor. You do not need an installation of MATLAB to modify the file.
The example folder contains the following files to register and unregister the target:
customPackage.m: This file defines a custom targetmyTargetusing the MATLAB functiontarget.create(Embedded Coder), and adds it to the repository of registered targets using the functiontarget.add(Embedded Coder).customPackageRemove.m: This file removes the targetmyTargetfrom the repository of registered targets using the functiontarget.remove(Embedded Coder).
For more information on the structure of the target registration file, see Create Target Registration Packages for C/C++ Test Execution on Targets.
To register the custom target myTarget:
Open the Polyspace Platform user interface. For more information on how to open the user interface, see Write C/C++ Unit Tests in Polyspace Platform User Interface.
On the Polyspace Platform toolstrip, select
in the Prepare section, and then select Manage Boards. In the Manage Boards window, select Register a target.
Navigate to the file
customPackage.mand select the file.
If the target registration completes successfully, you can see the target myTarget in the list of available boards. If your file contains syntax or other errors, the target registration step leads to an error. The associated error message points to the issue with the target registration file.
Create Project and Add Tests
The example folder contains a simple source file factorial.c that contains a single function factorial(). Configure a Polyspace Platform project to test this function.
Create a new project.
On the Projects pane, right-click the Code node and select Add Source Files(s). Add the file
factorial.cto your project.On the toolstrip, click Parse Code. The function
factorial()appears as a testable function.Right-click the
factorial()function and select Add Test Case. Specify the following information in the test.Test Information Test Data Input n = 1Assessment pst_call_out == 1
Select Target in Configuration
Select the previously registered target myTarget in your project configuration.
Double-click the Configuration node of the project.
On the Build tab, from the dropdown for Target board name (Testing), select
myTarget.You can see the following changes:
The option Processor is set to the processor
myPILProcessor. You cannot change the processor.The option Compilation toolchain (Testing) is set to
myToolchain. You can, however, pick a different toolchain for compilation.
For more information on the options, see:
Run Test on Target
After registering myTarget, you can run the previously created test case on the target.
On the Polyspace Platform toolstrip, select Build Project.
Select Run Tests.
Polyspace runs the tests on target and shows the test results on the Results pane.
Calculate Code Coverage on Target
After registering myTarget, you can calculate the code profile on the target.
On the toolstrip, locate the Profiling section and select Code Coverage.
Select Build Project.
Polyspace Test instruments the source file for code coverage calculation, and builds the instrumented sources along with tests.
Select Run Tests.
Polyspace Test runs the tests on target and shows the test as well as profiling results on the Results pane.
Unregister Target
After completing your dynamic testing, you might want to unregister the myTarget:
On the Polyspace Platform toolstrip, select
in the Prepare section, and then select Manage Boards. In the Manage Boards window, select Unregister a target.
Navigate to the file
customPackageRemove.mand select the file.
See Also
polyspace-test -manage-target-package | polyspace-test -check-target-package | polyspace-test -build | polyspace-test -run