View Code Coverage Output

After you have enabled code coverage, execute all test cases to completion, e.g., finishing at an empty while loop or idle state for a state machine. Then pause/halt execution automatically (_builtin_software_breakpoint) or manually.

If the code is still running, you can’t be sure if all of the coverage points have been executed.

To view code coverage, select Window>Debugging>Code Coverage.

No Add-On License

Figure 1: No Add-On License

MPLAB® Code Coverage Add-On License

  • Lines of covered code will be highlighted in the editor.
  • A summary report will be shown in the Code Coverage tab
Summary Report Display Description
File name Names of all files in the project
Address units covered Address units covered and executed
Address units not covered Address units covered but not executed
Coverage The Coverage percentage represents x/(x+y) where x =
address units covered and executed and y = address
units covered but not executed. x vs. y is shown visually
in the bar.
Figure 2: Code Coverage in MPLAB X IDE

Color Meanings

The meaning of colors in the Editor and on the Code Coverage tab are shown in the table below.

Color Name Meaning
Highlight_Color_Green_rc6.png Green Covered and Executed
Highlight_Color_Yellow_rc6.png Yellow Covered but not Executed
White/None Not Covered (for lines of code)

Address Units

An Address Unit (AU) can represent one or more program memory addresses. An instruction can consume a single AU, multiple AUs or a partial AU. For example, AVR® and dsPIC® instructions can consume multiple AUs, whereas MIPS® and ARM® instructions can consume partial AUs.

The AU coverage percentage will be greater than instruction coverage percentage if an instruction can consume multiple AUs. The AU coverage percentage will be less than instruction coverage percentage if an instruction can consume partial AUs.

Code Coverage Tab Buttons

Click on buttons in the left-side menu of this tab for the following functions.
GenerateHTMLReport_Icon.png Generate HTML Report. This report will show the same data presented in the Code Coverage window..
EditorHighlightToggle_Icon.png Toggle (enable/disable) color highlighting in the Editor window.
CCDisplayTools.png Open Project Properties to enable/disable code coverage.
© 2020 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.