lcov使用方法

lcov统计结果示例:http://ltp.sourceforge.net/coverage/lcov/output/index.html

 

lcov的具体功能和使用,在linux(如ubuntu)中使用命令即可看到,如下:

deliadong@deliadong-virtual-machine:~$ lcov --help
Usage: lcov [OPTIONS]

Use lcov to collect coverage data from either the currently running Linux
kernel or from a user space application. Specify the --directory option to
get coverage data for a user space program.

Misc:
  -h, --help                      Print this help, then exit
  -v, --version                   Print version number, then exit
  -q, --quiet                     Do not print progress messages

Operation:
  -z, --zerocounters              Reset all execution counts to zero
  -c, --capture                   Capture coverage data
  -a, --add-tracefile FILE        Add contents of tracefiles
  -e, --extract FILE PATTERN      Extract files matching PATTERN from FILE
  -r, --remove FILE PATTERN       Remove files matching PATTERN from FILE
  -l, --list FILE                 List contents of tracefile FILE
      --diff FILE DIFF            Transform tracefile FILE according to DIFF
      --summary FILE              Show summary coverage data for tracefiles

Options:
  -i, --initial                   Capture initial zero coverage data
  -t, --test-name NAME            Specify test name to be stored with data
  -o, --output-file FILENAME      Write data to FILENAME instead of stdout
  -d, --directory DIR             Use .da files in DIR instead of kernel
  -f, --follow                    Follow links when searching .da files
  -k, --kernel-directory KDIR     Capture kernel coverage data only from KDIR
  -b, --base-directory DIR        Use DIR as base directory for relative paths
      --convert-filenames         Convert filenames when applying diff
      --strip DEPTH               Strip initial DEPTH directory levels in diff
      --path PATH                 Strip PATH from tracefile when applying diff
      --(no-)checksum             Enable (disable) line checksumming
      --(no-)compat-libtool       Enable (disable) libtool compatibility mode
      --gcov-tool TOOL            Specify gcov tool location
      --ignore-errors ERRORS      Continue after ERRORS (gcov, source, graph)
      --no-recursion              Exclude subdirectories from processing
      --to-package FILENAME       Store unprocessed coverage data in FILENAME
      --from-package FILENAME     Capture from unprocessed data in FILENAME
      --no-markers                Ignore exclusion markers in source code
      --derive-func-data          Generate function data from line data
      --list-full-path            Print full path during a list operation
      --(no-)external             Include (ignore) data for external files
      --config-file FILENAME      Specify configuration file location
      --rc SETTING=VALUE          Override configuration file setting
      --compat MODE=on|off|auto   Set compat MODE (libtool, hammer, split_crc)

For more information see: http://ltp.sourceforge.net/coverage/lcov.php
deliadong@deliadong-virtual-machine:~$ 

 

 

我这里针对两个方面做一下笔记:

(1)设置lcov统计“branch coverage”的方法

    Lcov1.10及往后)默认是关闭 分支覆盖率的。 
需要将/etc/lcovrc~/.lcovrc文件修改为:

# Include branch coverage data display (can be disabled by the
# --no-branch-coverage option of genhtml)
genhtml_branch_coverage = 1

# Specify if branch coverage data should be collected and processed.
lcov_branch_coverage = 1

(2)设置文件过滤的方法

在某些情况下,比如三方库不需要统计覆盖率信息,则需要屏蔽,或者只需要某些文件的覆盖率,就需要对文件进行筛选。

A) 正向提取需要的文件:

lcov --capture --directory ${COV_BINARY_DIR} -o ${COV_TEST}
lcov -a ${COV_BASE} -a ${COV_TEST} -o ${COV_TOTAL}

//把source相关的路径提取出来

lcov --extract ${COV_TOTAL} "*/source/*" --output-file ${COV_TOTAL}

//产生的xml就包含所有source相关的文件

genhtml -o ./${COV_PROJECT} -t "${PROJECT} coverage" --num-spaces 4 ${COV_TOTAL}

 

B) 反向去除不需要的文件:

//比如希望去除test和3rdparty相关文件:

lcov --remove ${COV_TOTAL} "*/test/*" --output-file ${COV_TOTAL}

lcov --remove ${COV_TOTAL} "*/3rdparty/*" --output-file ${COV_TOTAL}

//产生的xml就去除了test和/3rdparty/相关的文件

genhtml -o ./${COV_PROJECT} -t "${PROJECT} coverage" --num-spaces 4 ${COV_TOTAL}

 

注意:lcov 不允许同时使用--extract  和  --remove
 

 

 

  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小帆别吃糖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值