Code Coverage for Device Drivers and Kernel
Code Coverage for Standalone Driver Module
How to generate Code Coverage for Standalone Driver Module (knetstat) and Testing in Kernel
Step 1: You need to patch the Linux kernel with the RKTracer patch.
patch -p1 < /home/rkvalidate/share/rktracer/01-rktracer.patch
Step 2: Build the knetstat Driver module with the command.
make CC=”rktracer -r aarch64-linux-gnu-gcc” ARCH=arm64 LD=aarch64-linux-gnu-ld
Step 3: Start kernel device or qemu 64-bit arm architecture emulator.
Step 4: Copy RKTracer instrumented knetnet.ko kernel object file to the kernel which is up and running
scp rkvalidate@192.168.15.129:*.ko
Step 5: Load and test knetnet.ko kernel object file to the kernel with command “insmod knetstat.ko”
Step 6: Save code coverage data to the RK_MEM.raw file.
cat /proc/RK_MEM.raw > RK_MEM.raw
Step 7: Copy “RK_MEM.raw” to the host build system to knetstats kernel module folder.
Step 8: Generate reports using command rkresults.
Code Coverage for kernel file system
Generate code coverage for a kernel file system using the RKTrace tool
Step 1: You need to patch the Linux kernel with the RKTracer patch.
patch -p1 < /home/rkvalidate/share/rktracer/01-rktracer.patch
Step 2: Since we have added the patch, you should be able to see “Enable RKTRacer RK_MEM[]” make sure it’s enabled and then add “CC:=rktracer -r ${CC}” fs makefile of the file system which needs to be instrumented
Step 3: Test file system in kernel mode by running/execute test “./runltp -s fs” to run the test suite.
Step 4: Now load the rkmem.ko, this is the interface to copy the coverage data which is already in memory ” insmod /lib/modules/4.19.16/kernel/drivers/char/rkmem.ko”
Step 5: Save code coverage data.
cat /proc/RK_MEM.raw > RK_MEM.raw
Step 6: Copy “RK_MEM.raw” to the host build system and generate reports using command rkresults.
Enable coverage for selected files
Generate coverage reports for the selected folders
C:projectsounddriversbasepower
C:projectsounddriversbasepowerfirmware_loader
C:projectsounddriverscore
C:projectsoundsecuritykeys
C:projectsoundsecuritylockdown
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