How Can We Help?
< All Topics
Print

Generate and Publish Code Coverage in Jenkins

Integrate RKTracer, Generate and Publish Code Coverage in Jenkins

Install the RKTracer tool plugin in Jenkins.

Step 1: Login into Jenkins

 

Step 2: On the right-hand side, the column selects Manage Jenkins and then manage plugins.

 

Step 3: Go to the advanced tab and scroll down to the Upload plugin section.

 

Step 4: Now browser and navigate to plugin section in RKTracer installation folder “C:\rktracer\share\rktracer-plugins” and select the rktracer.hpi file to upload.



 

Step 5: After uploading, it takes some time to install and restart the Jenkins.



Now you’re all set to publish RKTracer coverage data to Jenkins.

Enable RKTracer tool Generate and Publish Coverage report in Jenkins

Step 1: Enable the RKTracer tool

Before the build command settings in the Jenkins job. You need to enable RKTracer, as shown below.

MSBUILD

 

DotNet Build

 

    

Build system

Command to enable RKTracer tool

msbuild 

“C:\rktracer\bin\rktracer.exe” -vs -on “C:\Program Files (x86)\Microsoft Visual Studio\2019\Community” “D:\path-to-project-solution-file\Demo.sln”


-vs= Visual Studio environment

-on= Enable RKTracer Tool 


We are using the absolute path of the RKTracer installation folder with VS IDE path and the Path to project solution file. Here RKTracer tool will take the project solution file as a reference to enable the RKTracer tool.

DotNet

“C:\rktracer\bin\rktracer.exe” -vs -on “C:\Program Files (x86)\Microsoft Visual Studio\2019\Community” “D:\path-to-project-solution-file\Demo.csproj”


-vs= Visual Studio environment

-on= Enable RKTracer Tool 


We are using the absolute path of the RKTracer installation folder with VS IDE path and path to the project solution file. Here RKTracer tool will take the project solution file as a reference to enable the RKTracer tool.



Step 2: Build and Test the application.

i.e., unit testing or functional testing.

 

Step 3: Disable the RKTracer tool.

Build system

Command to enable RKTracer tool

msbuild 

“C:\rktracer\bin\rktracer.exe” -vs -off “C:\Program Files (x86)\Microsoft Visual Studio\2019\Community” “D:\path-to-project-solution-file\Demo.sln”


-vs= Visual Studio environment

-off= Disable RKTracer Tool 


We are using the absolute path of the RKTracer installation folder with VS IDE path and the Path to project solution file. Here RKTracer tool will take the project solution file as a reference to enable the RKTracer tool.

DotNet

“C:\rktracer\bin\rktracer.exe” -vs -on “C:\Program Files (x86)\Microsoft Visual Studio\2019\Community” “D:\path-to-project-solution-file\Demo.csproj”


-vs= Visual Studio environment

-off= Disable RKTracer Tool 


We are using the absolute path of the RKTracer installation folder with VS IDE path and path to the project solution file. Here RKTracer tool will take the project solution file as a reference to enable the RKTracer tool.



Step 4:  Generate HTML and XML reports.

 XML report rktracer.xml is to publish reports in Jenkins

 XML report rktracer-sonarqube.xml to publish generic reports to sonarQube.

c:\rktracer\bin\rkresults.exe  -xml 

-xml : will generate xml coverage reports along with HTML reports.

 

 

 

 

 

 

 

If you cannot find the rk-coverage.txt file in the project working folder, the tests have not exited the application with the proper exit handler, i.e., atexit() handler, or your application might be running in an infinite loop or live application.

Coverage data file not found after testing.

RKTracer tool uses the following approaches to save coverage data.

  • Run unit/functional testing, and at the end RKTracer tool will automatically save coverage data on the host/embedded target/server machine, that is, write coverage data to the rk-coverage.txt file.
  • Send a signal to the application running in an infinite loop to trigger and save coverage data. 
  • The application under test has crashed in the middle of testing on the host or target device. RKTracer saves coverage data to rk-coverage.txt and generate reports to check the point of a crash in reports.
  • Embedded devices without a file system or not connected to host while testing. In this case, rktracer RAW mode comes in to picture. You need to save the coverage data from the RKTracer variable. 

Suppose you cannot find the rk-coverage.txt file in the project working folder or target server machine. An application under test has not exited with the proper exit handler, i.e., atexit() handler, or your application might be running in an infinite loop. You can use the following two methods to save coverage data from memory to the file system.

Save coverage data when a particular function is executed at runtime testing.

Identify a function/method name in your application (ensure this function/method is not excluded from RKTracer instrumentation or file with this function). Then copy the function name and edit the rktracer.config in the RKTracer installation folder. 

For C programming language:  Add a new line at the end of rktracer.config file with “c-function-writeout” and function name. Here the function name is case sensitive, and you should also add empty braces, i.e., () at the end of a function name. In case if you have a function with an input parameter, it should still be empty braces. You can add multiple function names with one space to the list, as shown below.

  • c-function-writeout main()
  • c-function-writeout main()  OnCreate() fun()

For C++ programming language: Add a new line at the end of rktracer.config file with “c++-function-writeout” and function name. Here the function name is case sensitive, and you should also add empty braces, i.e., () at the end of a function name. In case if you have a function with an input parameter, it should still be empty braces. You can add multiple function names with one space to the list, as shown below.

  • c++-function-writeout main()
  • c++-function-writeout main()  OnCreate() fun()

After adding function name to rktracer.config file. You need to rebuild the application to re-instrument using rktracer. Coverage data will be saved to the rk-coverage.txt file when this function executes at runtime testing. 

Send a signal to save coverage data.

We can send a signal to the application running in an infinite loop to save coverage data to rk-coverage.txt.

  • Windows: send a kill signal using keys in the keyboard, i.e., Control+Pause/break. Contact support if you would like to add additional signal command to save coverage data at runtime testing.
  • Linux/Unix: Send a SIGWINCH signal: killall -SIGWINCH a.out or kill -SIGWINCH Process ID number. 

Step 5: Publish RKTracer Coverage reports in Jenkins.

You need to add “Publish RKTracer Coverage Reports” and don’t change the default setting.

 

 

 After build and testing the application, hit the refresh button on the browser. And now you will see the code coverage report

 

Click on that code coverage, and you will see the code coverage data.

 

To find this report go to the rktracer folder in the project directory and navigate to the report folder. Here you will find the RKTracer code coverage report in Html and XML reports for Jenkins and SonarQube.

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 Cpp 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 Cpp 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() = But instrument or don’t ignore these three functions from these three files.

Next Publish Code Coverage in Azure DevOps
Table of Contents