Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcov on larger projects (static libraries, ...)

I'm working on larger project which has the following directory layout:

Source
 MyA
  aa.cpp
  ab.cpp
  ac.cpp
 MyB
  ba.cpp
  bb.cpp
  bc.cpp
 MyTest
  testaa.cpp
  testab.cpp
  testac.cpp
  testba.cpp
  testbb.cpp
  testbc.cpp
  main.cpp
Build
 MyA
  aa.o
  ab.o
  ac.o
  libMyA.a (static library)
 MyB
  ba.o
  bb.o
  bc.o
  libMyB.a (static library)
 MyTest
  testaa.o
  testab.o
  testac.o
  testba.o
  testbb.o
  testbc.o
  MyTest (executable)

After compiling with -fprofile-arcs -ftest-coverage I execute the MyTest application inside the Build/MyTest directory. As expected there are *.gcno and *.gcda files inside the Build directory. After running gcov inside the MyTest directory different *.gcov files are produced but unfortunately not for everything inside MyA and MyB, although every function is called inside this two libraries. Tried different options but somehow I'm unable to create useful (means correct) *.gcov files with this layout.

If I copy every cpp inside one directory and repeat the steps everything works as expected and the coverage analysis is perfect.

like image 565
azraiyl Avatar asked Apr 07 '11 18:04

azraiyl


2 Answers

  1. You must specify source files as absolute paths to g++/gcc. Don't use relative paths with ".." or like "foo/bar.cpp", else you'll get errors like "geninfo: WARNING: no data found for XXXX".

  2. Don't include any header files on the command line to g++/gcc. Else you'll get "stamp mismatch with graph file" errors.

So, following should work when having multiple directories:

g++ --coverage -DDEBUG -g3 heyo.cpp /app/helper/blah.cpp /app/libfoo/foo.cpp -o program

./program

lcov --directory . --capture --output-file app.info

genhtml --output-directory cov_htmp app.info

Or, if you're in a Makefile that uses relative paths already, it's convenient to use:

g++ --coverage -DDEBUG -g3 $(abspath heyo.cpp helper/blah.cpp ../foo/bar/baz.cpp) -o program
like image 179
Lasse Reinhold Avatar answered Sep 19 '22 20:09

Lasse Reinhold


To be able to keep your directory structure, you need to run gcov once inside each source file folder, but use the -o option to tell gcov where the data files are.

I think it should be like this:

gcov -o ../../Build/MyA *.cpp

I have a project with a similar source file structure, but I let the compiler dump object files etc into the source folders. I then run gcov multiple times from the root folder, once for each source file, but I specify the relative path of the source file and use the -o option to specify the relative folder like this:

gcov -o Source/MyA Source/MyA/aa.cpp
like image 29
quamrana Avatar answered Sep 19 '22 20:09

quamrana