How Can We Help?
< All Topics
Print

Generate Code Coverage for msbuild C & C++ Projects

To generating code coverage for the msbuild project irrespective of the visual studio version in  Windows, you need to prefix rktracer to the msbuild command.

 

Examples:       

SL/No

Makefile command

with RKTracer tool

Description

1

msbuild

 

rktracer msbuild

rktracer msbuild

instruments all the source file in silent mode for multi conditions

2

 

rktracer -v msbuild

 

instrument all source files and displays verbose log for multi conditions

3

 

rktracer -v  -branch msbuild

 

instrument all source files and displays verbose log for branch/decision coverage

4

 

rktracer -v -r msbuild

instrument all source files and displays verbose log for multi conditions in raw mode. RAW mode coverage will be stored in the RK_MEM variable.

RKTracer tool internally checks the compiler used by the makefile variable and instrument all the source files compiled. By default, rktracer instruments for multi-condition, and you see the following code coverage information in the HTML report.

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

 

Example msbuild 

Step 1:Enable rktracer tool and rebuild application

msbuild project-name.sln /t:rebuild

TO

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

 

RKTracer preprocesses the source file with the below command

RKTracer instruments the preprocessed file with “c:\rktracer/lib/librklic-x86_64-w64-mingw32.exe ” and writes out the instrumented preprocessed file to “prime.ii” file. Also, it stores the metadata, structure of instrumentation, and copy of source file content in JSON file. The tool will refer rktracer.config for internal configuration at the time of instrumentation.

RKTracer automatically adds runtime at linking time.

 

 

Step 2:Test the Instrumented application.

You can do unit testing/integration testing. Let us go ahead and input values 2,5 and then quit testing.

Step 3:Generate Code Coverage HTML reports

Once you have the rk-coverage.txt file, you need to run the command “rkresults” to generate HTML reports. Ensure that you run the “rkresults” command in the project root folder or where we have the “rktracer” folder or in application working directory.

 

 

rkresults command will search coverage data file “rk-coverage.txt” and map with JSON files (generated during instrumentation) in the rktracer folder and generate the HTML reports. You can manually open the HTML report using index.html.

Generate code coverage for selected functions/files/folder

Generate coverage reports  for the selected folders

C:\project\sound\drivers\base\power\

C:\project\sound\drivers\base\power\firmware_loader\

C:\project\sound\drivers\core\

C:\project\sound\security\keys\

C:\project\sound\security\lockdown\

Suppose you need code coverage for source files from three different folders, i.e., core, keys, power, and ignore coverage for folders firmware_loader and lockdown. Edit rktracer.config in the RKTracer installation folder and go to the end of the file add the following information. 

ignore *.cpp

instrument */power/* */core/* */keys/*

never */firmware_loader/* */lockdown/*

ignore *.cpp = Ignores all C source files from instrumentation

Instrument = Instrument source files from given folders

never = ignore selected folder  

Generate coverage reports only for selected functions from three different files.

fun_X() in source-file-X 

fun_Y() in source-file-Y

fun_Z() in source-file-Z

Suppose you need code coverage for selected functions from three different files. Edit rktracer.config in the RKTracer installation folder and go to the end of the file and set the following variables as shown below.  

ignore *.cpp

instrument *source-file-X.cpp *source-file-Y.cpp *source-file-Z.cpp

function-ignore *

function-instrument fun_X() fun_Y() fun_Z()

ignore *.cpp = Ignore all C programming source files

instrument *file-X.cpp *file-Y.cpp *file-Z.cpp   = Instrument only these three source files.

function-ignore * = Then ignore all functions in the above three files.

function-instrument fun_X() fun_Y() fun_Z() = Don’t ignore these three functions from these three files from instrumentation.

Previous Generate Code Coverage for makefile Projects
Next Generate Code Coverage for NDK Projects
Table of Contents