How Can We Help?
< All Topics
Print

Generate Code Coverage for NDK Projects

To generate code coverage for the NDK-build based project in Windows and Linux, you need to prefix rktracer to ndk-build command and rebuild the application.

Example NDK-build

Step 1:Enable the RKTracer tool and rebuild the application.

ndk-build NDK_PROJECT_PATH=.  APP_BUILD_SCRIPT=.\app\Android.mk v=1

TO

rktracer ndk-build NDK_PROJECT_PATH=.  APP_BUILD_SCRIPT=.\app\Android.mk v=1

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 JSON file. RKTracer tool automatically adds runtime at linking time. The tool will refer to rktracer.config for internal configuration at the time of instrumentation.

Step 2: Testing instrumented application.

If you generate a shared library, push it to the target device or add it to application.apk.

Install the APK in the device.

By default, the RKTracer tool will autosave coverage data from the emulator or device to the app working folder in the build machine, provided the device or emulator is connected to the build machine. If the device/phone is not connected to the build machine at the time of testing, RKTracer coverage data will be saved in the logcat buffer and the testing device. You can later save coverage data from logcat log or pull coverage data from device to app folder in the build machine.

To pull the coverage data, you can execute the command. 

adb pull  /data/data/com.example.widecolor/rk-coverage.txt 

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 application root folder or where you have the “rktracer” folder generated at the time of build/Instrumentation.

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.

Previous Generate Code Coverage for msbuild C & C++ Projects
Next Generate Code Coverage for Windows Device Drivers
Table of Contents