覆盖率coverage

cpp 覆盖率

options

  • compile: -fprofile-arcs, -ftest-coverage
  • link: -lgcov

或者:

  • compile: --coverage
  • link: --coverage

详情参见:https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Instrumentation-Options.html

编译完后会产生*.gcno, *.gcda 文件

lcov

用lcov 收集数据

## *.gc?? 数据在gcda_dir下, 源代码路径在 src_dir, gcov_info_file 是gcov数据文件
## 用--no-external 排除掉不在前二者目录下的数据 
lcov --no-external -c -d {gcda_dir}  -b {src_dir} -o {gcov_info_file} 
## --extract 提取匹配 src 的文件  
lcov --extract {gcov_info_file} "*src*" -o {gcov_info_file} 
## --remove 去掉 匹配 unittest, odb 的文件  
lcov --remove {gcov_info_file} "*unittest*" "*odb*" -o {gcov_info_file} 
## 在output_dir 下生成html 的报告 
genhtml -o {output_dir} {gcov_info_file} --demangle-cpp

ref:

  • http://ltp.sourceforge.net/coverage/lcov/lcov.1.php
  • https://wiki.documentfoundation.org/Development/Lcov#Run_lcov_again_after_tests.2Fchecks_complete

scons

有几个用scons 集成gcov的项目

  • https://github.com/ptomulik/scons-tool-gcccov
  • https://github.com/sansajn/test/tree/master/scons/soname
  • https://sansajn.github.io/post/2021/03/17/coverage-report.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值