I'm trying to gather coverage results on a library file foobar.cpp by creating a googletest unit tests for the souce file and then using gcov for coverage results, finally using lcov to produce an html document.
I've gotten unit testing and gcov results to work okay BUT lcov never depicts proper coverage results, omitting my foobar.cpp .gcov results completely?
I have a unit testing platform set up essentially 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 run from unittest/, I make unittest/ $ make
, producing an executable foobar_test in this folder. The main() is in googletest/src/gtest_main.cc file. My Makefile is based on googletest's and has these 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 produces .gcda's to match each source's .gcno (4x total: foobar, foobar_test, gtest_main, and gtest-all).
Then run $ gcov foobar.cpp
on only foobar.cpp (I've tried alternatives like $ gcov *.cpp
as well...using only foobar_test.cpp doesn't work). This produces stdout which includes a bunch of /usr/lib crap, but also MY result: File '../foobar.cpp'; Lines executed:61.25% of 80; ..` and creates my .gcov files.
Inspecting my .cpp.gcov file it shows good hit's as described above for 61.25% of lines. At this point 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 a $ genhtml report.info --output-directory report && firefox report/index.html
shows only about 5 directories that don't include ANY foobar* files?
I've tried multiple combinations of $ gcov []cpp
as well as $ lcov --base-directory [] --directory [] -c -o
to no avail. Also tried soft linking some source files around, no help.
What needs to change in my setup or commands?? Commenters are welcome to suggest a better solution altogether.