Question

I am using Waf to build a C project and gcov to have some test code coverage. However, Waf calls gcc in a way that produces foo.c.1.o from source file foo.c that confuses gcov when searching for the generated files:

$ gcov foo.c
$ foo.gcno:cannot open graph file

Fortunately, gcov has the -o option with which it is possible to specify the corresponding object file. Nevertheless, this is not convenient and executing lcov still fails. Therefore, my questions are:

  1. Why does Waf rename the object files?
  2. How can this behaviour be disabled or ...
  3. How can gcov/lcov work around this issue?
Was it helpful?

Solution

You can use gcovr instead of directly running gcov.

gcovr does not rely on file name magic, but parses gcov's coverage files.
It then calls gcov with the appropriate parameters.
This works great with Waf's object file renaming.

You can run gcovr from Waf's build subdirectory:

cd build
gcovr --root=$(pwd) --keep
lcov --capture --directory $(pwd) --base-directory $(pwd) --output-file coverage.info
genhtml coverage.info --output-directory out

The --root option removes the current directory prefix
The --keep option keeps gcov's temporary files, used by lcov/genhtml.

You can also use gcovr's --xml option to produce Cobertura-compatible xml output.
It can then be used by various formatters (I use it with Jenkins' Cobertura Plugin)

OTHER TIPS

Have you tried modifying Waf's configuration with something like

bld.program(
  obj_ext  = '.o',
  source   = 'test.c',
  target   = 'test1')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top