CONFIG_GCOV_KERNEL=y CONFIG_GCOV_PROFILE_ALL=y CONFIG_GCOV_FORMAT_AUTODETECT=y
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 ./test.sh # generate coverage info and generate webpage sudo lcov -c -o kerneltest.info sudo genhtml -o /var/www/html kerneltest.info