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
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/223481.html原文链接:https://javaforall.net
