主要内容

Overview of Polyspace Test CMake Package

CMake is a third-party, open source tool for build process management that allows you to specify the build instructions for your code base in a platform and toolchain independent CMake language. When using CMake, you:

  1. Create a CMakeLists.txt file that contains the build instructions in the CMake language.

  2. Invoke the cmake command that uses the CMakeLists.txt file to generate standard build files. These include makefile and Ninja, as well as Microsoft® Visual Studio® and Xcode project builds.

To learn more about CMake, see the CMake Tutorial.

Polyspace® Test™ includes a CMake package that supplements the standard CMake API with additional variables, targets, and functions. You can use this package to manage testing and profiling workflows including:

  • Instrumenting source code for profiling

  • Linking source and test targets to the pstunit target to create an executable

  • Converting test and code profiling results to standard Polyspace Test formats

  • Generating XML and HTML reports from test and code profiling results

Prerequisites and Supported Testing Frameworks

To use the Polyspace Test CMake package (pstest package), you must have CMake version 13.0.0 or higher.

The pstest CMake package supports tests authored using:

  • Polyspace Test xUnit API

  • GoogleTest framework

pstest Targets

Suppose that you author tests using the Polyspace Test xUnit API. In your CMakeLists.txt file, once you define a target for your test executable, you must link this target against the Polyspace Test C or C++ target. To simplify this workflow, the Polyspace Test CMake package includes these two targets:

  • pstest::pstest_c

  • pstest::pstest_cpp

For example, suppose that your C++ test executable is named testRunner. To link this executable against your source library sourceLib and the Polyspace Test C++ target, include this command in your CMakeLists.txt file:

target_link_libraries(testRunner sourceLib pstest::pstest_cpp)

pstest Functions

When authoring your CMakeLists.txt file, you can use these functions in addition to the standard CMake API.

FunctionDescription

pstest_add_profiling_runtime

Create target for compiling a custom run-time library for code profiling

pstest_instrument_target

Instrument a target for profiling

pstest_add_convert_target

Create target for converting test or code profiling results to standard Polyspace Test format

pstest_add_report_target

Create target for generating XML and HTML reports from test or code profiling results

pstest Variables

To reference individual files and folders in polyspaceroot/polyspace/pstest/pstunit in your CMakeLists.txt file, use these variables. Here, polyspaceroot is the Polyspace Test installation folder, for example /usr/local/Polyspace/R2025a.

VariableDescription
pstest_INCLUDE_DIRS

Absolute path to the include folder.

pstest_SRC_C

Absolute path to the src/pstunit.c file.

pstest_SRC_CXX

Absolute path to the src/pstunit.cpp file.

See Also

| | |

Topics