Search code examples
ccode-coveragegcovgcovr

Gcovr --object-directory option not working as expected with .gcda files in a different directory than .o files


The program I want to profile with gcovr (or gcov/lcov) is located on a shared filesystem, along with the build directory from compiling the program, and I have multiple workers with which I intend to test my program, in parallel. To solve the race condition problem (the workers will all run my program, therefore all generating gcda files, named the same, in the same location on the shared filesystem), I redirect the gcda files to a separate target directory on each worker (as described here), and I have been running the following command:

gcovr -v -r /absolute/path/to/root --html --html-details -o test-details.html --object-directory=/absolute/path/to/object/dir /absolute/path/to/gcda/dir

where the last path is the search_paths, described here. I expected this to look in /absolute/path/to/root for the program source, /absolute/path/to/object/dir for the .o files, and /absolute/path/to/gcda/dir for the gcda files. However, I ran it with -v and I'm seeing that gcovr is running gcov commands in the form of this, from the root dir:

gcov /absolute/path/to/gcda/dir/file.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /absolute/path/to/gcda/dir

Again, I expected it to run in the form of this (look at the --object-directory path):

gcov /absolute/path/to/gcda/dir/file.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory /absolute/path/to/object/dir

It behaves properly when run like the latter command, but gcovr is running the former. I'm only using gcovr instead of gcov because I have a large project (I know gcovr is built off of lcov). Does anyone know why it is behaving like this? (Is this the way it is supposed to run?) How can I make it so it behaves the way I want? Thanks in advance!


Solution

  • This was cross-posted to the gcovr issue tracker on GitHub, here's the summary:

    Gcovr currently expects that the .gcda and .gcno files are right next to each other (which is usually the case). The search paths affect where gcovr searches for these files. The --object-directory only provides a default value for the search paths, but here you have overridden that with an explicit search path. The gcovr --object-directory option is not passed through to the gcov --object-directory option.

    As of gcovr 4.1 there is no option to solve this. You will have to copy the .gcno files from the build directory into each directory with coverage data. Alternatively you can run gcov manually and then aggregate the .gcov files with gcovr -g ....

    Additional notes:

    • gcov is not interested in the .o object files, only the .gcda files (written during test execution) and the .gcno files (written during compilation).
    • gcovr and lcov are not directly related