6

I would like to use gcov with my unit test written using QTestLib. I have managed to generate some .gcno files along my object files by adding this to my .pro file :

QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage -O0

But, when I run :

gcov main.cpp.gcno

I got a bunch of .gcov files generated with non-useful content (nothing like what I see in the tutorials on the web) :

-:    0:Source:main.cpp
-:    0:Graph:main.gcno
-:    0:Data:-
-:    0:Runs:0
-:    0:Programs:0
-:    1:/*EOF*/
-:    2:/*EOF*/
-:    3:/*EOF*/
-:    4:/*EOF*/
-:    5:/*EOF*/
-:    6:/*EOF*/
-:    7:/*EOF*/
-:    8:/*EOF*/
-:    9:/*EOF*/
-:   10:/*EOF*/
-:   11:/*EOF*/
-:   12:/*EOF*/
-:   13:/*EOF*/
-:   14:/*EOF*/
#####:   15:/*EOF*/
-:   16:/*EOF*/
#####:   17:/*EOF*/
-:   18:/*EOF*/
-:   19:/*EOF*/
#####:   20:/*EOF*/
-:   21:/*EOF*/
-:   22:/*EOF*/
-:   23:/*EOF*/
-:   24:/*EOF*/
#####:   25:/*EOF*/
#####:   26:/*EOF*/
-:   27:/*EOF*/
-:   28:/*EOF*/
-:   29:/*EOF*/
#####:   30:/*EOF*/

My source files are under ./MyProject/test/src directory and all my object files are in a .obj directory underneath src (ie: .MyProject/test/src/.obj). All binaries are created in ./MyProject/build directory.

What am I missing?

Thanks!

Symbiosoft
  • 4,681
  • 6
  • 32
  • 46

2 Answers2

4

Have you run your QT program? Until then there's no coverage data. Also, have a look at lcov, which you can use to get a nice html-based report of everything

Chris Card
  • 3,216
  • 20
  • 15
  • You are right for the coverage data : there is data in the files now. Also, I have to provide gcov with the option -o .obj because my object files are in a separate directory from my source. – Symbiosoft Nov 17 '10 at 17:24
0

It is worth noting that instead of directly manipulating the CXX_FLAGS, qmake has (had for a while now) a gcov CONFIG option which seems to work more reliably:

I implemented it with this conditional in my .pro files:

isEmpty(RELEASE_BUILD) {
CONFIG += gcov
}
MangoCat
  • 89
  • 5