主要内容

pstest_instrument_target

(CMake) Instrument a target for profiling

Since R2025a

Description

This function in the Polyspace® Test™ CMake package instruments a target for profiling using polyspace-code-profiler -instrument.

pstest_instrument_target(target profiling_type [LEVEL level]) instruments a target for profiling for a specified type and level by using polyspace-code-profiler -instrument.

example

pstest_instrument_target(target profiling_type [LEVEL level] [RUNTIME runtime]) allows you to specify the target runtime for a custom run-time profiling library that you create using pstest_add_profiling_runtime.

pstest_instrument_target(target profiling_type [LEVEL level] [RUNTIME runtime] [OPTIONS_FILE file]) allows you to specify an options file for configuring the profiling instrumentation.

pstest_instrument_target(target profiling_type [LEVEL level] [RUNTIME runtime] [OPTIONS_FILE file] [OTHER_ARGS arg1 arg2 ... argN]) allows you to specify additional options for configuring the profiling instrumentation.

Examples

collapse all

This example shows how to use instrument your source code to collect MC/DC coverage data. For an example that demonstrates the complete workflow, see Calculate Code Coverage of xUnit API-Based Tests Using CMake.

The files used for this example are available in the folder polyspaceroot/polyspace/examples/pstest/Getting_Started_Example. Here, polyspaceroot is the Polyspace Test installation folder, for example /usr/local/Polyspace/R2025a. Copy this folder to a writable location in your file system, such as /usr/data/Getting_Started_Example.

Add a library target for your source file utils.c. Specify the include folder for this target.

add_library(ecocar sources/utils.c)
target_include_directories(ecocar PUBLIC includes)

Instrument the ecocar target for calculating code coverage. Specify the coverage level as MC/DC.

pstest_instrument_target(ecocar COVERAGE LEVEL mcdc)

Input Arguments

collapse all

Target for your source code that you want to instrument.

Example: mycode

Whether you want to instrument your source code for calculating code coverage, execution time, or memory use.

The level of details for profiling your target, specified as one the following values:

  • For COVERAGE profiling type, specify as statement, decision, condition/decision, or mcdc

  • For EXECUTION or STACK profiling type, specify as minimal, standard, or detailed.

This argument is equivalent to the -cov-metric-level option of the polyspace-code-profiler function.

Name of target for custom profiling run-time library that you create using pstest_add_profiling_runtime.

Example: myruntime

Path to a text file containing one option per line. CMake forwards the file argument to the -options-file option of polyspace-code-profiler -instrument. See Instrument Source Files.

Example: options\instrum_options.txt

Additional profiling options that CMake forwards to polyspace-code-profiler -instrument. See Instrument Source Files.

Version History

Introduced in R2025a