5

我正在尝试使用Linux 测试项目中的一些测试场景并获取内核源代码覆盖率

我正在使用 GCOV/LCOV 这样做。

这是我到目前为止的东西:

  • 构建配置中的 GCOV 标志

基于 GCOV 的内核分析

CONFIG_GCOV_KERNEL=y

CONFIG_GCOV_PROFILE_ALL=y

Linux内核版本:2.6.32.60+drm33.26

  • 构建内核后,我在源文件夹中有所有 .gcov 文件
  • 当我使用源文件作为输入时,GCOV/LCOV 工作

我应该拥有但我没有的东西

  • /Proc/GCOV 文件夹
  • GCOV 内核模块 (gcov.o?)

现在我想要的是运行测试场景并使用 LCOV 获取到目前为止已使用的 Linux 内核代码部分。但是当我调用 LCOV -c 时,即使所有构建标志都正常,这也是我得到的。

加载所需的 gcov 内核模块。

lcov: 错误: 无法加载所需的 gcov 内核模块!

< 2.6.30 有一个内核补丁,然后它被内置。

4

2 回答 2

3

下面是我对 ubuntu 12.04 默认内核的尝试。以为 gcov 未启用,但已安装调试 fs,并且可以在其中找到一些 kvm 调试信息。

ubuntu:/sys/kernel# mount -t debugfs none /sys/kernel/debug
mount: none already mounted or /sys/kernel/debug busy
mount: according to mtab, none is already mounted on /sys/kernel/debug
ubuntu:/sys/kernel# umount /sys/kernel/debug
ubuntu:/sys/kernel# mount -t debugfs none /sys/kernel/debug
ubuntu:/sys/kernel# ls debug
acpi  bdi  bluetooth  extfrag  gpio  hid  kprobes  kvm  mce  regmap  regulator  sched_features  suspend_stats  tracing  usb  wakeup_sources  x86
ubuntu:/sys/kernel# cat debug/kvm/
efer_reload          host_state_reload    io_exits             mmio_exits           mmu_pte_write        nmi_window           signal_exits
exits                hypercalls           irq_exits            mmu_cache_miss       mmu_recycled         pf_fixed             tlb_flush
fpu_reload           insn_emulation       irq_injections       mmu_flooded          mmu_shadow_zapped    pf_guest
halt_exits           insn_emulation_fail  irq_window           mmu_pde_zapped       mmu_unsync           remote_tlb_flush
halt_wakeup          invlpg               largepages           mmu_pte_updated      nmi_injections       request_irq
ubuntu:/sys/kernel# cat debug/kvm/io_exits
467789515
ubuntu:/sys/kernel#
于 2013-01-15T05:10:07.040 回答
3

请阅读这份文件

http://www.mjmwired.net/kernel/Documentation/gcov.txt

以下是您的问题的答案:

  1. 没有用于内核覆盖的 proc fs。从新的 kenrel 启动后,您必须通过命令安装 debug-fs:“mount -t debugfs none /sys/kernel/debug”并从此文件中读取内核的覆盖日志

  2. 内核覆盖率不能构建为模块。如您所见,CONFIG 选项是“Y”,而不是“M”

于 2012-12-28T06:57:16.767 回答