What are your tips for interpreting gcov output in order to improve coverage?

回眸只為那壹抹淺笑 提交于 2019-12-04 07:06:46

As it is said in gcov.c

  /* For lines which don't exist in the .bb file, print '-' before
     the source line.  For lines which exist but were never
     executed, print '#####' before the source line.  Otherwise,
     print the execution count before the source line.  There are
     16 spaces of indentation added before the source line so that
     tabs won't be messed up.  */

I suggest you use a debug builds for gcov and for VS when trying to get a coverage.

The line you talk about is going to be inlined in release mode. That means the line itself will never be counted (although frankly the increment of the counter could have been moved to the place where the function gets inlined... but g++ does not do that yet.)

In order to fix the problem add -g to your g++ command line to keep all debug. You probably also want to make sure you defined -D_DEBUG. Actually, the documentation generally tells you to use -g.

Finally, you want to avoid optimizations with -O0.

On my end, I like to also use -fprofile-arcs and -ftest-coverage.

As mentioned in a comment in another answer, using -fno-elide-constructors and -fno-default-inline may also help with coverage of "missing" constructors and inline functions.

In regard to the opening brace being flagged, g++ is likely to create a constructor (possibly the copy constructor) and show it on that first class declaration line. There may be other compiler specific functions created like that and at times it is just impossible to hit them without extremely complicated test cases... I encounter that problem all the time.

As suggested by climbatizer, you could use lcov. That gives you HTML as output with easy to read tables that you can browse quickly. I have such an example here:

http://lcov.csspp.org/csspp-1.0.5/lib/index.html

As we can see, the library is 100% covered by all the tests. But somehow the assembler.cpp file says that one function is not covered. I have no idea which function that is though since 100% of the code I wrote is covered... So I just ignore such.

Recently I've been using cmake+"make Experimental"+lcov. I highly recommend that combination. Even if not using cmake, take a look at lcov.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!