Product
Solutions
Resources
Company
Download Trial Book a Demo

Code Coverage for the Visual Studio MSBuild System

Generate code coverage for a Visual Studio MSBuild project with RKTracer in 3 simple steps. Prefix the rktracer command to your msbuild build, run your tests on the host or the target, and produce an HTML report.

You will learn how to generate code coverage for MSBuild system applications using the RKTracer tool in 3 simple steps. You prefix the rktracer command to your msbuild commands, and the runtime libraries are added automatically during the build.

In short

Prefix rktracer to the msbuild command, run your tests, then run rkresults to generate the HTML report.

RKTracer command reference

Prefix the rktracer command to your msbuild command. The flags you add control the logging and the coverage metric.

rktracer commands
rktracer msbuild
rktracer -v msbuild
rktracer -v -branch msbuild
rktracer -v -r msbuild
  • rktracer msbuild instruments all source files in silent mode for multi conditions.
  • rktracer -v msbuild instruments all source files with verbose logging for multi conditions.
  • rktracer -v -branch msbuild instruments with verbose logging for branch/decision coverage.
  • rktracer -v -r msbuild instruments in raw mode; coverage is stored in the RK_MEM variable.

Coverage metrics generated

RKTracer generates the following coverage metrics:

  • Function Coverage
  • Line Coverage
  • Statement Coverage
  • Multi-Condition Code Coverage

Step 1: Enable the RKTracer tool

Prefix the rktracer command to your msbuild command. For example, if your original command is:

original msbuild command
msbuild project-name.sln /t:rebuild

Prefix rktracer (here with the verbose flag -v) to enable the coverage tool:

with rktracer
rktracer -v msbuild project-name.sln /t:rebuild

What happens during instrumentation

The tool preprocesses each source file, then instruments the preprocessed output to files (for example, prime.ii) and stores the metadata in JSON format. RKTracer adds the runtime automatically at linking time.

Step 2: Run your tests on the instrumented application

Execute your unit tests, integration tests, or functional tests on the instrumented application, on a native host or on an embedded system.

Step 3: Generate the HTML coverage report

Run the rkresults command to generate the HTML reports.

generate the report
rkresults

The rkresults command searches for the coverage data file rk-coverage.txt and maps it with the JSON files to generate the HTML reports. You can view the reports via index.html.

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 selected folders while ignoring others, add the following to rktracer.config:

rktracer.config
ignore *.c
instrument */power/* */core/* */keys/*
never */firmware_loader/* */lockdown/*

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()

Next steps

Once your MSBuild 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.

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.