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”的方法
Lcov(1.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