Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use gcov with QMake for code coverage

Tags:

c++

qt

qt4

qmake

gcov

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!

like image 310
Etienne Savard Avatar asked Nov 17 '10 12:11

Etienne Savard


People also ask

What can I do with gcov files?

You can use gcov as a profiling tool to help discover where your optimization efforts will best affect your code. You can also use gcov along with the other profiling tool, gprof, to assess which parts of your code use the greatest amount of computing time. Profiling tools help you analyze your code's performance.


1 Answers

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

like image 71
Chris Card Avatar answered Sep 30 '22 17:09

Chris Card