[SERVER-33484] Code coverage can't distinguish between files with identical names Created: 26/Feb/18  Updated: 29/Oct/23  Resolved: 21/Mar/18

Status: Closed
Project: Core Server
Component/s: Testing Infrastructure
Affects Version/s: 3.7.2
Fix Version/s: 3.4.15, 3.6.4, 3.7.4

Type: Bug Priority: Major - P3
Reporter: Robert Guo (Inactive) Assignee: Jonathan Abrahams
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v3.6, v3.4
Sprint: TIG 2018-03-26
Participants:

 Description   

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:

[2018/02/26 09:28:29.035] File 'src/mongo/db/session.cpp'
[2018/02/26 09:28:29.035] Lines executed:9.39% of 330
......
[2018/02/26 09:28:31.500] File 'src/mongo/scripting/mozjs/session.cpp'
[2018/02/26 09:28:31.500] Lines executed:90.70% of 43
......
[2018/02/26 09:28:32.055] File 'src/mongo/transport/session.cpp'
[2018/02/26 09:28:32.055] Lines executed:52.94% of 17

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.



 Comments   
Comment by Githook User [ 05/Apr/18 ]

Author:

{'email': 'jonathan@mongodb.com', 'name': 'Jonathan Abrahams', 'username': 'hptabster'}

Message: SERVER-33484 Code coverage can't distinguish between files with identical names, add a unique prefix to all *.gcda.gov files.

(cherry picked from commit 220a857ffc84cf755fa7d387f19d537a249bd099)
Branch: v3.4
https://github.com/mongodb/mongo/commit/bc71dfb5c27cc91096ac9c762b850719cee7751b

Comment by Githook User [ 05/Apr/18 ]

Author:

{'email': 'jonathan@mongodb.com', 'name': 'Jonathan Abrahams', 'username': 'hptabster'}

Message: SERVER-33484 Code coverage can't distinguish between files with identical names, add a unique prefix to all *.gcda.gov files.

(cherry picked from commit 220a857ffc84cf755fa7d387f19d537a249bd099)
Branch: v3.6
https://github.com/mongodb/mongo/commit/2dbb63045b203cc0667f8d2a2e939693c979beb0

Comment by Githook User [ 21/Mar/18 ]

Author:

{'email': 'jonathan@mongodb.com', 'name': 'Jonathan Abrahams', 'username': 'hptabster'}

Message: SERVER-33484 Code coverage can't distinguish between files with identical names, add a unique prefix to all *.gcda.gov files.
Branch: master
https://github.com/mongodb/mongo/commit/220a857ffc84cf755fa7d387f19d537a249bd099

Comment by Jonathan Abrahams [ 20/Mar/18 ]

Looks like we cannot use the --preserve-paths option, as it is not available when generating the intermediate file (using the --intermediate-format option).

Comment by Max Hirschhorn [ 20/Mar/18 ]

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.

jonathan.abrahams, I think Robert had made a similar realization that --hash-filenames is only available in versions of GCC newer than 6.4.

Given that we'd still be far from the 255 character limit on the filename for most filesystems even after mangling in the directories leading up to the file, I'd like to see if we can use the --preserve-paths command line option when invoking gcov on the .gcda file to address this issue for the time being.

$ find src/mongo | python -c 'import sys; print(max(len(line) for line in sys.stdin))'
141

Comment by Jonathan Abrahams [ 19/Mar/18 ]

The version of gcov that we have does not have the --hash-filenames option:

/opt/mongodbtoolchain/v2/bin/gcov --version
gcov (GCC) 5.4.0
...
/opt/mongodbtoolchain/v2/bin/gcov --help
Usage: gcov [OPTION]... SOURCE|OBJ...
 
Print code coverage information.
 
  -h, --help                      Print this help, then exit
  -a, --all-blocks                Show information for every basic block
  -b, --branch-probabilities      Include branch probabilities in output
  -c, --branch-counts             Output counts of branches taken
                                    rather than percentages
  -d, --display-progress          Display progress information
  -f, --function-summaries        Output summaries for each function
  -i, --intermediate-format       Output .gcov file in intermediate text format
  -l, --long-file-names           Use long output file names for included
                                    source files
  -m, --demangled-names           Output demangled function names
  -n, --no-output                 Do not create an output file
  -o, --object-directory DIR|FILE Search for object files in DIR or called FILE
  -p, --preserve-paths            Preserve all pathname components
  -r, --relative-only             Only show data for relative sources
  -s, --source-prefix DIR         Source prefix to elide
  -u, --unconditional-branches    Show unconditional branch counts too
  -v, --version                   Print version number, then exit
 
For bug reporting instructions, please see:
<http://gcc.gnu.org/bugs.html>.

Generated at Thu Feb 08 04:33:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.