如何防止函数被排除在覆盖率分析之外?
我们使用 AQTime 的覆盖率分析器来检查单元测试的覆盖率结果。它似乎通常工作正常,但有一个令人讨厌的习惯,即高估覆盖范围,因为某些功能根本不出现。我认为这是因为链接器已经剥离了它们,因为它们没有被调用,但显然这并不理想,因为我希望它们显示为“未覆盖”。
有谁知道是否有一种方法可以配置 Visual C++ 或 AQTime,以便这些函数将被正确标记为“未涵盖”?
We're using AQTime's coverage profiler to check coverage results for unit tests. It seems to generally work okay, but has a nasty habit of overestimating coverage because some functions don't appear at all. I think this is because the linker has stripped them because they're not called, but obviously it is not ideal because I'd like them to show up as "not covered".
Does anyone know if there's a way to configure either Visual C++ or AQTime such that these functions will be correctly tagged as "not covered"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AQtime 从模块的调试信息中获取例程列表。由于链接器已剥离了一些例程,因此没有它们的调试信息,并且 AQtime 无法“看到”它们。
通常,所有链接器都可以选择启用/禁用此功能。例如,在 Visual C++ 项目中,此选项名为引用,位于链接器| 目录下。优化属性组。删除此选项的值或在应用程序的调试配置中将其设置为否 (/OPT:NOREF),链接器将不会删除未使用的内容功能。该选项记录在此处。
AQtime gets the list of routines from a module's debug information. Since the linker has stripped some routines, there is no debug information for them and AQtime does not "see" them.
As a rule, all linkers have an option to enable/disable this feature. For example, in a Visual C++ project this option is named References and located under the Linker | Optimization properties group. Remove the value of this option or set it to No (/OPT:NOREF) in your application's Debug configuration and the linker will not remove unused functions. The option is documented here.
奇怪的。无论编译器/链接器是否剥离它们,事实是,在测试执行结束时,没有它们被执行的记录。因此,如果该工具可以列出所有函数,那么它应该没有这样的证据,因此它应该报告“未执行”。
我们的 SD C++ 测试覆盖率 工具不会出现这种奇怪的行为,至少在以下情况下不会出现这种情况:您实际上指定了包含的编译单元或头文件是应该检测的部分的一部分。 (您可能无法列出包含函数体的头文件,并且不会报告)。它甚至会报告已内联的函数已被执行,无论已内联的位置有多少。
Odd. Whether the compiler/linker strips them or not, the fact is, at the end of test execution, there is no record of them being executed. So if the tool can list all the functions, it should have no such evidence, and thus it should report "not executed".
Our SD C++ Test Coverage tool does not have this bizarre behavior, at least not if you actually specify that the containing compilation unit or header file that is part of those that should be instrumented. (You might fail to list ah header file that contains a function body, and that won't then get reported). It will even report that a function, which has been inlined, has been executed, regardless of the number of places it has been inlined.