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 not working with out-of-source builds #340

Closed
freesurfer-rge opened this issue Nov 19, 2019 · 2 comments
Closed

gcovr not working with out-of-source builds #340

freesurfer-rge opened this issue Nov 19, 2019 · 2 comments
Labels
Filters related to filters, include/exclude, path handling Type: Question

Comments

@freesurfer-rge
Copy link
Contributor

I'm trying to use gcovr with a cmake project, and it's failing to report code coverage on a fairly basic setup. I've created a sample repository to demonstrate the issue:
https://github.com/freesurfer-rge/gcovr-learn

For reference, if the sources are compiled using the manualbuild.sh script in the repo root, then after running the binary, gcovr -r . produces a sensible report.

However, if I go to /tmp/bld and run

cmake ~/gcovr-learn/
make
./tst/SimpleTest

then gcovr -r . finds no source files and reports no usage. The .gcno and .gcda files are definitely produced. In particular:

./tst/CMakeFiles/SimpleTest.dir:
CXX.includecache  cmake_clean.cmake  flags.make     simpletests.cpp.gcda  test.cpp.gcda
DependInfo.cmake  depend.internal    link.txt       simpletests.cpp.gcno  test.cpp.gcno
build.make        depend.make        progress.make  simpletests.cpp.o     test.cpp.o

but they don't seem to be found. Running with --verbose I see output such as:

Pool started with 1 threads
Processing file: /tmp/bld/src/CMakeFiles/simple.dir/simple.cpp.gcda
Running gcov: 'gcov /tmp/bld/src/CMakeFiles/simple.dir/simple.cpp.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /tmp/bld/src/CMakeFiles/simple.dir' in '/tmp/tmps35c5cdp'
Finding source file corresponding to a gcov data file
  currdir      /tmp/bld
  gcov_fname   /tmp/tmps35c5cdp/#home#freesurferrge#gcovr-learn#src#simple.cpp.gcov
               ['        -', '    0', 'Source', '/home/freesurferrge/gcovr-learn/src/simple.cpp\n']
  source_fname /tmp/bld/src/CMakeFiles/simple.dir/simple.cpp.gcda
  root         /tmp/bld
  fname        /home/freesurferrge/gcovr-learn/src/simple.cpp
Parsing coverage data for file /home/freesurferrge/gcovr-learn/src/simple.cpp
  Filtering coverage data for file /home/freesurferrge/gcovr-learn/src/simple.cpp

which implies that files are being found OK.

The machine is a stock Azure ubuntu 18.04 VM, with the modifications detailed in the setup-commands.txt file in the repo root.

@latk latk added Filters related to filters, include/exclude, path handling Type: Question labels Nov 19, 2019
@latk
Copy link
Member

latk commented Nov 19, 2019

Gcovr needs to know about two directories:

  1. where to search for coverage data?
  2. where is the project root with your source files?

The search paths default to -r/--root (in-source build) and --root defaults to the current directory.

In your case, these directories are not the same so you should explicitly provide them both:

# cd /tmp/bld
gcovr --root ~/gcovr-learn .
#            ^^^^^^^^^^^^^ ^-- search path
#            root dir

This is admittedly not the most intuitive scheme, but changing it would break backwards compatibility.

In the --verbose output, the problem was indicated by the following information:

  • “Filtering coverage data for file …” means that the file was excluded:
  • The fname is the source file name, which here starts with /home.
  • The root is your project dir, which here is /tmp/bld.
  • The source file must match a --filter. The default filter checks that the source file is in the --root directory.
  • Here, the source file is not in the root directory.

This filtering system is intended to remove coverage information about unrelated libraries such as standard library headers. To explicitly disable any filters, add an empty filter like --filter ''.

@freesurfer-rge
Copy link
Contributor Author

Thanks for your help - I was able to get code coverage information after that tweak to the command line.

I've opened a PR (#341 ) to add a short section to the user guide about this.

latk pushed a commit that referenced this issue Dec 1, 2019
Using gcovr with CMake-based builds requires additional care.
Based on #340, @freesurfer-rge wrote a new section for the documentation,
and added an example script.
opikalo pushed a commit to opikalo/gcovr that referenced this issue Apr 12, 2020
Using gcovr with CMake-based builds requires additional care.
Based on gcovr#340, @freesurfer-rge wrote a new section for the documentation,
and added an example script.
opikalo pushed a commit to opikalo/gcovr that referenced this issue Apr 18, 2020
Using gcovr with CMake-based builds requires additional care.
Based on gcovr#340, @freesurfer-rge wrote a new section for the documentation,
and added an example script.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Filters related to filters, include/exclude, path handling Type: Question
Projects
None yet
Development

No branches or pull requests

2 participants