[coverage] Update code coverage script to allow multiple input profdata
files.
Right now the coverage script supports an input of a single profdata
files. However, there are times when we may have a test harness that
generates multiple profdata files, and we'd like to use the script to
handle the merging of these multiple profdata files.
The script already knows how to do that, so this CL is simply adding a
command line option to utilize that functionality.
Bug: 1356583
Change-Id: I9200d0e687e95eccaa97759840444881d27fc7d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4378379
Reviewed-by: Prakhar Asthana <[email protected]>
Commit-Queue: Julia Hansbrough <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1123992}
diff --git a/tools/code_coverage/coverage.py b/tools/code_coverage/coverage.py
index b1c62a1..d25edf6f 100755
--- a/tools/code_coverage/coverage.py
+++ b/tools/code_coverage/coverage.py
@@ -975,11 +975,12 @@
'-p',
'--profdata-file',
type=str,
+ action='append'
required=False,
- help='Path to profdata file to use for generating code coverage reports. '
- 'This can be useful if you generated the profdata file seperately in '
- 'your own test harness. This option is ignored if run command(s) are '
- 'already provided above using -c/--command option.')
+ help='Path(s) to profdata file(s) to use for generating code coverage reports. '
+ 'This can be useful if you generated the profdata file seperately in '
+ 'your own test harness. This option is ignored if run command(s) are '
+ 'already provided above using -c/--command option.')
arg_parser.add_argument(
'-f',
@@ -1119,8 +1120,15 @@
args.targets, args.command, args.jobs)
binary_paths = [_GetBinaryPath(command) for command in args.command]
else:
- # An input prof-data file is already provided. Just calculate binary paths.
- profdata_file_path = args.profdata_file
+ # An input prof-data file(s) is already provided.
+ if len(args.profdata_file) == 1:
+ # If it's just one input file, use as-is.
+ profdata_file_path = args.profdata_file
+ else:
+ # Otherwise, there are multiple profdata files and we need to merge them.
+ profdata_file_path = _CreateCoverageProfileDataFromTargetProfDataFiles(args.profdata_file)
+ # Since input prof-data files were provided, we only need to calculate the
+ # binary paths from here.
binary_paths = _GetBinaryPathsFromTargets(args.targets, args.build_dir)
# If the checkout uses the hermetic xcode binaries, then otool must be