Tips and Tricks
Consider the following tips and tricks to get the code coverage you expect.
Simple Code
When performing code coverage on a simple program in main(), do not let the program simply end. Depending on the device, the code could reset or end up in an undefined state. This may interfere with code coverage calculation. It is suggested that you place something like a while(1) loop at the end of main(). Then to see code coverage, either:
- Place a breakpoint at the last brace of the while(1) loop. When you hit the breakpoint, step once to ensure you have completed the loop to see the coverage output.
- Let the code run for a while before hitting Pause. This will ensure that the while(1) loop was run (and covered) at least once. View coverage output.
Optimized Code
Different optimizations (-On) may result in different coverage of code. The code may be optimized so that it becomes smaller, faster, or more efficient in its operation. A code that is optimized for size will produce different coverage results from code that is optimized for speed.