Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

gcc

gcov

I'm successfully using gcov in my project:

  • I can build my project with gcov flags: -fprofile-arcs -ftest-coverage
  • I link with the -lgcov option
  • I run my unit test program and lots of gcda and gcno files are produced.
  • I run gcov lots of times and lots of gcov files are produced.
  • I summarise the results and produce a list of lines like this:
    • #####: 42: virtual double run_time() const { return 0; }

I then go 'doh!' and write a test which calls that missing method.

The above example line is quite easy to diagnose - gcov told me the exact method I was not calling.

I've also had an example of a copy constructor being flagged by gcov, but I'm able to step through it using my Visual Studio debugger. The solution there was to realise that gcov was suffering from RVO which elided the copy, but writing a test which forced a copy fixed that.

I have a couple of other examples which I cannot figure out:

1.
File.cpp
#####: 78:}

gcov seems to be flagging the close brace of a namespace which is the last line of a file.

2.
File.h
#####: 33:  class FooBase: public IResult {

What is gcov trying to tell me here? I can't think of a call to make here.
Update 1: I've detected that FooBase has a default constructor, which if only 'called' by a subclass is not the same as calling it by instantiating it, as far as gcov is concerned.

Update 2: I've been using djgpp/gcc 4.4.4 which produced the above results. However, by using MinGW/gcc 4.5.2 the 'aberrations' disappear and with a little more work I've been able to get to 100% line coverage.

Please write your answers with either a single tip for the unwary gcov user, or an answer to one of my examples.

like image 362
quamrana Avatar asked May 26 '11 14:05

quamrana


1 Answers

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.

like image 194
osgx Avatar answered Oct 03 '22 07:10

osgx