Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcovr confused by duplicate filenames #60

Closed
cbagwell opened this issue Aug 3, 2014 · 10 comments
Closed

gcovr confused by duplicate filenames #60

cbagwell opened this issue Aug 3, 2014 · 10 comments

Comments

@cbagwell
Copy link

cbagwell commented Aug 3, 2014

I saw this issue in a test project where some coverage data was not showing up in the gcovr generated reports.

I believe as of gcovr 3.2, all gcov reports are ran from starting_dir and output is stored in this single directory but nothing in filename contains subdirectory info.

Here is a made up project layout that has plugins for various audio formats:

root/src/main.cpp
root/src/read.cpp
root/src/mp3/read.cpp
root/src/wav/read.cpp

read.cpp.gcov would be generated in root directory 3 times and overwrite each other.

In my tests, only root/src/read.cpp shows up in reports because it happens to be last gcov ran.

@cbagwell
Copy link
Author

cbagwell commented Aug 3, 2014

Digging a little deeper, this appears to be a bigger issue for autotools based packages as apposed to the hand coded single test Makefile in gcovr/tests/nested. If you use a single Makefile to compile, the subdir paths get embedded into objects and gcov reports.

If you have a package that uses automake then you tend to have a Makefile per subdirectory and the path names no longer get embedded and generating all gcov reports in starting_dir will greatly confuse gcovr.

To help see issue, I modified nested test to have a Makefile in subdir/A and subdir/Makefile to link in those precompiled objects. Here is result of gcovr from that modifications. Notice how most items under subdir/A are missing from report:

$ ../../../../scripts/gcovr -r . -k -v
Scanning directory . for gcda/gcno files...
Found 12 files (and will process 9)
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/B/main.gcno --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/B' in '/home/test/src/gcovr/gcovr/tests/n/subdir'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/file2.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A' in '/home/test/src/gcovr/gcovr/tests/n/subdir'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/file7.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A' in '/home/test/src/gcovr/gcovr/tests/n/subdir'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/file1.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A' in '/home/test/src/gcovr/gcovr/tests/n/subdir'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/file5.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A/C' in '/home/test/src/gcovr/gcovr/tests/n/subdir'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/file5.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A/C' in '/home/test/src/gcovr/gcovr/tests/n/subdir/A/C'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/file5.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A/C' in '/home/test/src/gcovr/gcovr/tests/n/subdir/A'
Parsing coverage data for file /home/test/src/gcovr/gcovr/tests/n/subdir/C/file5.cpp
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/file4.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A' in '/home/test/src/gcovr/gcovr/tests/n/subdir'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/main.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir' in '/home/test/src/gcovr/gcovr/tests/n/subdir'
Parsing coverage data for file /home/test/src/gcovr/gcovr/tests/n/subdir/main.cpp
Parsing coverage data for file /usr/include/c++/4.8.3/iostream
  Filtering coverage data for file /usr/include/c++/4.8.3/iostream
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/D/file6.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/D' in '/home/test/src/gcovr/gcovr/tests/n/subdir'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/D/file6.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/D' in '/home/test/src/gcovr/gcovr/tests/n/subdir/A/C/D'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/D/file6.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/D' in '/home/test/src/gcovr/gcovr/tests/n/subdir/A/C'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/D/file6.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/D' in '/home/test/src/gcovr/gcovr/tests/n/subdir/A'
Parsing coverage data for file /home/test/src/gcovr/gcovr/tests/n/subdir/C/D/file6.cpp
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/file3.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A' in '/home/test/src/gcovr/gcovr/tests/n/subdir'
Gathered coveraged data for 3 files
------------------------------------------------------------------------------
                           GCC Code Coverage Report
