gcov 仅报告 header 的错误结果 class
gcov reporting wrong result for header only class
之前已经有很多人问过类似的问题了:
- Getting useful GCov results for header-only libraries
- Why does gcov report 0% coverage on a header file for a well used class?
仅举几例。但是 none 帮助我解决了我自己的问题。
我正在使用 gcc 版本 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
编译我的源代码
g++ -c -pipe -Wno-psabi -std=gnu++11 -Wextra -pedantic -fprofile-arcs -ftest-coverage --coverage -fno-inline -fno-inline-small-functions -fno-default-inline -O0 -fno-elide-constructors -g -Wall -W -o .obj/myclass.o unittest_myclass.cpp
然后我 运行 gcov (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4 在我的一个源文件上
gcov unittest_myclass.cpp -o .obj/
此文件仅包含 header class 的单元测试。 gcov 成功生成此 header 文件的覆盖率信息:
File '../include/myclass.h'
Lines executed:11.05% of 173
Creating 'myclass.h.gcov'
然而,myclass.h.gcov中的结果是错误的。对于大多数行,gcov 报告它们不包含可执行代码。对于那些它检测为可执行文件,它主要报告它们尚未执行。但我确信它们正在被执行(我在调试时验证了它,一些单元测试由于错误等而失败了)。不涉及模板。
因此我猜想由于某种原因 gcov 无法检测到正确的执行。正如您从我上面的命令行参数中看到的那样:优化已关闭,内联已关闭...
还有什么可能导致这些问题的想法吗?
似乎问题不在于我的 class 只是 header,而是我用
调用了 gcov
gcov unittest_myclass.cpp -o .obj/
如果我用
代替 运行
gcov *.cpp -o .obj/
它报告
File '../include/myclass.h'
Lines executed:95.56% of 248
Creating 'myclass.h.gcov'
生成的 myclass.h.gcov
文件看起来比我预期的要好得多。
之前已经有很多人问过类似的问题了:
- Getting useful GCov results for header-only libraries
- Why does gcov report 0% coverage on a header file for a well used class?
仅举几例。但是 none 帮助我解决了我自己的问题。
我正在使用 gcc 版本 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
编译我的源代码g++ -c -pipe -Wno-psabi -std=gnu++11 -Wextra -pedantic -fprofile-arcs -ftest-coverage --coverage -fno-inline -fno-inline-small-functions -fno-default-inline -O0 -fno-elide-constructors -g -Wall -W -o .obj/myclass.o unittest_myclass.cpp
然后我 运行 gcov (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4 在我的一个源文件上
gcov unittest_myclass.cpp -o .obj/
此文件仅包含 header class 的单元测试。 gcov 成功生成此 header 文件的覆盖率信息:
File '../include/myclass.h'
Lines executed:11.05% of 173
Creating 'myclass.h.gcov'
然而,myclass.h.gcov中的结果是错误的。对于大多数行,gcov 报告它们不包含可执行代码。对于那些它检测为可执行文件,它主要报告它们尚未执行。但我确信它们正在被执行(我在调试时验证了它,一些单元测试由于错误等而失败了)。不涉及模板。 因此我猜想由于某种原因 gcov 无法检测到正确的执行。正如您从我上面的命令行参数中看到的那样:优化已关闭,内联已关闭...
还有什么可能导致这些问题的想法吗?
似乎问题不在于我的 class 只是 header,而是我用
调用了 gcovgcov unittest_myclass.cpp -o .obj/
如果我用
代替 运行gcov *.cpp -o .obj/
它报告
File '../include/myclass.h'
Lines executed:95.56% of 248
Creating 'myclass.h.gcov'
生成的 myclass.h.gcov
文件看起来比我预期的要好得多。