主要内容

使用自管理编译执行代码探查

R2026b
计算 C/C++ 源文件和 xUnit 测试的代码覆盖率、执行时间或内存使用

如果您使用 Polyspace Test xUnit API 编写 C/C++ 测试,则可以探查源文件和测试以计算代码覆盖率、代码执行时间或内存使用。在编译时对源代码进行插桩,然后使用 polyspace-test -monitor 运行测试以收集探查结果:

polyspace-code-profiler -instrument -instrum-dir instrums -cov-metric-level decision -- gcc -c src.c 
gcc -c test.c <PSTEST_SOURCE> <PSTEST_INCLUDE> # <PSTEST_SOURCE> is pstest.c
gcc src.o test.o pstest.o <PSTEST_LIB> -o testrunner
polyspace-code-profiler -run -instrum-dir instrums -results-dir results -- ./testrunner
有关文件路径 <PSTEST_SOURCE>、<PSTEST_INCLUDE> 和 <PSTEST_LIB> 的信息,请参阅Set Up C/C++ Testing and Code Profiling Using Self-Managed Builds。

系统命令

polyspace-code-profiler(System Command) Profile your source code for calculating C/C++ code coverage, code execution time, and memory use
polyspace-test -monitor(System Command) Monitor execution of C/C++ xUnit tests and retrieve test and code profiling results
polyspace-test -dccc(System Command) Generate Data Coupling and Control Coupling (DCCC) coverage data from static and dynamic results (requires Polyspace Code Prover)

CMake 函数

pstest_add_profiling_runtime(CMake) Create target for compiling a custom run-time library for code profiling
pstest_instrument_target(CMake) Instrument a target for profiling
pstest_add_convert_target(CMake) Create target for converting test or code profiling results to standard Polyspace Test format
pstest_add_report_target(CMake) Generate XML and HTML reports from test or code profiling results

MATLAB 函数

pstest.exportToPolyspaceProfilingResults(MATLAB Function) Export coverage results from Simulink Coverage, Simulink Test, or MATLAB Test to Polyspace Test

主题

疑难解答

Troubleshoot Code Profiling for Polyspace Test xUnit API-Based Tests

Troubleshoot calculating code coverage, execution profiling, and stack memory profiling of xUnit-based tests.