Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Using gcov and lcov problem?

Tags:

c++

lcov

gcov

I am using ubuntu 10.1, g++ compiler.

I trying to use gcov and lcov for my C++ project. I manage to compile the gcov:

g++ -fprofile-arcs -ftest-coverage main.cpp user.cpp game.cpp

There is no error or warning message. Next I try to run gcov:

gcov main.cpp user.cpp game.cpp

Also fine. I also try to run my program:

./a.out

and run gcov again, my main, user and game.cpp shows some percentage now. I want to capture the data, I type this in terminal:

lcov --directory /home/projects/Game1/ -c -o application.info

But it gives me this:

Capturing coverage data from /home/projects/Game1/
geninfo: ERROR: cannot read /home/projects/Game1/!

I search all over the web, read lcov documentation, I cant find the answers. Anyone can help me?

In addition, I also could not open the main.gcda file.(I tried open using text editor, it says some character encoding problem, quite alot: UTF-8, Western (ISO-8859-1), Western (ISO-8859-11) etc, but still cant open and read the file.

Please help me.. anyone??

EDIT:

I admit, its my mistake (i am terribly sorry, "home/Projects/Game1" with capital "P".) After verifying the path, I got this new error:

geninfo: ERROR: /home/Projects/Game1/main.gcno: reached unexpected end of file
like image 658
cpp_noob Avatar asked Jan 30 '11 17:01

cpp_noob


People also ask

What is difference between gcov and LCOV?

Lcov is a graphical front-end for gcov. It collects gcov data for multiple source files and creates HTML pages containing the source code annotated with coverage information. It also adds overview pages for easy navigation within the file structure. Lcov supports statement, function, and branch coverage measurement.


2 Answers

Be sure to include -g flag (debug information): -g -fprofile-arcs -ftest-coverage

While working with lcov I found that it is better to use absolute paths instead of relative paths. You can try to use lcov to capture initial zero coverage date with -i, --initial switch.

Here is an example of my way of achieving zerocounters

$ lcov --zerocounters --directory myFullPath
$ lcov --capture --initial --directory myFullPath --output-file myOutputFile

Then run your program and then capture the coverage data:

$ lcov --no-checksum --directory myFullPath --capture --output-file myOutputFile

Finaly lcov enables you to generate html report:

$ lcov/genhtml --highlight --legend --output-directory myOutPutHTMLdirectory myOutputFile

Hope this helps you.

like image 62
Blaise Avatar answered Sep 29 '22 00:09

Blaise


I had exactly the same problem. And it turned out that if the library code changes while you had already ran the coverage tests, sometimes it gets confused. The only way to get out of it is to remove the file(s) causing the error and recompile.

like image 39
PierreBdR Avatar answered Sep 28 '22 23:09

PierreBdR