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:
You require a valid Polyspace Platform project containing source files and tests.
You must have created a valid registration file for your target. For more information on target registration files, see Run C/C++ Tests on Target in Polyspace Platform User Interface.
You must have set up a host compiler for use with Polyspace Test. A host compiler is required for on-target execution, as certain generated source files need to be compiled on the host before cross-compiling your sources for the specified target.
For more information on how to set up a host compiler at the command line, see
polyspace-test -manage-host-compiler.For more information on host compiler requirements, see Specify C/C++ Compilers for Testing in Polyspace Platform User Interface.
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> polyspace-test -manage-target-package -list Board
polyspace-test -manage-target-package -list ToolchainYour 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>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><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 TestResultsreportFolder.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><Path_to_Package_removal.m> is the MATLAB file that unregisters the registration file.See Also
polyspace-test -manage-target-package | polyspace-test -build | polyspace-test -run