为标题库获取有用的GCov结果 [英] Getting useful GCov results for header-only libraries

查看:257
本文介绍了为标题库获取有用的GCov结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的只有头的C ++库(大量模板等),我使用GCov来检查测试覆盖率。但是,它报告所有头的100%覆盖,因为未使用的函数不是由编译器首先生成的。手动识别未覆盖的函数很容易,但是破坏了连续集成的目的...

For my header-only C++ library (lots of templates etc) I use GCov to check test coverage. However, it reports 100% coverage for all headers because the unused functions aren't generated by the compiler in the first place. Manually spotting uncovered functions is easy but defeats the purpose of continuous integration…

如何自动解决?

推荐答案

除了使用覆盖率指标之外, GCC控制内联的常用标志;

Apart from the usual flags to GCC controlling inlining;

--coverage -fno-inline -fno-inline-small-functions -fno-default-inline

您可以在单元测试文件的顶部实例化模板类;

You can instantiate your template classes at the top of your unit test files;

template class std::map<std::string, std::string>;

这将为该模板类中的每个方法生成代码,使coverage工具完美工作。

This will generate code for every method in that template class making the coverage tools work perfectly.

此外,请确保您初始化您的* .gcno文件(因此对于lcov)

Also, make sure that you initialise your *.gcno files (so for lcov)

lcov -c -i -b ${ROOT} -d . -o Coverage.baseline
<run your tests here>
lcov -c -d . -b ${ROOT} -o Coverage.out
lcov -a Coverage.baseline -a Coverage.out -o Coverage.combined
genhtml Coverage.combined -o HTML

这篇关于为标题库获取有用的GCov结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