Product
Solutions
Resources
Company
Download Trial Book a Demo

Code Coverage for Microchip MPLAB IDE

Generate code coverage for embedded applications in Microchip MPLAB X IDE using the RKTracer tool, in three simple steps: enable RKTracer and rebuild, test the instrumented application on the target, then generate the coverage reports.

Generate code coverage for embedded applications in Microchip MPLAB IDE using the RKTracer tool with three simple steps:

  1. Enable the RKTracer tool and rebuild the application.
  2. Test the instrumented application and save the coverage data.
  3. Generate the code coverage reports.

Code coverage tool integration with MPLAB IDE

Ensure you have only one instance of MPLAB IDE opened. Go to Tools > Plugins Download and go to the MPLAB X Plugin Manager.

Select the Downloaded tab, then Add Plugin and select the RKTracer tool plugin com-rkvalidate-nb.nbm for MPLAB IDE from the RKTracer tool installation folder:

plugin location
C:\rktracer\share\rktracer-plugins

Restart the MPLAB IDE, and you should be able to see the RKTracer tool options in the Tools menu.

Prerequisites

Once you have successfully integrated the RKTracer tool, you need to build and test the application on the embedded target in debug mode at least once, and restart the IDE.

Step 1: Enable the RKTracer tool

The RKTracer options in the Tools menu are:

  • RKTracer ON: will enable the RKTracer tool for instrumentation.
  • RKTracer OFF: will disable the RKTracer tool.
  • RKTracer Reports: will generate reports in HTML format.

Go to Tools > RKTracer ON. When you enable the RKTracer tool for the first time, you will see a popup message; click OK.

Step 2: Rebuild the application and run your tests

Coverage data is saved automatically when you terminate the debug process after running the test case on the embedded target. Once testing is complete, the RKTracer tool saves the coverage data to the RK_MEM.raw file in the application working folder.

Step 3: Generate the code coverage reports

Go to Tools > RKTracer Report to generate the HTML reports. The RKTracer tool internally converts the RK_MEM.raw data file to rk-coverage.txt, maps it with the JSON files (generated during instrumentation) in the rktracer folder, and generates the HTML reports. You can manually open the HTML report using index.html.

Enable coverage for selected files

Edit rktracer.config in the RKTracer installation folder, go to the end of the file, and add the following information:

rktracer.config
ignore *.c
instrument */power/* */core/* */keys/*
never */firmware_loader/* */lockdown/*
  • ignore *.c ignores all C source files from instrumentation.
  • instrument instruments source files from the given folders.
  • never ignores the selected folders.

To generate coverage only for specific functions in specific files, add the following instead:

rktracer.config
ignore *.c
instrument *file-X.c *file-Y.c *file-Z.c
function-ignore *
function-instrument fun_X() fun_Y() fun_Z()
  • ignore *.c ignores all C programming source files.
  • instrument *file-X.c *file-Y.c *file-Z.c instruments only these three source files.
  • function-ignore * then ignores all functions in the above three files.
  • function-instrument fun_X() fun_Y() fun_Z() does not ignore these three functions from these three files from instrumentation.

Stuck on your build?

Open a support ticket and an engineer who knows your toolchain will help. You get a tracked ticket ID by email.