I'm trying to use gcovr 4.1 to generate coverage reports for a shared library project in C++/Qt while running unit tests. I had no problems instrumenting my code but am having trouble getting gcda files for the library and also having trouble getting a complete report for even the unit tests which did yield gcda files.
My project has the following hierarchy after running make
in project-root
and executing the unit tests by calling x64/release/tests
:
project-root/
├─ Makefile
├─ build
| ├─ library/
| | ├─ GeneratedFiles/
| | | └─ <cpp files generated by Qt's moc compiler>
| | └─ obj
| | └─ <*.o, *.gcno, *.gcda> (gcda files show up after Edit #2)
| └─ tests/
| ├─ GeneratedFiles/
| | └─ <cpp files generated by Qt's moc compiler>
| └─ obj
| └─ <*.o, *.gcno, *.gcda>
├─ library/
| ├─ Makefile
| └─ src/
| ├─ subdir/
| | └─ <source files>
| └─ <other source files>
├─ tests/
| ├─ Makefile
| └─ src/
| ├─ subdir/
| | └─ <source files>
| └─ <other source files>
└─ x64/
└─ release/
├─ tests
└─ library.so
Note that Altogether, 11 gcda files exist in the latter directory.build/library/obj
does not contain any gcda files while build/tests/obj
does.
I have tried running gcovr from several directories with various filters. Some examples that at least produced some output:
[user@50f886c6bdeb project-root] gcovr
Attempting to specify source directories:
[user@50f886c6bdeb project-root] gcovr --filter library/src/ --filter tests/src/
Specifying the root with full paths:
[user@50f886c6bdeb project-root] gcovr -r /code/project-root/ --filter /code/project-root/library/src/ --filter /code/project-root/tests/src/
Each of these (along with several other variations) produce identical results.
- I get a long list of "Cannot open source file" messages
- It reports coverage for the files immediately in
tests/src
but not for those intests/src/subdir
even though I can verify that the gcda files in the subdirectory contain data by examining them with gcov.
The cpp files in build/.../GeneratedFiles
are getting instrumented (i.e. have corresponding gcno files); however, I don't really care much whether or not their data is included in the report. I do need to figure out:
How do I get the gcda files to generate for the library while executing the unit tests?- What command line do I use to allow gcovr to pair up the results and source for this structure?
I appreciate any help!
Edit #1: Added locations of Makefiles and clarified on building/running the binary.
Edit #2:
Part of the mystery solved. A typo in my Qt *.pro file prevented -fprofile-arcs from being included in the linker flags for the library.
I found help through this question: gcov: producing .gcda output from shared library?
which led me to this gcc help thread: gcov support for shared library
which eventually got me to check where the compiler was trying to save gcda files by running:
[user@50f886c6bdeb release]strings library.so | grep gcda
There were no entries, so I double checked the build settings for the library and found my mistake. With that fixed, gcda files are produced for the library files, and gcov can create a report with them - including the files in library/src/subdir
(contradictory to the behavior for the tests binary).
However, I still see all of the same "Cannot open source file" messages. Attempting to build a detailed HTML report fails with an error as a result.