Directory: /home/test/src/gcovr/gcovr/tests/n/subdir
------------------------------------------------------------------------------
File                                       Lines    Exec  Cover   Missing
------------------------------------------------------------------------------
C/D/file6.cpp                                  4       3    75%   4
C/file5.cpp                                    4       3    75%   4
main.cpp                                       9       9   100%   
------------------------------------------------------------------------------
TOTAL                                         17      15    88%
------------------------------------------------------------------------------
$ ls -R
.:
A/                  main.cpp       Makefile
B/                  main.cpp.gcov  testcase*
C#D#file6.cpp.gcov  main.gcda      #usr#include#c++#4.8.3#iostream.gcov
C#file5.cpp.gcov    main.gcno
coverage.txt        main.o

./A:
C/                  file1.gcda  file2.o     file4.cpp   file7.gcda
C#D#file6.cpp.gcov  file1.o     file3.cpp   file4.gcda  file7.o
C#file5.cpp.gcov    file2.cpp   file3.gcda  file4.o     Makefile
file1.cpp           file2.gcda  file3.o     file7.cpp

./A/C:
C#D#file6.cpp.gcov  D/         file5.gcda  file5.o
C#file5.cpp.gcov    file5.cpp  file5.gcno

./A/C/D:
C#D#file6.cpp.gcov  file6.cpp  file6.gcda  file6.gcno  file6.o

./B:
main.cpp  main.gcno  main.o

@whart222
Copy link
Member

whart222 commented Aug 3, 2014

Given the difference that you note, is this a gcovr issue or a gcov issue?
I'm wondering if gcov is providing gcovr information that confuses these
files.

Can you provide a test example that we can use to motivate a fix?

On Sun, Aug 3, 2014 at 5:27 PM, Chris Bagwell notifications@github.com
wrote:

Digging a little deeper, this appears to be a bigger issue for autotools
based packages as apposed to the hand coded single test Makefile in
gcovr/tests/nested. If you use a single Makefile to compile, the subdir
paths get embedded into objects and gcov reports.

If you have a package that uses automake then you tend to have a Makefile
per subdirectory and the path names no longer get embedded and generating
all gcov reports in starting_dir will greatly confuse gcovr.

To help see issue, I modified nested test to have a Makefile in subdir/A
and subdir/Makefile to link in those precompiled objects. Here is result of
gcovr from that modifications. Notice how most items under subdir/A are
missing from report:

$ ../../../../scripts/gcovr -r . -k -v
Scanning directory . for gcda/gcno files...
Found 12 files (and will process 9)
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/B/main.gcno --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/B' in '/home/test/src/gcovr/gcovr/tests/n/subdir'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/file2.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A' in '/home/test/src/gcovr/gcovr/tests/n/subdir'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/file7.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A' in '/home/test/src/gcovr/gcovr/tests/n/subdir'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/file1.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A' in '/home/test/src/gcovr/gcovr/tests/n/subdir'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/file5.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A/C' in '/home/test/src/gcovr/gcovr/tests/n/subdir'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/file5.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A/C' in '/home/test/src/gcovr/gcovr/tests/n/subdir/A/C'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/file5.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A/C' in '/home/test/src/gcovr/gcovr/tests/n/subdir/A'
Parsing coverage data for file /home/test/src/gcovr/gcovr/tests/n/subdir/C/file5.cpp
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/file4.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A' in '/home/test/src/gcovr/gcovr/tests/n/subdir'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/main.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir' in '/home/test/src/gcovr/gcovr/tests/n/subdir'
Parsing coverage data for file /home/test/src/gcovr/gcovr/tests/n/subdir/main.cpp
Parsing coverage data for file /usr/include/c++/4.8.3/iostream
Filtering coverage data for file /usr/include/c++/4.8.3/iostream
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/D/file6.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/D' in '/home/test/src/gcovr/gcovr/tests/n/subdir'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/D/file6.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/D' in '/home/test/src/gcovr/gcovr/tests/n/subdir/A/C/D'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/D/file6.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/D' in '/home/test/src/gcovr/gcovr/tests/n/subdir/A/C'
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/D/file6.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A/C/D' in '/home/test/src/gcovr/gcovr/tests/n/subdir/A'
Parsing coverage data for file /home/test/src/gcovr/gcovr/tests/n/subdir/C/D/file6.cpp
Running gcov: 'gcov /home/test/src/gcovr/gcovr/tests/n/subdir/A/file3.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /home/test/src/gcovr/gcovr/tests/n/subdir/A' in '/home/test/src/gcovr/gcovr/tests/n/subdir'

