lcov使用方法

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
 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章