Thursday, November 13, 2014

using gcov/lcov with the linux kernel

Enable the following in your kernel configuration:

Build the kernel and install headers/debug/images to your machine. Note there may be issues if you run this on a separate machine so consult the official documentation for additional information [1].

Reboot the machine and use the following to see it things work:
sudo apt-get install lcov gcc
SRC_PATH=~/src/linux # or whatever your path to your kernel tree is
gcov ${SRC_PATH}/kernel/sched/core.c -o /sys/kernel/debug/gcov/${SRC_PATH}/kernel/sched/

Obviously this would be useful for quick tests, but perhaps we want to test coverage after a test, and display results graphically. We can use lcov [2] to accomplish this using the following:
# reset counters
sudo lcov --zerocounters
# run test
# generate coverage info and generate webpage
sudo lcov -c -o
sudo genhtml -o /var/www/html