Gathered coveraged data for 3 files

                       GCC Code Coverage Report

Directory: /home/test/src/gcovr/gcovr/tests/n/subdir

File Lines Exec Cover Missing

C/D/file6.cpp 4 3 75% 4
C/file5.cpp 4 3 75% 4

main.cpp 9 9 100%

TOTAL 17 15 88%

$ ls -R
.:
A/ main.cpp Makefile
B/ main.cpp.gcov testcase*
C#D#file6.cpp.gcov main.gcda #usr#include#c++#4.8.3#iostream.gcov
C#file5.cpp.gcov main.gcno
coverage.txt main.o

./A:
C/ file1.gcda file2.o file4.cpp file7.gcda
C#D#file6.cpp.gcov file1.o file3.cpp file4.gcda file7.o
C#file5.cpp.gcov file2.cpp file3.gcda file4.o Makefile
file1.cpp file2.gcda file3.o file7.cpp

./A/C:
C#D#file6.cpp.gcov D/ file5.gcda file5.o
C#file5.cpp.gcov file5.cpp file5.gcno

./A/C/D:
C#D#file6.cpp.gcov file6.cpp file6.gcda file6.gcno file6.o

./B:
main.cpp main.gcno main.o


Reply to this email directly or view it on GitHub
#60 (comment).

@cbagwell
Copy link
Author

cbagwell commented Aug 6, 2014

I think its likely a gcovr issue with assuming the root of all compiles is starting_dir. I'm new to gcovr but it may have worked fine before 3.2 when it starting chdir()'ing before running gcov.

Let me find some time to package up a modified version of 'nested' example distributed with gcovr and we can go from there.

mikael-s added a commit to mikael-s/gcovr that referenced this issue Oct 22, 2014
However there are some issues in tests in shared_lib. I don't know gcovr
sufficiently well to understand if that's a real problem or no.
@mikael-s
Copy link
Contributor

Hi,
I do have the same issue (if I understand well what @cbagwell means). When having a Makefile by subdirectory, you end up with a report that completely removes all the subdirectories.

I created an example in 23b7d41 (highly inspired from the nested test). The current version of gcovr would produce that output (when launched with gcovr -r subdir)

------------------------------------------------------------------------------
                           GCC Code Coverage Report
Directory: subdir/
------------------------------------------------------------------------------
File                                       Lines    Exec  Cover   Missing
------------------------------------------------------------------------------
B/main.cpp                                     9       9   100%   
------------------------------------------------------------------------------
TOTAL                                          9       9   100%
------------------------------------------------------------------------------

Or that output when launched with gcovr -r .

                           GCC Code Coverage Report
Directory: .
------------------------------------------------------------------------------
File                                       Lines    Exec  Cover   Missing
------------------------------------------------------------------------------
file1.cpp                                      4       3    75%   4
file2.cpp                                      7       4    57%   8-11
file3.cpp                                      9       4    44%   8-14
file4.cpp                                      4       3    75%   6
file5.cpp                                      4       3    75%   4
file6.cpp                                      4       3    75%   4
file7.cpp                                      2       0     0%   1-3
subdir/B/main.cpp                              9       9   100%   
------------------------------------------------------------------------------
TOTAL                                         43      29    67%
------------------------------------------------------------------------------

The second case is better but still all the subdirectories are ignored (except for main.cpp). With my commit 6fa250f the output is now (when launching gcovr -r subdir):

                           GCC Code Coverage Report
