How Can We Help?
< All Topics
Print

Generate Code Coverage for Cmake Projects

To generate code coverage for the cmake-based project in Windows and Linux, you need to prefix rktracer to cmake command and run the cmake command to integrate the rktracer tool with the application.

  •  MinGW cmake
  •  nmake cmake
  •  GNU gcc cmake
  •  Microsoft visual studio cmake
 

Examples:       

SL/No

CMAKE command

with rktracer tool

 

1

cmake

rktracer cmake

instruments all the source file in silent mode for multi conditions

2

 

rktracer -v cmake

instrument all source files and displays verbose log for multi conditions

3

 

rktracer -v  -branch cmake

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

4

 

rktracer -v -r cmake

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

 

Example cmake build

Step 1:Enable RKTracer Tool

cmake -G “MinGW Makefiles” “D:\path-to-project\project.”

TO

rktracer -v cmake -G “MinGW Makefiles” “D:\path-to-project\project”

RKTracer tool finds the compiler used in cmake build and then, based on the compiler found makes necessary changes to the CMakeCache.txt file. Now run the “make” command to build and Instrument the project with the RKTracer tool.

Note: Prefixing the “rktracer” command to the “make” command will not work for the cmake build. You need to prefix rktracer to cmake command, not to “make” command.

Now, you can execute the make command.

  • 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.i” file. Also, it stores the metadata, structure of instrumentation, and copy of source file content to corresponding JSON files. Tool will refer rktracer.config for internal configuration at the time of instrumentation. 
  • RKTracer automatically adds runtime at linking time.

Step 2:Testing instrumented application.

You can do unit testing/integration testing. In this case, we will run unit tests.

 

We can also see coverage metrics written out to the rk-coverage.txt file. 

Post-testing the RKTracer tool will save coverage data to the rk-coverage.txt file. 

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.

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 *.c

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

never */firmware_loader/* */lockdown/*

ignore *.c = 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 *.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 = Ignore all C programming source files

instrument *file-X.c *file-Y.c *file-Z.c   = 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.

Next Generate Code Coverage for External Kernel module/ kernel file system
Table of Contents