メインコンテンツ

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 polyspaceroot\polyspace\examples\doc_pstest\execute_on_target to a writable location. Here, polyspaceroot is the Polyspace installation folder, for instance, C:\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 target myTarget using the MATLAB function target.create (Embedded Coder), and adds it to the repository of registered targets using the function target.add (Embedded Coder).

  • customPackageRemove.m: This file removes the target myTarget from the repository of registered targets using the function target.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:

  1. 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.

  2. On the Polyspace Platform toolstrip, select Mange Boards button in the Prepare section, and then select Manage Boards.

  3. In the Manage Boards window, select Register a target.

  4. Navigate to the file customPackage.m and 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.

  1. Create a new project.

  2. On the Projects pane, right-click the Code node and select Add Source Files(s). Add the file factorial.c to your project.

  3. On the toolstrip, click Parse Code. The function factorial() appears as a testable function.

  4. Right-click the factorial() function and select Add Test Case. Specify the following information in the test.

    Test InformationTest Data
    Inputn = 1
    Assessmentpst_call_out == 1

Select Target in Configuration

Select the previously registered target myTarget in your project configuration.

  1. Double-click the Configuration node of the project.

  2. 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.

  1. On the Polyspace Platform toolstrip, select Build Project.

  2. 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.

  1. On the toolstrip, locate the Profiling section and select Code Coverage.

  2. Select Build Project.

    Polyspace Test instruments the source file for code coverage calculation, and builds the instrumented sources along with tests.

  3. 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:

  1. On the Polyspace Platform toolstrip, select Mange Boards button in the Prepare section, and then select Manage Boards.

  2. In the Manage Boards window, select Unregister a target.

  3. Navigate to the file customPackageRemove.m and select the file.

See Also

| | |

Topics