Integrating GTest with GNU gcov

7,037 views
Skip to first unread message

Anu

unread,
Mar 8, 2011, 2:58:44 PM3/8/11
to Google C++ Testing Framework, anuj...@rim.com
Hello Folks,

GTest is working fine for me as far as writing test cases and testing
the code. I have a unit tet exe which is calling the static code
library that actually contains the code to be tested.

After unit test cases , I am now focused on code coverage analysis. I
am usign GNU gcov for this. I could get code coverage for an unit test
exe but I couldn't get coverage results for underlying binary which is
the goal.


Has anyone tried GCOV and GTEST in integrated together?

Any help would be appreciated..

Thanking you.




Mike Long

unread,
Mar 8, 2011, 3:17:32 PM3/8/11
to Anu, Google C++ Testing Framework, anuj...@rim.com
Hi Anu,

I have set up gcov for my build with gtest, I have written up the steps here:
http://meekrosoft.wordpress.com/2010/06/02/continuous-code-coverage-with-gcc-googletest-and-hudson/

The way to get full coverage (for every part of the underlying binary) is to make sure that all the objects that are in your production code are in your test binary.  You might need to reference a dummy symbol in each of your untested translation units to get the linker to pull them in.

Good luck!

Mike

deuberger

unread,
Mar 10, 2011, 6:20:56 PM3/10/11
to Google C++ Testing Framework
> On Tue, Mar 8, 2011 at 8:58 PM, Anu <anu...@gmail.com> wrote:
> > After unit test cases , I am now focused on code coverage analysis. I
Yes, and with good success. What I set up was inspired by Mike's
article that he mentioned above (thanks Mike!), but I've since made a
number of changes to fit our project. If you have any other problems,
please post back because I've probably already run into them.

On Mar 8, 3:17 pm, Mike Long <mikelong2...@gmail.com> wrote:
> The way to get full coverage (for every part of the underlying binary) is to
> make sure that all the objects that are in your production code are in your
> test binary.  You might need to reference a dummy symbol in each of your
> untested translation units to get the linker to pull them in.
We don't do this and everything works great, but we did use some other
workarounds that seem a bit easier to me:

1. Older versions of gcovr had problems finding source files not in
the same directories as the .gcda files (for instance if you're using
autotools). This has since been fixed, so just use the latest release
or at least make sure you have the patch from here:
https://software.sandia.gov/trac/fast/ticket/3872.

2. .gcda files are only produced for code that is run, so it's best if
you search for .gcno files as well, which will give you a better idea
of your overall coverage. See https://software.sandia.gov/trac/fast/ticket/3887
for a patch to make gcovr do this for you.

Also, this isn't really related, but another problem I had is fixed
with a patch here: https://software.sandia.gov/trac/fast/ticket/3888.

Lastly, make sure your running gcovr with the right command. Here's
what we use:

gcovr -e '/usr' -e '.+/test/.+' -e 'gtest' -r . -x

Hope that helps. Thanks again Mike.

- Daniel

Mike Long

unread,
Mar 11, 2011, 2:05:08 AM3/11/11
to anuya joshi, Google C++ Testing Framework
Hi,

Adding the list back in.  I am all out of ideas, maybe someone here can help?

Regards,
Mike

On Wed, Mar 9, 2011 at 9:13 PM, anuya joshi <anu...@gmail.com> wrote:
Hi Mike,
 
I looked into the thread. However, in my case,  gcda files are not getting created in any other location. I confirmed this by searching for *.gcda file(s) in My Computer.
 
I am unable to understand whats going wrong.
 
Any pointers from your side would be of great help. Also, library in my case is not a shared library. But, its a static library.
 
Thanks,
Anuya 

On Tue, Mar 8, 2011 at 11:34 PM, Mike Long <mikelo...@gmail.com> wrote:
Have you had a look at this webpage?

It could be that the file are being written, only to a different place than you think.

Regards,
Mike

On Wed, Mar 9, 2011 at 3:17 AM, Anu <anu...@gmail.com> wrote:
Hi Mike,

I would like to correct myself as below that I mentioned previously:

*****************************************************************************


After unit test cases , I am now focused on code coverage analysis. I
am usign GNU gcov for this. I could get code coverage for an unit
test
exe but I couldn't get coverage results for underlying LIBRARY which
is
the goal.

*****************************************************************************

Actually, my setup is as follows in brief:

1) A code to be tested is in static library libXXX.a
2) A unit test exe that actually contains the test cases has been
linked with this code library.

Now, I am able to get the code coverage for an exe. However, my aim is
to get code coverage for underlying code library. .gcno and .gcda
files are getting created for an exe. However, only .gcno file is
getting created for library.

My both exe and library have been instrumented using -fprofile-arcs  -
ftest-coverage options during compile time.

I am not sure why coverage results are not being displayed for a
library.

I would be thankful if you can provide me pointers on this.


Thanks,
Anuya



On Mar 8, 12:17 pm, Mike Long <mikelong2...@gmail.com> wrote:
> Hi Anu,
>
> I have set up gcov for my build with gtest, I have written up the steps

>
> The way to get full coverage (for every part of the underlying binary) is to
> make sure that all the objects that are in your production code are in your
> test binary.  You might need to reference a dummy symbol in each of your
> untested translation units to get the linker to pull them in.
>
> Good luck!
>
> Mike
>
>
>
> On Tue, Mar 8, 2011 at 8:58 PM, Anu <anu...@gmail.com> wrote:
> > Hello Folks,
>
> > GTest is working fine for me as far as writing test cases and testing
> > the code. I have a unit tet exe which is calling the static code
> > library that actually contains the code to be tested.
>
> > After unit test cases , I am now focused on code coverage analysis. I
> > am usign GNU gcov for this. I could get code coverage for an unit test
> > exe but I couldn't get coverage results for underlying binary which is
> > the goal.
>
> > Has anyone tried GCOV and GTEST in integrated together?
>
> > Any help would be appreciated..
>
> > Thanking you.- Hide quoted text -
>
> - Show quoted text -



Mike Long

unread,
Mar 11, 2011, 2:06:55 AM3/11/11
to deuberger, Google C++ Testing Framework
Hi Daniel,

Thanks for the feedback!  These are very useful tips, I will try them out on my system.

Regards,
Mike

deuberger

unread,
Mar 11, 2011, 11:22:32 AM3/11/11
to Google C++ Testing Framework
> > I looked into the thread. However, in my case,  gcda files are not getting
> > created in any other location. I confirmed this by searching for *.gcda
> > file(s) in My Computer.
What about .gcno files? A .gcno file should be created during
compilation for every object/source file that you want coverage
information for. If there are no .gcno files, you won't get .gcda
files. If you're not seeing the .gcno files, then you're compilation
options somewhere.

deuberger

unread,
Mar 11, 2011, 11:27:42 AM3/11/11
to Google C++ Testing Framework
On Mar 11, 11:22 am, deuberger <daniel.neuber...@gmail.com> wrote:
> If you're not seeing the .gcno files, then you're compilation
> options somewhere.
Oops... that should be "then you're *missing* compilation options
somewhere.
Reply all
Reply to author
Forward
0 new messages