Product
Solutions
Resources
Company
Download Trial Book a Demo

Code Coverage for the Makefile Build System

Generate code coverage for a Makefile project with RKTracer. Prefix the rktracer command to your make or nmake build, run your tests on the host or the target, and produce an HTML report.

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.

In short

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 command options
rktracer make
rktracer -v make
rktracer -v -branch make
rktracer -v -r make
  • rktracer make instruments all source files in silent mode for multi-condition code coverage.
  • rktracer -v make instruments all files with verbose logging for multi-condition code coverage.
  • rktracer -v -branch make uses verbose logging with branch / decision coverage.
  • rktracer -v -r make uses raw mode coverage stored in the RK_MEM variable.
Default coverage metrics

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.

with rktracer
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.

generate the report
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:

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.

Coverage for selected functions

To generate coverage only for specific functions in specific files, edit rktracer.config:

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 *.c ignores all C source files.
  • instrument *source-file-X.c *source-file-Y.c *source-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 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.

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.