Linux Test Project

gcov-kernel - a gcov infrastructure for the Linux kernel

About gcov-kernel

gcov-kernel enables code coverage measurements for the Linux kernel and kernel modules. It is based on GCC's gcov tool. gcov-kernel is available as a set of patches for Linux kernels 2.6.4 to 2.6.30. Starting with Linux kernel 2.6.31, gcov-kernel is part of the Linux kernel and can be used without extra patches.

Using gcov-kernel (Linux 2.6.31 and above)

Example: (assumes that Linux source code is installed in directory /tmp/linux)

  1. Obtain the Linux kernel source code
  2. Enable the gcov-kernel configuration options:
    CONFIG_GCOV_KERNEL=y
    CONFIG_GCOV_PROFILE_ALL=y
  3. Compile, install and boot the kernel
  4. Mount the debugfs file system at mount point /sys/kernel/debug
    [root@host]# mount -t debugfs none /sys/kernel/debug
  5. Change to the kernel source tree
    [root@host]# cd /tmp/linux
  6. Run the gcov tool on a source code file
    [root@host]# gcov kernel/gcov/base.c -o /sys/kernel/debug/gcov/tmp/linux/kernel/gcov/
    File 'kernel/gcov/base.c'
    Lines executed:52.17% of 46
    kernel/gcov/base.c:creating 'base.c.gcov'
    
  7. Code coverage information for the specified source file can be found in the files created by gcov. Alternatively, use LCOV to obtain the information automatically.

Using gcov-kernel (Linux 2.6.30 and below)

Example: (assumes that Linux source code is installed in directory /tmp/linux)

  1. Obtain the Linux kernel source code
  2. Obtain and apply the corresponding gcov-kernel patch
  3. Enable the gcov-kernel configuration options:
    CONFIG_GCOV_PROFILE=y
    CONFIG_GCOV_ALL=y
    CONFIG_GCOV_PROC=y
  4. Compile, install and boot the kernel
  5. Change to the kernel source tree
    [root@host]# cd /tmp/linux
  6. Run the gcov tool on a source code file
    [root@host]# gcov lib/sort.c -o /proc/gcov/module/tmp/linux/lib/
    File '/tmp/linux/lib/sort.c'
    Lines executed:84.85% of 33
    /tmp/linux/lib/sort.c:creating 'sort.c.gcov'

Code coverage information for the specified source file can be found in the files created by gcov. Alternatively, use LCOV to obtain the information automatically.

Download

Source code: gcov-kernel is released under the GPL license. The latest patch versions can be found in the LTP CVS repository.

Comments And Questions

For comments and questions contact: ltp-coverage@lists.sourceforge.net


Sourceforge.net  Last modified on: July 12, 2010 - 15:40:07 UTC.
Theme: