Generate code coverage for embedded applications in Microchip MPLAB IDE using the RKTracer tool with three simple steps:
- Enable the RKTracer tool and rebuild the application.
- Test the instrumented application and save the coverage data.
- 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:
C:\rktracer\share\rktracer-plugins
Restart the MPLAB IDE, and you should be able to see the RKTracer tool options in the Tools menu.
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:
ignore *.c instrument */power/* */core/* */keys/* never */firmware_loader/* */lockdown/*
ignore *.cignores all C source files from instrumentation.instrumentinstruments source files from the given folders.neverignores the selected folders.
To generate coverage only for specific functions in specific files, add the following instead:
ignore *.c instrument *file-X.c *file-Y.c *file-Z.c function-ignore * function-instrument fun_X() fun_Y() fun_Z()
ignore *.cignores all C programming source files.instrument *file-X.c *file-Y.c *file-Z.cinstruments 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.