Introduction to code coverage
Reasons for using code coverage
The code coverage functionality is useful when you design your test procedure to verify whether all parts of the code have been executed. It also helps you identify parts of your code that are not reachable.
Briefly about code coverage
The Code Coverage window reports the status of the current code coverage analysis for C or C++ code. For every program, module, and function, the analysis shows the percentage of code that has been executed since code coverage was turned on up to the point where the application has stopped. In addition, all statements that have not been executed are listed. The analysis will continue until turned off.
For debug probes that support it, C-SPY can capture full instruction trace in real time, and process the information for the Code Coverage window.
Note
Assembler code is not covered in the Code Coverage window. To view code coverage for assembler code, use the Disassembly window.
Requirements and restrictions for using code coverage
Code coverage is supported by the C-SPY simulator for most cores and devices and if supported there are no specific requirements or restrictions.
To use code coverage in your hardware debugger system, consider these requirements and restrictions:
When SWO trace is used—code coverage information is based on trace samples only. This means that a function must be executed several times before 100% code coverage is reached. Also, no code coverage information is collected while single stepping.
When ETM trace is used—for some devices, code coverage can be of infinite length. Without this enhanced trace capability, the coverage length is restricted by the size of the trace buffer. For efficient use of the trace buffer, you can limit the trace data collection using the trace start and trace stop breakpoints.
Real-time code coverage requires that the debug probe supports this feature.
Run code coverage on non-optimized code, as optimizations will negatively affect code coverage.