Use this guide to generate code coverage for an application that uses the Makefile build system. RKTracer enables coverage by prefixing the rktracer command to your build command, and the code is instrumented during compilation. The runtime libraries are added to the build automatically, so you can run the instrumented application on a native host or on an embedded system and then generate the coverage report.
Change make to rktracer make (or nmake to rktracer nmake) to build and instrument, run your tests, then run rkresults to generate the HTML report.
RKTracer command options
Depending on the coverage you need and the verbosity of the logging, you can prefix the rktracer command in several ways. Each of the following can be used with make or with nmake.
rktracer make rktracer -v make rktracer -v -branch make rktracer -v -r make
rktracer makeinstruments all source files in silent mode for multi-condition code coverage.rktracer -v makeinstruments all files with verbose logging for multi-condition code coverage.rktracer -v -branch makeuses verbose logging with branch / decision coverage.rktracer -v -r makeuses raw mode coverage stored in theRK_MEMvariable.
By default, RKTracer reports Function Coverage, Line Coverage, Statement Coverage, and Multi-Condition Code Coverage.
Step 1: Enable the RKTracer tool
Prefix the rktracer command to your build command. Change the make command to rktracer make to build and instrument the project.
rktracer make
What happens during instrumentation
RKTracer preprocesses each source file, then instruments the preprocessed file with the bundled librklic instrumentor. It also stores the metadata, the structure of the instrumentation, and a copy of the source file content to corresponding JSON files. The runtime libraries are added automatically during linking.
Step 2: Run your tests on the instrumented application
Run your unit, integration, and functional tests against the RKTracer-instrumented application, on a native host or on an embedded system. As the instrumented application runs, RKTracer captures the coverage data and writes the coverage data file (rk-coverage.txt).
Step 3: Generate the HTML coverage report
Once you have the rk-coverage.txt file, run the rkresults command to generate the HTML reports.
rkresults
The rkresults command maps the rk-coverage.txt coverage data file with the JSON files generated during instrumentation and generates the HTML reports.
Enable coverage for selected files and functions
You can scope coverage to specific folders, files, or functions by editing rktracer.config.
Coverage for selected folders
To instrument source files from some folders while ignoring others, edit rktracer.config:
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.
Coverage for selected functions
To generate coverage only for specific functions in specific files, edit rktracer.config:
ignore *.c instrument *source-file-X.c *source-file-Y.c *source-file-Z.c function-ignore * function-instrument fun_X() fun_Y() fun_Z()
ignore *.cignores all C source files.instrument *source-file-X.c *source-file-Y.c *source-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 instrumentation.
Next steps
Once your Makefile project reports coverage, the same RKTracer workflow applies across other build systems and IDEs. Browse the rest of the documentation, or read more about how RKTracer measures coverage through MC/DC.