1

I am trying to obtain code coverage for a component I am writing for the Arora browser, that is written using C++ and Qt framework.

I am not able to use the gcov program, neither under Gnu/Linux nor Mac Os X. I tried everything I was able to find on the Internet, also by forcing things automatically editing the Makefile generated by the .pro file.

Can somebody help me please? This is my very simple pro file:

TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
LIBS += -lgcov
QMAKE_CXXFLAGS += -g -fprofile-arcs -ftest-coverage -O0
QMAKE_LDFLAGS += -g -fprofile-arcs -ftest-coverage  -O0


include(../autotests.pri)

# Input
SOURCES += tst_quickview.cpp
HEADERS +=

The Makefile does correctly contain the flags. I also tried the --coverage option. But nothing happens. When I run the executable, no gcov files are generated. There are no errors and no warnings. I am using the QTestLib framework.

Thank you

Jérôme
  • 26,567
  • 29
  • 98
  • 120
  • Can you get gcov working at all? Can you get it working on a simple test program, independent of Qt, using only the command line for example? – Troubadour Dec 19 '10 at 14:48
  • I mean, the simple test program works, not the one I am working on –  Dec 19 '10 at 16:11
  • 1
    I'm successfully using gcov/lcov with QTestLib. Your .pro file looks good to me --- the key parts are there (`-fprofile-arcs -ftest-coverage` and `-lgcov`). Does your test code exit normally? The measurement data is only written out in an `atexit()` function. – laalto Dec 20 '10 at 12:02
  • The project test file actually uses QTEST_MAIN(tst_QuickView) macro for generating the main function. Could this be the problem? –  Dec 20 '10 at 14:37

2 Answers2

1

At least you should use

QMAKE_LFLAGS += -g -fprofile-arcs -ftest-coverage  -O0

instead of

QMAKE_LDFLAGS += -g -fprofile-arcs -ftest-coverage  -O0

I'm not sure if that will fix your problem but QMAKE_LDFLAGS is not going to do anything useful.

cellcortex
  • 3,166
  • 1
  • 24
  • 34
1

Atleast in cases where i've had similar issues, the problem has been in directory structures.

First issue was/is that in order to generate proper .gc* files during execution, compiler cache needs to be disabled. I never really debugged the issue but now, i'd assume that the gconv files where infact placed on the compiler cache folder and during the execution of the coverage instrumented binaries, binary was not able to idenfify where new datafiles should be generated.

Second issue is/was that i had to run the tests in the same directory structure as they where compiled in. For example, if i had compiled the application in "/home/foo/src/myproject/" and all its subdirectories .. The execution has to happen in that same directory structure or the datafiles won't get generated..

rasjani
  • 7,372
  • 4
  • 22
  • 35