gcov generates coverage data files using the name of the source file by default, which is how we invoke it in etc/evergreen.yml
This causes subsequent files of the same name to override previous coverage files. An example is session.cpp. In the mongo repo, there are three session.cpp files in the following directories respectively: src/mongo/db/, src/mongo/transport/, and src/mongo/scripting/mozjs/. When we gather the coverage information at the end of each Evergreen task with: /opt/mongodbtoolchain/v2/bin/gcov -i $gcda_file, a file called session.gcda.gcov is generated and placed at the top-level directory for each of the three session.cpp files. Subsequent files will override previous ones. As a result, only information about one session.cpp is retained; the lucky file is whichever one happens to be parsed last.
This bug can easily be verified by looking at the task log for any code coverage Evergreen build and finding the following lines:
The above can be compared with the content of the content of the "gcov intermediate files - Execution 0" task artifact, which only has one session.gcda.gcov; opening up that file will show that it always corresponds to the last session.cpp
We should use the --preserve-paths or the --hash-filenames flag to have the file names be unique. --hash-filenames seems like the better option to ensure the file names are short but is not supported on the version of gcov that we use.
Thanks to Siyuan Zhou for noticing this issue.