Directory: subdir
------------------------------------------------------------------------------
File                                       Lines    Exec  Cover   Missing
------------------------------------------------------------------------------
A/C/D/file6.cpp                                4       3    75%   4
A/C/file5.cpp                                  4       3    75%   4
A/file1.cpp                                    4       3    75%   4
A/file2.cpp                                    7       4    57%   8,10-11
A/file3.cpp                                    9       4    44%   8,10-12,14
A/file4.cpp                                    4       3    75%   6
A/file7.cpp                                    2       0     0%   1,3
B/main.cpp                                     9       9   100%   
------------------------------------------------------------------------------
TOTAL                                         43      29    67%
------------------------------------------------------------------------------

which totally reflects the directory hierarchy.

However the tests in shared_lib now fails. I need help to understand if that's an issue or not. There is a difference in the coverage.txt, but my version seems better to me. There is also a difference in the coverage.xml file (in the package tag) but I'm unable to tell if the difference matters.

I think correcting this issue #60 is very important since it makes gcovr unusable with Cobertura plugins as soon as you have several Makefiles (which is not unusual with large projects).

@cbagwell
Copy link
Author

Thanks for creating a test case with issue, @mikael-s . I hadn't found time to push one myself.

Also, I see you have prototype fix for issue on your fix_nexted_makefiles branch. I had a similar work around that I've been using. For my case, I commented out the call to os.chdir() in process_gcov_data() and this 1 line change works for my nested Makefile cases. I'm guessing it causes other problems but lets me keep using Cobertura plugins.

@michaelgallacher
Copy link

@cbagwell, just curious, which of the os.chdir() calls in process_gov_data did you comment out? I'd like to try it on my setup. Thx!

@cbagwell
Copy link
Author

I commented out only the first os.chdir() call in process_gcov_data(). The one that says os.chdir(starting_dir).

As kinda mentioned in comment #2, this os.chdir(starting_dir) means gcovr supports 1 Makefile that references files in nested subdirectories but doesn't handle well nested subdirectories with a Makefile per directory.

In former case, subdirectory info is stored in gcov data and so temp files are created of form $starting_dir/path#to#filename but in later case temp files are created of form $starting_dir/filename and thus risk overwriting each other.

Another bad thing that happens in later case is that since subdirectory names are missing, you also don't see them in gcovr reports and everything looks like its in root directory. Commenting out os.chdir(starting_dir) fixes that issue as well.

@michaelgallacher
Copy link

Wow! Removing the os.chdir(starting_dir) solved several issues I was having. I still have the problem of a few duplicate header files, but the large majority were resolved. Also resolved was the issue where I specify a root directory and all the files show up in in a flat list. They now show up in relative directories. Seems like a nice change. I don't see a downside to it. Yet. :) Thanks!

@michaelgallacher
Copy link

FYI, I found out what removing that line breaks. "--html-details" no longer works for me after removing the os.chdir(starting_dir).

whart222 added a commit that referenced this issue Aug 6, 2016
These changes didn't work for all problems, so I'm reverting them
for now.
@latk
Copy link
Member

latk commented Dec 28, 2017

This issue has not seen any progress in a while, so I am closing it for now. If the problem persists, please add further details so it can be re-opened. If someone else is experiencing a similar issue, please create a new issue.

In particular, the test case added by @mikael-s in 23b7d41 seems to pass. If that test case does not describe the intended behaviour or if the test case did not reproduce the actual problem, please explain in more detail.
@cbagwell, you seem to understand this issue better than me. Does the problem still exist with an up to date gcovr?

@latk latk closed this as completed Dec 28, 2017
JamesReynolds pushed a commit to JamesReynolds/gcovr that referenced this issue Mar 8, 2018
However there are some issues in tests in shared_lib. I don't know gcovr
sufficiently well to understand if that's a real problem or no.
JamesReynolds pushed a commit to JamesReynolds/gcovr that referenced this issue Mar 8, 2018
These changes didn't work for all problems, so I'm reverting them
for now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants