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.
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 msbuild rktracer -v msbuild rktracer -v -branch msbuild rktracer -v -r msbuild
rktracer msbuildinstruments all source files in silent mode for multi conditions.rktracer -v msbuildinstruments all source files with verbose logging for multi conditions.rktracer -v -branch msbuildinstruments with verbose logging for branch/decision coverage.rktracer -v -r msbuildinstruments in raw mode; coverage is stored in theRK_MEMvariable.
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:
msbuild project-name.sln /t:rebuild
Prefix rktracer (here with the verbose flag -v) to enable the coverage tool:
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.
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:
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:
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.