Lcov does not match gcov coverage results for googletest unit test

I am trying to collect coverage results in library file foobar.cpp by creating googletest unit tests for souce file and then using gcov for coverage results, finally using lcov to generate html document.

I got unit testing and gcov results to work fine, but lcov never displays the correct coverage results, omitting my foobar.cpp.gcov results entirely?

I have a unit test framework built basically like this:

Directories:

~/svn/googletest-read-only/
    /src
        gtest_main.cc
        gtest-all.cc
    /include
~/code/proj/
    foobar.cpp 
    foobar.hpp
~/code/proj/unittest/
    foobar_test.cpp
    Makefile

      

Everything works from unittest / I do unittest/ $ make

by creating the foobar_test executable in that folder. main () is located in googletest / src / gtest_main.cc . My Makefile is based on googletest and has the following notable settings:

Makefile:

CXXFLAGS += -g -O0 --coverage -fprofile-arcs -ftest-coverage -Wall -Wextra -pthread LDFLAGS = -lpthread -lgcov foobar_test : foobar.o foobar_test.o gtest_main.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) $^ -o $@

I run the executable once $ ./foobar_test

. This gives a .gcda to match every .gcno source (4x total: foobar, foobar_test, gtest_main, and gtest-all).

Then $ gcov foobar.cpp

only run foobar.cpp (I've also tried alternatives like $ gcov *.cpp

... using only foobar_test.cpp doesn't work). This creates a stdout which includes a bunch of / usr / lib crap, but also MY result: File '../foobar.cpp'; Completed lines: 61.25% of 80; .. ` and creates my .gcov files.

Checking my .cpp.gcov file it shows a nice bump as described above for 61.25% of the lines. At the moment I have 4x.gcda, 4x, gcno and about 20x other .gcov files.

Now, when I try to use lcov here lcov --directory . -c -o result.info

, it goes wrong.

lcov Results:

Capturing coverage data from .
Found gcov version: 4.4.7
Scanning . for .gcda files ...
Found 4 data files in .
Processing ./gtest_main.gcda
geninfo: WARNING: cannot find an entry for foobar.cpp.gcov in .gcno file, skipping file!
geninfo: WARNING: cannot find an entry for *more c++ files*.gcov in .gcno file, skipping file!
Processing ./foobar.gcda
geninfo: WARNING: no data found for /home/asdf/code/proj/foobar.cpp
Processing ./foobar_test.gcda
geninfo: WARNING: no data found for /home/asdf/code/proj/unittest/foobar_test.cpp
Processing ./gtest-all.gcda
Finished .info-file creation```

      

Viewing the lcov output after $ genhtml report.info --output-directory report && firefox report/index.html

only shows about 5 directories which does not include ANY foobar * files

I have tried several combinations $ gcov []cpp

and also to $ lcov --base-directory [] --directory [] -c -o

no avail. Also tried soft linking some source files, no help.

What do you need to change in settings or commands? Commentators can suggest the best solution overall.

+3


source to share





All Articles