blob: 9fe6abdd93d2127c3eaf9af6731c8aa060533705 [file] [log] [blame]
Lei Zhang42a5b51a2022-03-07 19:16:161#!/usr/bin/env vpython3
Avi Drissmandfd880852022-09-15 20:11:092# Copyright 2017 The Chromium Authors
Yuke Liao506e8822017-12-04 16:52:543# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
Abhishek Arya1ec832c2017-12-05 18:06:595"""This script helps to generate code coverage report.
Yuke Liao506e8822017-12-04 16:52:546
Abhishek Arya1ec832c2017-12-05 18:06:597 It uses Clang Source-based Code Coverage -
8 https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
Yuke Liao506e8822017-12-04 16:52:549
Abhishek Arya16f059a2017-12-07 17:47:3210 In order to generate code coverage report, you need to first add
Yuke Liaoab9c44e2018-02-21 00:24:4011 "use_clang_coverage=true" and "is_component_build=false" GN flags to args.gn
12 file in your build output directory (e.g. out/coverage).
Yuke Liao506e8822017-12-04 16:52:5413
Abhishek Arya03911092018-05-21 16:42:3514 * Example usage:
Abhishek Arya1ec832c2017-12-05 18:06:5915
Max Moroza5a95272018-08-31 16:20:5516 gn gen out/coverage \\
Abhishek Arya2f261182019-04-24 17:06:4517 --args="use_clang_coverage=true is_component_build=false\\
18 is_debug=false dcheck_always_on=true"
Abhishek Arya16f059a2017-12-07 17:47:3219 gclient runhooks
Fabrice de Gans0b5511e72022-09-16 22:07:2020 vpython3 tools/code_coverage/coverage.py crypto_unittests url_unittests \\
Abhishek Arya16f059a2017-12-07 17:47:3221 -b out/coverage -o out/report -c 'out/coverage/crypto_unittests' \\
22 -c 'out/coverage/url_unittests --gtest_filter=URLParser.PathURL' \\
23 -f url/ -f crypto/
Abhishek Arya1ec832c2017-12-05 18:06:5924
Abhishek Arya16f059a2017-12-07 17:47:3225 The command above builds crypto_unittests and url_unittests targets and then
26 runs them with specified command line arguments. For url_unittests, it only
27 runs the test URLParser.PathURL. The coverage report is filtered to include
28 only files and sub-directories under url/ and crypto/ directories.
Abhishek Arya1ec832c2017-12-05 18:06:5929
Yuke Liao545db322018-02-15 17:12:0130 If you want to run tests that try to draw to the screen but don't have a
31 display connected, you can run tests in headless mode with xvfb.
32
Abhishek Arya03911092018-05-21 16:42:3533 * Sample flow for running a test target with xvfb (e.g. unit_tests):
Yuke Liao545db322018-02-15 17:12:0134
Fabrice de Gans0b5511e72022-09-16 22:07:2035 vpython3 tools/code_coverage/coverage.py unit_tests -b out/coverage \\
Yuke Liao545db322018-02-15 17:12:0136 -o out/report -c 'python testing/xvfb.py out/coverage/unit_tests'
37
Julia Hansbrough570a8a82023-01-19 19:45:4838 If you are building a fuzz target, in addition to "use_clang_coverage=true"
39 and "is_component_build=false", you must have the following GN flags as well:
40 optimize_for_fuzzing=false
41 use_remoteexec=false
42 is_asan=false (ASAN & other sanitizers are incompatible with coverage)
43 use_libfuzzer=true
Abhishek Arya1ec832c2017-12-05 18:06:5944
Abhishek Arya03911092018-05-21 16:42:3545 * Sample workflow for a fuzz target (e.g. pdfium_fuzzer):
Abhishek Arya1ec832c2017-12-05 18:06:5946
Fabrice de Gans0b5511e72022-09-16 22:07:2047 vpython3 tools/code_coverage/coverage.py pdfium_fuzzer \\
Abhishek Arya16f059a2017-12-07 17:47:3248 -b out/coverage -o out/report \\
Max Moroz13c23182018-11-17 00:23:2249 -c 'out/coverage/pdfium_fuzzer -runs=0 <corpus_dir>' \\
Abhishek Arya16f059a2017-12-07 17:47:3250 -f third_party/pdfium
Abhishek Arya1ec832c2017-12-05 18:06:5951
52 where:
53 <corpus_dir> - directory containing samples files for this format.
Max Moroz13c23182018-11-17 00:23:2254
55 To learn more about generating code coverage reports for fuzz targets, see
John Palmerab8812a2021-05-21 17:03:4356 https://chromium.googlesource.com/chromium/src/+/main/testing/libfuzzer/efficient_fuzzer.md#Code-Coverage
Abhishek Arya1ec832c2017-12-05 18:06:5957
Prakhara6418512023-05-22 17:17:4558 * Sample workflow for running Blink web platform tests:
Abhishek Arya03911092018-05-21 16:42:3559
Fabrice de Gans0b5511e72022-09-16 22:07:2060 vpython3 tools/code_coverage/coverage.py blink_tests \\
Prakhara6418512023-05-22 17:17:4561 -b out/coverage -o out/report -f third_party/blink -wt
Abhishek Arya03911092018-05-21 16:42:3562
Prakhara6418512023-05-22 17:17:4563 -wt flag tells coverage script that it is a web test, and can also be
64 used to pass arguments to run_web_tests.py
65
66 vpython3 tools/code_coverage/coverage.py blink_wpt_tests \\
67 -b out/Release -o out/report
68 -wt external/wpt/webcodecs/per-frame-qp-encoding.https.any.js
Abhishek Arya03911092018-05-21 16:42:3569
Abhishek Arya1ec832c2017-12-05 18:06:5970 For more options, please refer to tools/code_coverage/coverage.py -h.
Yuke Liao8e209fe82018-04-18 20:36:3871
72 For an overview of how code coverage works in Chromium, please refer to
John Palmerab8812a2021-05-21 17:03:4373 https://chromium.googlesource.com/chromium/src/+/main/docs/testing/code_coverage.md
Yuke Liao506e8822017-12-04 16:52:5474"""
75
76from __future__ import print_function
77
78import sys
79
80import argparse
Julia Hansbrough58aa7b0a2023-01-17 21:08:4181import glob
Yuke Liaoea228d02018-01-05 19:10:3382import json
Yuke Liao481d3482018-01-29 19:17:1083import logging
Abhishek Arya03911092018-05-21 16:42:3584import multiprocessing
Yuke Liao506e8822017-12-04 16:52:5485import os
Sajjad Mirza0b96e002020-11-10 19:32:5586import platform
Yuke Liaob2926832018-03-02 17:34:2987import re
88import shlex
Max Moroz025d8952018-05-03 16:33:3489import shutil
Yuke Liao506e8822017-12-04 16:52:5490import subprocess
Choongwoo Hanbd1aa952021-06-09 22:25:3891
Lei Zhang20e2ab752022-10-11 22:11:0092from urllib.request import urlopen
Choongwoo Hanbd1aa952021-06-09 22:25:3893
Abhishek Arya1ec832c2017-12-05 18:06:5994sys.path.append(
95 os.path.join(
Yuke Liaoea228d02018-01-05 19:10:3396 os.path.dirname(__file__), os.path.pardir, os.path.pardir,
97 'third_party'))
Yuke Liaoea228d02018-01-05 19:10:3398from collections import defaultdict
99
Max Moroz1de68d72018-08-21 13:38:18100import coverage_utils
101
Yuke Liao082e99632018-05-18 15:40:40102# Absolute path to the code coverage tools binary. These paths can be
103# overwritten by user specified coverage tool paths.
pasthanab37d5bfd2020-05-28 12:18:31104# Absolute path to the root of the checkout.
105SRC_ROOT_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)),
106 os.path.pardir, os.path.pardir)
107LLVM_BIN_DIR = os.path.join(
108 os.path.join(SRC_ROOT_PATH, 'third_party', 'llvm-build', 'Release+Asserts'),
109 'bin')
Abhishek Arya1c97ea542018-05-10 03:53:19110LLVM_COV_PATH = os.path.join(LLVM_BIN_DIR, 'llvm-cov')
111LLVM_PROFDATA_PATH = os.path.join(LLVM_BIN_DIR, 'llvm-profdata')
Yuke Liao506e8822017-12-04 16:52:54112
Abhishek Arya03911092018-05-21 16:42:35113
Yuke Liao506e8822017-12-04 16:52:54114# Build directory, the value is parsed from command line arguments.
115BUILD_DIR = None
116
117# Output directory for generated artifacts, the value is parsed from command
118# line arguemnts.
119OUTPUT_DIR = None
120
Yuke Liao506e8822017-12-04 16:52:54121# Name of the file extension for profraw data files.
122PROFRAW_FILE_EXTENSION = 'profraw'
123
124# Name of the final profdata file, and this file needs to be passed to
125# "llvm-cov" command in order to call "llvm-cov show" to inspect the
126# line-by-line coverage of specific files.
Max Moroz7c5354f2018-05-06 00:03:48127PROFDATA_FILE_NAME = os.extsep.join(['coverage', 'profdata'])
128
129# Name of the file with summary information generated by llvm-cov export.
130SUMMARY_FILE_NAME = os.extsep.join(['summary', 'json'])
Yuke Liao506e8822017-12-04 16:52:54131
Akekawit Jitprasertf9cb6622021-08-24 17:48:02132# Name of the coverage file in lcov format generated by llvm-cov export.
133LCOV_FILE_NAME = os.extsep.join(['coverage', 'lcov'])
134
Yuke Liao506e8822017-12-04 16:52:54135# Build arg required for generating code coverage data.
136CLANG_COVERAGE_BUILD_ARG = 'use_clang_coverage'
137
Max Moroz7c5354f2018-05-06 00:03:48138LOGS_DIR_NAME = 'logs'
Yuke Liaodd1ec0592018-02-02 01:26:37139
140# Used to extract a mapping between directories and components.
Abhishek Arya1c97ea542018-05-10 03:53:19141COMPONENT_MAPPING_URL = (
142 'https://storage.googleapis.com/chromium-owners/component_map.json')
Yuke Liaodd1ec0592018-02-02 01:26:37143
Yuke Liao80afff32018-03-07 01:26:20144# Caches the results returned by _GetBuildArgs, don't use this variable
145# directly, call _GetBuildArgs instead.
146_BUILD_ARGS = None
147
Abhishek Aryac19bc5ef2018-05-04 22:10:02148# Retry failed merges.
149MERGE_RETRIES = 3
150
Abhishek Aryad35de7e2018-05-10 22:23:04151# Message to guide user to file a bug when everything else fails.
152FILE_BUG_MESSAGE = (
153 'If it persists, please file a bug with the command you used, git revision '
154 'and args.gn config here: '
155 'https://bugs.chromium.org/p/chromium/issues/entry?'
Yuke Liao03c644072019-07-30 18:33:40156 'components=Infra%3ETest%3ECodeCoverage')
Abhishek Aryad35de7e2018-05-10 22:23:04157
Abhishek Aryabd0655d2018-05-21 19:55:24158# String to replace with actual llvm profile path.
159LLVM_PROFILE_FILE_PATH_SUBSTITUTION = '<llvm_profile_file_path>'
160
Yuke Liao082e99632018-05-18 15:40:40161def _ConfigureLLVMCoverageTools(args):
162 """Configures llvm coverage tools."""
163 if args.coverage_tools_dir:
Max Moroz1de68d72018-08-21 13:38:18164 llvm_bin_dir = coverage_utils.GetFullPath(args.coverage_tools_dir)
Yuke Liao082e99632018-05-18 15:40:40165 global LLVM_COV_PATH
166 global LLVM_PROFDATA_PATH
167 LLVM_COV_PATH = os.path.join(llvm_bin_dir, 'llvm-cov')
168 LLVM_PROFDATA_PATH = os.path.join(llvm_bin_dir, 'llvm-profdata')
169 else:
Choongwoo Hanbd1aa952021-06-09 22:25:38170 subprocess.check_call([
Akekawit Jitprasert928671e2021-09-20 18:40:58171 sys.executable, 'tools/clang/scripts/update.py', '--package',
172 'coverage_tools'
Choongwoo Hanbd1aa952021-06-09 22:25:38173 ])
Brent McBrideb25b177a42020-05-11 18:13:06174
175 if coverage_utils.GetHostPlatform() == 'win':
176 LLVM_COV_PATH += '.exe'
177 LLVM_PROFDATA_PATH += '.exe'
Yuke Liao082e99632018-05-18 15:40:40178
179 coverage_tools_exist = (
180 os.path.exists(LLVM_COV_PATH) and os.path.exists(LLVM_PROFDATA_PATH))
181 assert coverage_tools_exist, ('Cannot find coverage tools, please make sure '
182 'both \'%s\' and \'%s\' exist.') % (
183 LLVM_COV_PATH, LLVM_PROFDATA_PATH)
184
Abhishek Arya2f261182019-04-24 17:06:45185
Abhishek Arya1c97ea542018-05-10 03:53:19186def _GetPathWithLLVMSymbolizerDir():
187 """Add llvm-symbolizer directory to path for symbolized stacks."""
188 path = os.getenv('PATH')
189 dirs = path.split(os.pathsep)
190 if LLVM_BIN_DIR in dirs:
191 return path
192
193 return path + os.pathsep + LLVM_BIN_DIR
194
195
Yuke Liaoc60b2d02018-03-02 21:40:43196def _GetTargetOS():
197 """Returns the target os specified in args.gn file.
198
199 Returns an empty string is target_os is not specified.
200 """
Yuke Liao80afff32018-03-07 01:26:20201 build_args = _GetBuildArgs()
Yuke Liaoc60b2d02018-03-02 21:40:43202 return build_args['target_os'] if 'target_os' in build_args else ''
203
204
Ben Joyce88282362021-01-29 23:53:31205def _IsAndroid():
206 """Returns true if the target_os specified in args.gn file is android"""
207 return _GetTargetOS() == 'android'
208
209
Yuke Liaob2926832018-03-02 17:34:29210def _IsIOS():
Yuke Liaoa0c8c2f2018-02-28 20:14:10211 """Returns true if the target_os specified in args.gn file is ios"""
Yuke Liaoc60b2d02018-03-02 21:40:43212 return _GetTargetOS() == 'ios'
Yuke Liaoa0c8c2f2018-02-28 20:14:10213
214
Sahel Sharify38cabdc2020-01-16 00:40:01215def _GeneratePerFileLineByLineCoverageInFormat(binary_paths, profdata_file_path,
216 filters, ignore_filename_regex,
217 output_format):
218 """Generates per file line-by-line coverage in html or text using
219 'llvm-cov show'.
Yuke Liao506e8822017-12-04 16:52:54220
Sahel Sharify38cabdc2020-01-16 00:40:01221 For a file with absolute path /a/b/x.cc, a html/txt report is generated as:
222 OUTPUT_DIR/coverage/a/b/x.cc.[html|txt]. For html format, an index html file
223 is also generated as: OUTPUT_DIR/index.html.
Yuke Liao506e8822017-12-04 16:52:54224
225 Args:
226 binary_paths: A list of paths to the instrumented binaries.
227 profdata_file_path: A path to the profdata file.
Yuke Liao66da1732017-12-05 22:19:42228 filters: A list of directories and files to get coverage for.
Sahel Sharify38cabdc2020-01-16 00:40:01229 ignore_filename_regex: A regular expression for skipping source code files
230 with certain file paths.
231 output_format: The output format of generated report files.
Yuke Liao506e8822017-12-04 16:52:54232 """
Yuke Liao506e8822017-12-04 16:52:54233 # llvm-cov show [options] -instr-profile PROFILE BIN [-object BIN,...]
234 # [[-object BIN]] [SOURCES]
235 # NOTE: For object files, the first one is specified as a positional argument,
236 # and the rest are specified as keyword argument.
Yuke Liao481d3482018-01-29 19:17:10237 logging.debug('Generating per file line by line coverage reports using '
Abhishek Aryafb70b532018-05-06 17:47:40238 '"llvm-cov show" command.')
Sahel Sharify38cabdc2020-01-16 00:40:01239
Abhishek Arya1ec832c2017-12-05 18:06:59240 subprocess_cmd = [
Sahel Sharify38cabdc2020-01-16 00:40:01241 LLVM_COV_PATH, 'show', '-format={}'.format(output_format),
Choongwoo Han56752522021-06-10 17:38:34242 '-compilation-dir={}'.format(BUILD_DIR),
Abhishek Arya1ec832c2017-12-05 18:06:59243 '-output-dir={}'.format(OUTPUT_DIR),
244 '-instr-profile={}'.format(profdata_file_path), binary_paths[0]
245 ]
246 subprocess_cmd.extend(
247 ['-object=' + binary_path for binary_path in binary_paths[1:]])
Yuke Liaob2926832018-03-02 17:34:29248 _AddArchArgumentForIOSIfNeeded(subprocess_cmd, len(binary_paths))
Max Moroz1de68d72018-08-21 13:38:18249 if coverage_utils.GetHostPlatform() in ['linux', 'mac']:
Ryan Sleeviae19b2c32018-05-15 22:36:17250 subprocess_cmd.extend(['-Xdemangler', 'c++filt', '-Xdemangler', '-n'])
Yuke Liao66da1732017-12-05 22:19:42251 subprocess_cmd.extend(filters)
Yuke Liao0e4c8682018-04-18 21:06:59252 if ignore_filename_regex:
253 subprocess_cmd.append('-ignore-filename-regex=%s' % ignore_filename_regex)
254
Yuke Liao506e8822017-12-04 16:52:54255 subprocess.check_call(subprocess_cmd)
Max Moroz025d8952018-05-03 16:33:34256
Abhishek Aryafb70b532018-05-06 17:47:40257 logging.debug('Finished running "llvm-cov show" command.')
Yuke Liao506e8822017-12-04 16:52:54258
259
Lei Zhang42a5b51a2022-03-07 19:16:16260def _GeneratePerFileLineByLineCoverageInLcov(binary_paths, profdata_file_path,
261 filters, ignore_filename_regex):
Akekawit Jitprasertf9cb6622021-08-24 17:48:02262 """Generates per file line-by-line coverage using "llvm-cov export".
263
264 Args:
265 binary_paths: A list of paths to the instrumented binaries.
266 profdata_file_path: A path to the profdata file.
267 filters: A list of directories and files to get coverage for.
268 ignore_filename_regex: A regular expression for skipping source code files
269 with certain file paths.
270 """
271 logging.debug('Generating per file line by line coverage reports using '
272 '"llvm-cov export" command.')
273 for path in binary_paths:
274 if not os.path.exists(path):
275 logging.error("Binary %s does not exist", path)
276 subprocess_cmd = [
277 LLVM_COV_PATH, 'export', '-format=lcov',
278 '-instr-profile=' + profdata_file_path, binary_paths[0]
279 ]
280 subprocess_cmd.extend(
281 ['-object=' + binary_path for binary_path in binary_paths[1:]])
282 _AddArchArgumentForIOSIfNeeded(subprocess_cmd, len(binary_paths))
283 subprocess_cmd.extend(filters)
284 if ignore_filename_regex:
285 subprocess_cmd.append('-ignore-filename-regex=%s' % ignore_filename_regex)
286
287 # Write output on the disk to be used by code coverage bot.
288 with open(_GetLcovFilePath(), 'w') as f:
289 subprocess.check_call(subprocess_cmd, stdout=f)
290
291 logging.debug('Finished running "llvm-cov export" command.')
292
293
Max Moroz7c5354f2018-05-06 00:03:48294def _GetLogsDirectoryPath():
295 """Path to the logs directory."""
Max Moroz1de68d72018-08-21 13:38:18296 return os.path.join(
297 coverage_utils.GetCoverageReportRootDirPath(OUTPUT_DIR), LOGS_DIR_NAME)
Max Moroz7c5354f2018-05-06 00:03:48298
299
300def _GetProfdataFilePath():
301 """Path to the resulting .profdata file."""
Max Moroz1de68d72018-08-21 13:38:18302 return os.path.join(
303 coverage_utils.GetCoverageReportRootDirPath(OUTPUT_DIR),
304 PROFDATA_FILE_NAME)
Max Moroz7c5354f2018-05-06 00:03:48305
306
307def _GetSummaryFilePath():
308 """The JSON file that contains coverage summary written by llvm-cov export."""
Max Moroz1de68d72018-08-21 13:38:18309 return os.path.join(
310 coverage_utils.GetCoverageReportRootDirPath(OUTPUT_DIR),
311 SUMMARY_FILE_NAME)
Yuke Liaoea228d02018-01-05 19:10:33312
313
Akekawit Jitprasertf9cb6622021-08-24 17:48:02314def _GetLcovFilePath():
315 """The LCOV file that contains coverage data written by llvm-cov export."""
316 return os.path.join(
317 coverage_utils.GetCoverageReportRootDirPath(OUTPUT_DIR),
318 LCOV_FILE_NAME)
319
320
Yuke Liao506e8822017-12-04 16:52:54321def _CreateCoverageProfileDataForTargets(targets, commands, jobs_count=None):
322 """Builds and runs target to generate the coverage profile data.
323
324 Args:
325 targets: A list of targets to build with coverage instrumentation.
326 commands: A list of commands used to run the targets.
327 jobs_count: Number of jobs to run in parallel for building. If None, a
328 default value is derived based on CPUs availability.
329
330 Returns:
331 A relative path to the generated profdata file.
332 """
333 _BuildTargets(targets, jobs_count)
Abhishek Aryac19bc5ef2018-05-04 22:10:02334 target_profdata_file_paths = _GetTargetProfDataPathsByExecutingCommands(
Abhishek Arya1ec832c2017-12-05 18:06:59335 targets, commands)
Abhishek Aryac19bc5ef2018-05-04 22:10:02336 coverage_profdata_file_path = (
337 _CreateCoverageProfileDataFromTargetProfDataFiles(
338 target_profdata_file_paths))
Yuke Liao506e8822017-12-04 16:52:54339
Abhishek Aryac19bc5ef2018-05-04 22:10:02340 for target_profdata_file_path in target_profdata_file_paths:
341 os.remove(target_profdata_file_path)
Yuke Liaod4a9865202018-01-12 23:17:52342
Abhishek Aryac19bc5ef2018-05-04 22:10:02343 return coverage_profdata_file_path
Yuke Liao506e8822017-12-04 16:52:54344
345
346def _BuildTargets(targets, jobs_count):
347 """Builds target with Clang coverage instrumentation.
348
349 This function requires current working directory to be the root of checkout.
350
351 Args:
352 targets: A list of targets to build with coverage instrumentation.
353 jobs_count: Number of jobs to run in parallel for compilation. If None, a
354 default value is derived based on CPUs availability.
Yuke Liao506e8822017-12-04 16:52:54355 """
Abhishek Aryafb70b532018-05-06 17:47:40356 logging.info('Building %s.', str(targets))
Brent McBrideb25b177a42020-05-11 18:13:06357 autoninja = 'autoninja'
358 if coverage_utils.GetHostPlatform() == 'win':
359 autoninja += '.bat'
Yuke Liao506e8822017-12-04 16:52:54360
Brent McBrideb25b177a42020-05-11 18:13:06361 subprocess_cmd = [autoninja, '-C', BUILD_DIR]
Yuke Liao506e8822017-12-04 16:52:54362 if jobs_count is not None:
363 subprocess_cmd.append('-j' + str(jobs_count))
364
365 subprocess_cmd.extend(targets)
Arthur Eubanks97d1d4b2023-08-16 03:57:43366 subprocess.check_call(subprocess_cmd, shell=os.name == 'nt')
Abhishek Aryafb70b532018-05-06 17:47:40367 logging.debug('Finished building %s.', str(targets))
Yuke Liao506e8822017-12-04 16:52:54368
369
Abhishek Aryac19bc5ef2018-05-04 22:10:02370def _GetTargetProfDataPathsByExecutingCommands(targets, commands):
Yuke Liao506e8822017-12-04 16:52:54371 """Runs commands and returns the relative paths to the profraw data files.
372
373 Args:
374 targets: A list of targets built with coverage instrumentation.
375 commands: A list of commands used to run the targets.
376
377 Returns:
378 A list of relative paths to the generated profraw data files.
379 """
Abhishek Aryafb70b532018-05-06 17:47:40380 logging.debug('Executing the test commands.')
Yuke Liao481d3482018-01-29 19:17:10381
Yuke Liao506e8822017-12-04 16:52:54382 # Remove existing profraw data files.
Max Moroz1de68d72018-08-21 13:38:18383 report_root_dir = coverage_utils.GetCoverageReportRootDirPath(OUTPUT_DIR)
384 for file_or_dir in os.listdir(report_root_dir):
Yuke Liao506e8822017-12-04 16:52:54385 if file_or_dir.endswith(PROFRAW_FILE_EXTENSION):
Max Moroz1de68d72018-08-21 13:38:18386 os.remove(os.path.join(report_root_dir, file_or_dir))
Max Moroz7c5354f2018-05-06 00:03:48387
388 # Ensure that logs directory exists.
389 if not os.path.exists(_GetLogsDirectoryPath()):
390 os.makedirs(_GetLogsDirectoryPath())
Yuke Liao506e8822017-12-04 16:52:54391
Abhishek Aryac19bc5ef2018-05-04 22:10:02392 profdata_file_paths = []
Yuke Liaoa0c8c2f2018-02-28 20:14:10393
Yuke Liaod4a9865202018-01-12 23:17:52394 # Run all test targets to generate profraw data files.
Yuke Liao506e8822017-12-04 16:52:54395 for target, command in zip(targets, commands):
Max Moroz7c5354f2018-05-06 00:03:48396 output_file_name = os.extsep.join([target + '_output', 'log'])
397 output_file_path = os.path.join(_GetLogsDirectoryPath(), output_file_name)
Yuke Liaoa0c8c2f2018-02-28 20:14:10398
Abhishek Aryac19bc5ef2018-05-04 22:10:02399 profdata_file_path = None
Prakhar65d63832021-06-16 23:01:37400 for _ in range(MERGE_RETRIES):
Abhishek Aryafb70b532018-05-06 17:47:40401 logging.info('Running command: "%s", the output is redirected to "%s".',
Abhishek Aryac19bc5ef2018-05-04 22:10:02402 command, output_file_path)
Yuke Liaoa0c8c2f2018-02-28 20:14:10403
Abhishek Aryac19bc5ef2018-05-04 22:10:02404 if _IsIOSCommand(command):
405 # On iOS platform, due to lack of write permissions, profraw files are
406 # generated outside of the OUTPUT_DIR, and the exact paths are contained
407 # in the output of the command execution.
Abhishek Arya03911092018-05-21 16:42:35408 output = _ExecuteIOSCommand(command, output_file_path)
Abhishek Aryac19bc5ef2018-05-04 22:10:02409 else:
410 # On other platforms, profraw files are generated inside the OUTPUT_DIR.
Abhishek Arya03911092018-05-21 16:42:35411 output = _ExecuteCommand(target, command, output_file_path)
Abhishek Aryac19bc5ef2018-05-04 22:10:02412
413 profraw_file_paths = []
414 if _IsIOS():
Yuke Liao9c2c70b2018-05-23 15:37:57415 profraw_file_paths = [_GetProfrawDataFileByParsingOutput(output)]
Ben Joyce88282362021-01-29 23:53:31416 elif _IsAndroid():
417 android_coverage_dir = os.path.join(BUILD_DIR, 'coverage')
418 for r, _, files in os.walk(android_coverage_dir):
419 for f in files:
420 if f.endswith(PROFRAW_FILE_EXTENSION):
421 profraw_file_paths.append(os.path.join(r, f))
Abhishek Aryac19bc5ef2018-05-04 22:10:02422 else:
Max Moroz1de68d72018-08-21 13:38:18423 for file_or_dir in os.listdir(report_root_dir):
Abhishek Aryac19bc5ef2018-05-04 22:10:02424 if file_or_dir.endswith(PROFRAW_FILE_EXTENSION):
Max Moroz7c5354f2018-05-06 00:03:48425 profraw_file_paths.append(
Max Moroz1de68d72018-08-21 13:38:18426 os.path.join(report_root_dir, file_or_dir))
Abhishek Aryac19bc5ef2018-05-04 22:10:02427
428 assert profraw_file_paths, (
Abhishek Aryafb70b532018-05-06 17:47:40429 'Running target "%s" failed to generate any profraw data file, '
Abhishek Aryad35de7e2018-05-10 22:23:04430 'please make sure the binary exists, is properly instrumented and '
431 'does not crash. %s' % (target, FILE_BUG_MESSAGE))
Abhishek Aryac19bc5ef2018-05-04 22:10:02432
Yuke Liao9c2c70b2018-05-23 15:37:57433 assert isinstance(profraw_file_paths, list), (
Max Moroz1de68d72018-08-21 13:38:18434 'Variable \'profraw_file_paths\' is expected to be of type \'list\', '
435 'but it is a %s. %s' % (type(profraw_file_paths), FILE_BUG_MESSAGE))
Yuke Liao9c2c70b2018-05-23 15:37:57436
Abhishek Aryac19bc5ef2018-05-04 22:10:02437 try:
438 profdata_file_path = _CreateTargetProfDataFileFromProfRawFiles(
439 target, profraw_file_paths)
440 break
441 except Exception:
Abhishek Aryad35de7e2018-05-10 22:23:04442 logging.info('Retrying...')
Abhishek Aryac19bc5ef2018-05-04 22:10:02443 finally:
444 # Remove profraw files now so that they are not used in next iteration.
445 for profraw_file_path in profraw_file_paths:
446 os.remove(profraw_file_path)
447
448 assert profdata_file_path, (
Abhishek Aryad35de7e2018-05-10 22:23:04449 'Failed to merge target "%s" profraw files after %d retries. %s' %
450 (target, MERGE_RETRIES, FILE_BUG_MESSAGE))
Abhishek Aryac19bc5ef2018-05-04 22:10:02451 profdata_file_paths.append(profdata_file_path)
Yuke Liao506e8822017-12-04 16:52:54452
Abhishek Aryafb70b532018-05-06 17:47:40453 logging.debug('Finished executing the test commands.')
Yuke Liao481d3482018-01-29 19:17:10454
Abhishek Aryac19bc5ef2018-05-04 22:10:02455 return profdata_file_paths
Yuke Liao506e8822017-12-04 16:52:54456
457
Abhishek Arya03911092018-05-21 16:42:35458def _GetEnvironmentVars(profraw_file_path):
459 """Return environment vars for subprocess, given a profraw file path."""
460 env = os.environ.copy()
461 env.update({
462 'LLVM_PROFILE_FILE': profraw_file_path,
463 'PATH': _GetPathWithLLVMSymbolizerDir()
464 })
465 return env
466
467
Sajjad Mirza0b96e002020-11-10 19:32:55468def _SplitCommand(command):
469 """Split a command string into parts in a platform-specific way."""
470 if coverage_utils.GetHostPlatform() == 'win':
471 return command.split()
Julia Hansbrough58aa7b0a2023-01-17 21:08:41472 split_command = shlex.split(command)
473 # Python's subprocess does not do glob expansion, so we expand it out here.
474 new_command = []
475 for item in split_command:
476 if '*' in item:
477 files = glob.glob(item)
478 for file in files:
479 new_command.append(file)
480 else:
481 new_command.append(item)
482 return new_command
Sajjad Mirza0b96e002020-11-10 19:32:55483
484
Abhishek Arya03911092018-05-21 16:42:35485def _ExecuteCommand(target, command, output_file_path):
Yuke Liaoa0c8c2f2018-02-28 20:14:10486 """Runs a single command and generates a profraw data file."""
Yuke Liaod4a9865202018-01-12 23:17:52487 # Per Clang "Source-based Code Coverage" doc:
Yuke Liao27349c92018-03-22 21:10:01488 #
Max Morozd73e45f2018-04-24 18:32:47489 # "%p" expands out to the process ID. It's not used by this scripts due to:
490 # 1) If a target program spawns too many processess, it may exhaust all disk
491 # space available. For example, unit_tests writes thousands of .profraw
492 # files each of size 1GB+.
493 # 2) If a target binary uses shared libraries, coverage profile data for them
494 # will be missing, resulting in incomplete coverage reports.
Yuke Liao27349c92018-03-22 21:10:01495 #
Yuke Liaod4a9865202018-01-12 23:17:52496 # "%Nm" expands out to the instrumented binary's signature. When this pattern
497 # is specified, the runtime creates a pool of N raw profiles which are used
498 # for on-line profile merging. The runtime takes care of selecting a raw
499 # profile from the pool, locking it, and updating it before the program exits.
Yuke Liaod4a9865202018-01-12 23:17:52500 # N must be between 1 and 9. The merge pool specifier can only occur once per
501 # filename pattern.
502 #
Max Morozd73e45f2018-04-24 18:32:47503 # "%1m" is used when tests run in single process, such as fuzz targets.
Yuke Liao27349c92018-03-22 21:10:01504 #
Max Morozd73e45f2018-04-24 18:32:47505 # For other cases, "%4m" is chosen as it creates some level of parallelism,
506 # but it's not too big to consume too much computing resource or disk space.
Alan Zhao02658792023-12-11 21:47:18507 #
508 # "%c" expands out to nothing, but it enables the continuous coverage mode
509 # where profile counter updates are continuously written to the profraw file.
Max Morozd73e45f2018-04-24 18:32:47510 profile_pattern_string = '%1m' if _IsFuzzerTarget(target) else '%4m'
Abhishek Arya1ec832c2017-12-05 18:06:59511 expected_profraw_file_name = os.extsep.join(
Alan Zhao02658792023-12-11 21:47:18512 [target, '%c', profile_pattern_string, PROFRAW_FILE_EXTENSION])
Max Moroz1de68d72018-08-21 13:38:18513 expected_profraw_file_path = os.path.join(
514 coverage_utils.GetCoverageReportRootDirPath(OUTPUT_DIR),
515 expected_profraw_file_name)
Abhishek Aryabd0655d2018-05-21 19:55:24516 command = command.replace(LLVM_PROFILE_FILE_PATH_SUBSTITUTION,
517 expected_profraw_file_path)
Yuke Liao506e8822017-12-04 16:52:54518
Yuke Liaoa0c8c2f2018-02-28 20:14:10519 try:
Max Moroz7c5354f2018-05-06 00:03:48520 # Some fuzz targets or tests may write into stderr, redirect it as well.
Abhishek Arya03911092018-05-21 16:42:35521 with open(output_file_path, 'wb') as output_file_handle:
Sajjad Mirza0b96e002020-11-10 19:32:55522 subprocess.check_call(_SplitCommand(command),
523 stdout=output_file_handle,
524 stderr=subprocess.STDOUT,
525 env=_GetEnvironmentVars(expected_profraw_file_path))
Yuke Liaoa0c8c2f2018-02-28 20:14:10526 except subprocess.CalledProcessError as e:
Abhishek Arya03911092018-05-21 16:42:35527 logging.warning('Command: "%s" exited with non-zero return code.', command)
Yuke Liaoa0c8c2f2018-02-28 20:14:10528
Abhishek Arya03911092018-05-21 16:42:35529 return open(output_file_path, 'rb').read()
Yuke Liaoa0c8c2f2018-02-28 20:14:10530
531
Yuke Liao27349c92018-03-22 21:10:01532def _IsFuzzerTarget(target):
533 """Returns true if the target is a fuzzer target."""
534 build_args = _GetBuildArgs()
535 use_libfuzzer = ('use_libfuzzer' in build_args and
536 build_args['use_libfuzzer'] == 'true')
Adrian Taylor9470000f2023-03-10 16:18:25537 use_centipede = ('use_centipede' in build_args
538 and build_args['use_centipede'] == 'true')
539 return (use_libfuzzer or use_centipede) and target.endswith('_fuzzer')
Yuke Liao27349c92018-03-22 21:10:01540
541
Abhishek Arya03911092018-05-21 16:42:35542def _ExecuteIOSCommand(command, output_file_path):
Yuke Liaoa0c8c2f2018-02-28 20:14:10543 """Runs a single iOS command and generates a profraw data file.
544
545 iOS application doesn't have write access to folders outside of the app, so
546 it's impossible to instruct the app to flush the profraw data file to the
547 desired location. The profraw data file will be generated somewhere within the
548 application's Documents folder, and the full path can be obtained by parsing
549 the output.
550 """
Yuke Liaob2926832018-03-02 17:34:29551 assert _IsIOSCommand(command)
552
553 # After running tests, iossim generates a profraw data file, it won't be
554 # needed anyway, so dump it into the OUTPUT_DIR to avoid polluting the
555 # checkout.
556 iossim_profraw_file_path = os.path.join(
557 OUTPUT_DIR, os.extsep.join(['iossim', PROFRAW_FILE_EXTENSION]))
Abhishek Aryabd0655d2018-05-21 19:55:24558 command = command.replace(LLVM_PROFILE_FILE_PATH_SUBSTITUTION,
559 iossim_profraw_file_path)
Yuke Liaoa0c8c2f2018-02-28 20:14:10560
561 try:
Abhishek Arya03911092018-05-21 16:42:35562 with open(output_file_path, 'wb') as output_file_handle:
Sajjad Mirza0b96e002020-11-10 19:32:55563 subprocess.check_call(_SplitCommand(command),
564 stdout=output_file_handle,
565 stderr=subprocess.STDOUT,
566 env=_GetEnvironmentVars(iossim_profraw_file_path))
Yuke Liaoa0c8c2f2018-02-28 20:14:10567 except subprocess.CalledProcessError as e:
568 # iossim emits non-zero return code even if tests run successfully, so
569 # ignore the return code.
Abhishek Arya03911092018-05-21 16:42:35570 pass
Yuke Liaoa0c8c2f2018-02-28 20:14:10571
Abhishek Arya03911092018-05-21 16:42:35572 return open(output_file_path, 'rb').read()
Yuke Liaoa0c8c2f2018-02-28 20:14:10573
574
575def _GetProfrawDataFileByParsingOutput(output):
576 """Returns the path to the profraw data file obtained by parsing the output.
577
578 The output of running the test target has no format, but it is guaranteed to
579 have a single line containing the path to the generated profraw data file.
580 NOTE: This should only be called when target os is iOS.
581 """
Yuke Liaob2926832018-03-02 17:34:29582 assert _IsIOS()
Yuke Liaoa0c8c2f2018-02-28 20:14:10583
Yuke Liaob2926832018-03-02 17:34:29584 output_by_lines = ''.join(output).splitlines()
585 profraw_file_pattern = re.compile('.*Coverage data at (.*coverage\.profraw).')
Yuke Liaoa0c8c2f2018-02-28 20:14:10586
587 for line in output_by_lines:
Yuke Liaob2926832018-03-02 17:34:29588 result = profraw_file_pattern.match(line)
589 if result:
590 return result.group(1)
Yuke Liaoa0c8c2f2018-02-28 20:14:10591
592 assert False, ('No profraw data file was generated, did you call '
593 'coverage_util::ConfigureCoverageReportPath() in test setup? '
594 'Please refer to base/test/test_support_ios.mm for example.')
Yuke Liao506e8822017-12-04 16:52:54595
596
Abhishek Aryac19bc5ef2018-05-04 22:10:02597def _CreateCoverageProfileDataFromTargetProfDataFiles(profdata_file_paths):
598 """Returns a relative path to coverage profdata file by merging target
599 profdata files.
Yuke Liao506e8822017-12-04 16:52:54600
601 Args:
Abhishek Aryac19bc5ef2018-05-04 22:10:02602 profdata_file_paths: A list of relative paths to the profdata data files
603 that are to be merged.
Yuke Liao506e8822017-12-04 16:52:54604
605 Returns:
Abhishek Aryac19bc5ef2018-05-04 22:10:02606 A relative path to the merged coverage profdata file.
Yuke Liao506e8822017-12-04 16:52:54607
608 Raises:
Abhishek Aryac19bc5ef2018-05-04 22:10:02609 CalledProcessError: An error occurred merging profdata files.
Yuke Liao506e8822017-12-04 16:52:54610 """
Abhishek Aryafb70b532018-05-06 17:47:40611 logging.info('Creating the coverage profile data file.')
612 logging.debug('Merging target profraw files to create target profdata file.')
Max Moroz7c5354f2018-05-06 00:03:48613 profdata_file_path = _GetProfdataFilePath()
Yuke Liao506e8822017-12-04 16:52:54614 try:
Abhishek Arya1ec832c2017-12-05 18:06:59615 subprocess_cmd = [
616 LLVM_PROFDATA_PATH, 'merge', '-o', profdata_file_path, '-sparse=true'
617 ]
Abhishek Aryac19bc5ef2018-05-04 22:10:02618 subprocess_cmd.extend(profdata_file_paths)
Abhishek Aryae5811afa2018-05-24 03:56:01619
620 output = subprocess.check_output(subprocess_cmd)
Max Moroz1de68d72018-08-21 13:38:18621 logging.debug('Merge output: %s', output)
Abhishek Aryac19bc5ef2018-05-04 22:10:02622 except subprocess.CalledProcessError as error:
Abhishek Aryad35de7e2018-05-10 22:23:04623 logging.error(
624 'Failed to merge target profdata files to create coverage profdata. %s',
625 FILE_BUG_MESSAGE)
Abhishek Aryac19bc5ef2018-05-04 22:10:02626 raise error
627
Abhishek Aryafb70b532018-05-06 17:47:40628 logging.debug('Finished merging target profdata files.')
629 logging.info('Code coverage profile data is created as: "%s".',
Abhishek Aryac19bc5ef2018-05-04 22:10:02630 profdata_file_path)
631 return profdata_file_path
632
633
634def _CreateTargetProfDataFileFromProfRawFiles(target, profraw_file_paths):
635 """Returns a relative path to target profdata file by merging target
636 profraw files.
637
638 Args:
639 profraw_file_paths: A list of relative paths to the profdata data files
640 that are to be merged.
641
642 Returns:
643 A relative path to the merged coverage profdata file.
644
645 Raises:
646 CalledProcessError: An error occurred merging profdata files.
647 """
Abhishek Aryafb70b532018-05-06 17:47:40648 logging.info('Creating target profile data file.')
649 logging.debug('Merging target profraw files to create target profdata file.')
Abhishek Aryac19bc5ef2018-05-04 22:10:02650 profdata_file_path = os.path.join(OUTPUT_DIR, '%s.profdata' % target)
651
652 try:
653 subprocess_cmd = [
654 LLVM_PROFDATA_PATH, 'merge', '-o', profdata_file_path, '-sparse=true'
655 ]
Yuke Liao506e8822017-12-04 16:52:54656 subprocess_cmd.extend(profraw_file_paths)
Abhishek Aryae5811afa2018-05-24 03:56:01657 output = subprocess.check_output(subprocess_cmd)
Max Moroz1de68d72018-08-21 13:38:18658 logging.debug('Merge output: %s', output)
Yuke Liao506e8822017-12-04 16:52:54659 except subprocess.CalledProcessError as error:
Abhishek Aryad35de7e2018-05-10 22:23:04660 logging.error(
661 'Failed to merge target profraw files to create target profdata.')
Yuke Liao506e8822017-12-04 16:52:54662 raise error
663
Abhishek Aryafb70b532018-05-06 17:47:40664 logging.debug('Finished merging target profraw files.')
665 logging.info('Target "%s" profile data is created as: "%s".', target,
Yuke Liao481d3482018-01-29 19:17:10666 profdata_file_path)
Yuke Liao506e8822017-12-04 16:52:54667 return profdata_file_path
668
669
Yuke Liao0e4c8682018-04-18 21:06:59670def _GeneratePerFileCoverageSummary(binary_paths, profdata_file_path, filters,
671 ignore_filename_regex):
Yuke Liaoea228d02018-01-05 19:10:33672 """Generates per file coverage summary using "llvm-cov export" command."""
673 # llvm-cov export [options] -instr-profile PROFILE BIN [-object BIN,...]
674 # [[-object BIN]] [SOURCES].
675 # NOTE: For object files, the first one is specified as a positional argument,
676 # and the rest are specified as keyword argument.
Yuke Liao481d3482018-01-29 19:17:10677 logging.debug('Generating per-file code coverage summary using "llvm-cov '
Abhishek Aryafb70b532018-05-06 17:47:40678 'export -summary-only" command.')
Sajjad Mirza07f52332020-11-11 01:50:47679 for path in binary_paths:
680 if not os.path.exists(path):
681 logging.error("Binary %s does not exist", path)
Yuke Liaoea228d02018-01-05 19:10:33682 subprocess_cmd = [
683 LLVM_COV_PATH, 'export', '-summary-only',
Choongwoo Han56752522021-06-10 17:38:34684 '-compilation-dir={}'.format(BUILD_DIR),
Yuke Liaoea228d02018-01-05 19:10:33685 '-instr-profile=' + profdata_file_path, binary_paths[0]
686 ]
687 subprocess_cmd.extend(
688 ['-object=' + binary_path for binary_path in binary_paths[1:]])
Yuke Liaob2926832018-03-02 17:34:29689 _AddArchArgumentForIOSIfNeeded(subprocess_cmd, len(binary_paths))
Yuke Liaoea228d02018-01-05 19:10:33690 subprocess_cmd.extend(filters)
Yuke Liao0e4c8682018-04-18 21:06:59691 if ignore_filename_regex:
692 subprocess_cmd.append('-ignore-filename-regex=%s' % ignore_filename_regex)
Yuke Liaoea228d02018-01-05 19:10:33693
Max Moroz7c5354f2018-05-06 00:03:48694 export_output = subprocess.check_output(subprocess_cmd)
695
696 # Write output on the disk to be used by code coverage bot.
Prakhar65d63832021-06-16 23:01:37697 with open(_GetSummaryFilePath(), 'wb') as f:
Max Moroz7c5354f2018-05-06 00:03:48698 f.write(export_output)
699
Max Moroz1de68d72018-08-21 13:38:18700 return export_output
Yuke Liaoea228d02018-01-05 19:10:33701
702
Yuke Liaob2926832018-03-02 17:34:29703def _AddArchArgumentForIOSIfNeeded(cmd_list, num_archs):
704 """Appends -arch arguments to the command list if it's ios platform.
705
706 iOS binaries are universal binaries, and require specifying the architecture
707 to use, and one architecture needs to be specified for each binary.
708 """
709 if _IsIOS():
710 cmd_list.extend(['-arch=x86_64'] * num_archs)
711
712
Yuke Liao506e8822017-12-04 16:52:54713def _GetBinaryPath(command):
714 """Returns a relative path to the binary to be run by the command.
715
Yuke Liao545db322018-02-15 17:12:01716 Currently, following types of commands are supported (e.g. url_unittests):
717 1. Run test binary direcly: "out/coverage/url_unittests <arguments>"
718 2. Use xvfb.
719 2.1. "python testing/xvfb.py out/coverage/url_unittests <arguments>"
720 2.2. "testing/xvfb.py out/coverage/url_unittests <arguments>"
Yuke Liao92107f02018-03-07 01:44:37721 3. Use iossim to run tests on iOS platform, please refer to testing/iossim.mm
722 for its usage.
Yuke Liaoa0c8c2f2018-02-28 20:14:10723 3.1. "out/Coverage-iphonesimulator/iossim
Yuke Liao92107f02018-03-07 01:44:37724 <iossim_arguments> -c <app_arguments>
725 out/Coverage-iphonesimulator/url_unittests.app"
726
Yuke Liao506e8822017-12-04 16:52:54727 Args:
728 command: A command used to run a target.
729
730 Returns:
731 A relative path to the binary.
732 """
Yuke Liao545db322018-02-15 17:12:01733 xvfb_script_name = os.extsep.join(['xvfb', 'py'])
734
Sajjad Mirza0b96e002020-11-10 19:32:55735 command_parts = _SplitCommand(command)
Yuke Liao545db322018-02-15 17:12:01736 if os.path.basename(command_parts[0]) == 'python':
737 assert os.path.basename(command_parts[1]) == xvfb_script_name, (
Abhishek Aryafb70b532018-05-06 17:47:40738 'This tool doesn\'t understand the command: "%s".' % command)
Yuke Liao545db322018-02-15 17:12:01739 return command_parts[2]
740
741 if os.path.basename(command_parts[0]) == xvfb_script_name:
742 return command_parts[1]
743
Yuke Liaob2926832018-03-02 17:34:29744 if _IsIOSCommand(command):
Yuke Liaoa0c8c2f2018-02-28 20:14:10745 # For a given application bundle, the binary resides in the bundle and has
746 # the same name with the application without the .app extension.
Artem Titarenko2b464952018-11-07 17:22:02747 app_path = command_parts[1].rstrip(os.path.sep)
Yuke Liaoa0c8c2f2018-02-28 20:14:10748 app_name = os.path.splitext(os.path.basename(app_path))[0]
749 return os.path.join(app_path, app_name)
750
Sajjad Mirza07f52332020-11-11 01:50:47751 if coverage_utils.GetHostPlatform() == 'win' \
752 and not command_parts[0].endswith('.exe'):
753 return command_parts[0] + '.exe'
754
Yuke Liaob2926832018-03-02 17:34:29755 return command_parts[0]
Yuke Liao506e8822017-12-04 16:52:54756
757
Yuke Liaob2926832018-03-02 17:34:29758def _IsIOSCommand(command):
Yuke Liaoa0c8c2f2018-02-28 20:14:10759 """Returns true if command is used to run tests on iOS platform."""
Sajjad Mirza0b96e002020-11-10 19:32:55760 return os.path.basename(_SplitCommand(command)[0]) == 'iossim'
Yuke Liaoa0c8c2f2018-02-28 20:14:10761
762
Yuke Liao95d13d72017-12-07 18:18:50763def _VerifyTargetExecutablesAreInBuildDirectory(commands):
764 """Verifies that the target executables specified in the commands are inside
765 the given build directory."""
Yuke Liao506e8822017-12-04 16:52:54766 for command in commands:
767 binary_path = _GetBinaryPath(command)
Max Moroz1de68d72018-08-21 13:38:18768 binary_absolute_path = coverage_utils.GetFullPath(binary_path)
Abhishek Arya03911092018-05-21 16:42:35769 assert binary_absolute_path.startswith(BUILD_DIR + os.sep), (
Yuke Liao95d13d72017-12-07 18:18:50770 'Target executable "%s" in command: "%s" is outside of '
771 'the given build directory: "%s".' % (binary_path, command, BUILD_DIR))
Yuke Liao506e8822017-12-04 16:52:54772
773
774def _ValidateBuildingWithClangCoverage():
775 """Asserts that targets are built with Clang coverage enabled."""
Yuke Liao80afff32018-03-07 01:26:20776 build_args = _GetBuildArgs()
Yuke Liao506e8822017-12-04 16:52:54777
778 if (CLANG_COVERAGE_BUILD_ARG not in build_args or
779 build_args[CLANG_COVERAGE_BUILD_ARG] != 'true'):
Abhishek Arya1ec832c2017-12-05 18:06:59780 assert False, ('\'{} = true\' is required in args.gn.'
781 ).format(CLANG_COVERAGE_BUILD_ARG)
Yuke Liao506e8822017-12-04 16:52:54782
783
Yuke Liaoc60b2d02018-03-02 21:40:43784def _ValidateCurrentPlatformIsSupported():
785 """Asserts that this script suports running on the current platform"""
786 target_os = _GetTargetOS()
787 if target_os:
788 current_platform = target_os
789 else:
Max Moroz1de68d72018-08-21 13:38:18790 current_platform = coverage_utils.GetHostPlatform()
Yuke Liaoc60b2d02018-03-02 21:40:43791
Ben Joyce88282362021-01-29 23:53:31792 supported_platforms = ['android', 'chromeos', 'ios', 'linux', 'mac', 'win']
793 assert current_platform in supported_platforms, ('Coverage is only'
794 'supported on %s' %
795 supported_platforms)
Yuke Liaoc60b2d02018-03-02 21:40:43796
797
Yuke Liao80afff32018-03-07 01:26:20798def _GetBuildArgs():
Yuke Liao506e8822017-12-04 16:52:54799 """Parses args.gn file and returns results as a dictionary.
800
801 Returns:
802 A dictionary representing the build args.
803 """
Yuke Liao80afff32018-03-07 01:26:20804 global _BUILD_ARGS
805 if _BUILD_ARGS is not None:
806 return _BUILD_ARGS
807
808 _BUILD_ARGS = {}
Yuke Liao506e8822017-12-04 16:52:54809 build_args_path = os.path.join(BUILD_DIR, 'args.gn')
810 assert os.path.exists(build_args_path), ('"%s" is not a build directory, '
811 'missing args.gn file.' % BUILD_DIR)
812 with open(build_args_path) as build_args_file:
813 build_args_lines = build_args_file.readlines()
814
Yuke Liao506e8822017-12-04 16:52:54815 for build_arg_line in build_args_lines:
816 build_arg_without_comments = build_arg_line.split('#')[0]
817 key_value_pair = build_arg_without_comments.split('=')
818 if len(key_value_pair) != 2:
819 continue
820
821 key = key_value_pair[0].strip()
Yuke Liaoc60b2d02018-03-02 21:40:43822
823 # Values are wrapped within a pair of double-quotes, so remove the leading
824 # and trailing double-quotes.
825 value = key_value_pair[1].strip().strip('"')
Yuke Liao80afff32018-03-07 01:26:20826 _BUILD_ARGS[key] = value
Yuke Liao506e8822017-12-04 16:52:54827
Yuke Liao80afff32018-03-07 01:26:20828 return _BUILD_ARGS
Yuke Liao506e8822017-12-04 16:52:54829
830
Abhishek Arya16f059a2017-12-07 17:47:32831def _VerifyPathsAndReturnAbsolutes(paths):
832 """Verifies that the paths specified in |paths| exist and returns absolute
833 versions.
Yuke Liao66da1732017-12-05 22:19:42834
835 Args:
836 paths: A list of files or directories.
837 """
Abhishek Arya16f059a2017-12-07 17:47:32838 absolute_paths = []
Yuke Liao66da1732017-12-05 22:19:42839 for path in paths:
Abhishek Arya16f059a2017-12-07 17:47:32840 absolute_path = os.path.join(SRC_ROOT_PATH, path)
841 assert os.path.exists(absolute_path), ('Path: "%s" doesn\'t exist.' % path)
842
843 absolute_paths.append(absolute_path)
844
845 return absolute_paths
Yuke Liao66da1732017-12-05 22:19:42846
847
Abhishek Arya64636af2018-05-04 14:42:13848def _GetBinaryPathsFromTargets(targets, build_dir):
849 """Return binary paths from target names."""
Ben Joyce88282362021-01-29 23:53:31850 # TODO(crbug.com/899974): Derive output binary from target build definitions
851 # rather than assuming that it is always the same name.
Abhishek Arya64636af2018-05-04 14:42:13852 binary_paths = []
853 for target in targets:
854 binary_path = os.path.join(build_dir, target)
Max Moroz1de68d72018-08-21 13:38:18855 if coverage_utils.GetHostPlatform() == 'win':
Abhishek Arya64636af2018-05-04 14:42:13856 binary_path += '.exe'
857
858 if os.path.exists(binary_path):
859 binary_paths.append(binary_path)
860 else:
861 logging.warning(
Abhishek Aryafb70b532018-05-06 17:47:40862 'Target binary "%s" not found in build directory, skipping.',
Abhishek Arya64636af2018-05-04 14:42:13863 os.path.basename(binary_path))
864
865 return binary_paths
866
867
Prakhara6418512023-05-22 17:17:45868def _GetCommandForWebTests(targets, arguments):
Abhishek Arya03911092018-05-21 16:42:35869 """Return command to run for blink web tests."""
Prakhara6418512023-05-22 17:17:45870 assert len(targets) == 1, "Only one wpt target can be run"
871 target = targets[0]
872 expected_profraw_file_name = os.extsep.join(
Alan Zhao02658792023-12-11 21:47:18873 [target, '%c', '%2m', PROFRAW_FILE_EXTENSION])
Prakhara6418512023-05-22 17:17:45874 expected_profraw_file_path = os.path.join(
875 coverage_utils.GetCoverageReportRootDirPath(OUTPUT_DIR),
876 expected_profraw_file_name)
877
Dirk Pranke34c093a42021-03-25 19:19:05878 cpu_count = multiprocessing.cpu_count()
879 if sys.platform == 'win32':
880 # TODO(crbug.com/1190269) - we can't use more than 56
881 # cores on Windows or Python3 may hang.
882 cpu_count = min(cpu_count, 56)
883 cpu_count = max(1, cpu_count // 2)
884
Abhishek Arya03911092018-05-21 16:42:35885 command_list = [
Abhishek Arya03911092018-05-21 16:42:35886 'third_party/blink/tools/run_web_tests.py',
887 '--additional-driver-flag=--no-sandbox',
Prakhara6418512023-05-22 17:17:45888 '--additional-env-var=LLVM_PROFILE_FILE=%s' % expected_profraw_file_path,
Dirk Pranke34c093a42021-03-25 19:19:05889 '--child-processes=%d' % cpu_count, '--disable-breakpad',
890 '--no-show-results', '--skip-failing-tests',
Weizhong Xia91b53362022-01-05 17:13:35891 '--target=%s' % os.path.basename(BUILD_DIR), '--timeout-ms=30000'
Abhishek Arya03911092018-05-21 16:42:35892 ]
893 if arguments.strip():
894 command_list.append(arguments)
895 return ' '.join(command_list)
896
897
Ben Joyce88282362021-01-29 23:53:31898def _GetBinaryPathsForAndroid(targets):
899 """Return binary paths used when running android tests."""
900 # TODO(crbug.com/899974): Implement approach that doesn't assume .so file is
901 # based on the target's name.
902 android_binaries = set()
903 for target in targets:
904 so_library_path = os.path.join(BUILD_DIR, 'lib.unstripped',
905 'lib%s__library.so' % target)
906 if os.path.exists(so_library_path):
907 android_binaries.add(so_library_path)
908
909 return list(android_binaries)
910
911
Abhishek Arya03911092018-05-21 16:42:35912def _GetBinaryPathForWebTests():
913 """Return binary path used to run blink web tests."""
Max Moroz1de68d72018-08-21 13:38:18914 host_platform = coverage_utils.GetHostPlatform()
Abhishek Arya03911092018-05-21 16:42:35915 if host_platform == 'win':
916 return os.path.join(BUILD_DIR, 'content_shell.exe')
917 elif host_platform == 'linux':
918 return os.path.join(BUILD_DIR, 'content_shell')
919 elif host_platform == 'mac':
920 return os.path.join(BUILD_DIR, 'Content Shell.app', 'Contents', 'MacOS',
921 'Content Shell')
922 else:
923 assert False, 'This platform is not supported for web tests.'
924
925
Abhishek Aryae5811afa2018-05-24 03:56:01926def _SetupOutputDir():
927 """Setup output directory."""
928 if os.path.exists(OUTPUT_DIR):
929 shutil.rmtree(OUTPUT_DIR)
930
931 # Creates |OUTPUT_DIR| and its platform sub-directory.
Max Moroz1de68d72018-08-21 13:38:18932 os.makedirs(coverage_utils.GetCoverageReportRootDirPath(OUTPUT_DIR))
Abhishek Aryae5811afa2018-05-24 03:56:01933
934
Yuke Liaoabfbba42019-06-11 16:03:59935def _SetMacXcodePath():
936 """Set DEVELOPER_DIR to the path to hermetic Xcode.app on Mac OS X."""
937 if sys.platform != 'darwin':
938 return
939
940 xcode_path = os.path.join(SRC_ROOT_PATH, 'build', 'mac_files', 'Xcode.app')
941 if os.path.exists(xcode_path):
942 os.environ['DEVELOPER_DIR'] = xcode_path
943
944
Yuke Liao506e8822017-12-04 16:52:54945def _ParseCommandArguments():
946 """Adds and parses relevant arguments for tool comands.
947
948 Returns:
949 A dictionary representing the arguments.
950 """
951 arg_parser = argparse.ArgumentParser()
952 arg_parser.usage = __doc__
953
Abhishek Arya1ec832c2017-12-05 18:06:59954 arg_parser.add_argument(
955 '-b',
956 '--build-dir',
957 type=str,
958 required=True,
959 help='The build directory, the path needs to be relative to the root of '
960 'the checkout.')
Yuke Liao506e8822017-12-04 16:52:54961
Abhishek Arya1ec832c2017-12-05 18:06:59962 arg_parser.add_argument(
963 '-o',
964 '--output-dir',
965 type=str,
966 required=True,
967 help='Output directory for generated artifacts.')
Yuke Liao506e8822017-12-04 16:52:54968
Abhishek Arya1ec832c2017-12-05 18:06:59969 arg_parser.add_argument(
970 '-c',
971 '--command',
972 action='append',
Abhishek Arya64636af2018-05-04 14:42:13973 required=False,
Abhishek Arya1ec832c2017-12-05 18:06:59974 help='Commands used to run test targets, one test target needs one and '
975 'only one command, when specifying commands, one should assume the '
Abhishek Arya64636af2018-05-04 14:42:13976 'current working directory is the root of the checkout. This option is '
977 'incompatible with -p/--profdata-file option.')
978
979 arg_parser.add_argument(
Abhishek Arya03911092018-05-21 16:42:35980 '-wt',
981 '--web-tests',
982 nargs='?',
983 type=str,
984 const=' ',
985 required=False,
986 help='Run blink web tests. Support passing arguments to run_web_tests.py')
987
988 arg_parser.add_argument(
Abhishek Arya64636af2018-05-04 14:42:13989 '-p',
990 '--profdata-file',
991 type=str,
Prakharb8527802023-04-20 09:48:46992 action='append',
Abhishek Arya64636af2018-05-04 14:42:13993 required=False,
Prakharb8527802023-04-20 09:48:46994 help=
995 'Path(s) to profdata file(s) to use for generating code coverage reports. '
996 'This can be useful if you generated the profdata file seperately in '
997 'your own test harness. This option is ignored if run command(s) are '
998 'already provided above using -c/--command option.')
Yuke Liao506e8822017-12-04 16:52:54999
Abhishek Arya1ec832c2017-12-05 18:06:591000 arg_parser.add_argument(
Yuke Liao66da1732017-12-05 22:19:421001 '-f',
1002 '--filters',
1003 action='append',
Abhishek Arya16f059a2017-12-07 17:47:321004 required=False,
Yuke Liao66da1732017-12-05 22:19:421005 help='Directories or files to get code coverage for, and all files under '
1006 'the directories are included recursively.')
1007
1008 arg_parser.add_argument(
Yuke Liao0e4c8682018-04-18 21:06:591009 '-i',
1010 '--ignore-filename-regex',
1011 type=str,
1012 help='Skip source code files with file paths that match the given '
1013 'regular expression. For example, use -i=\'.*/out/.*|.*/third_party/.*\' '
1014 'to exclude files in third_party/ and out/ folders from the report.')
1015
1016 arg_parser.add_argument(
Yuke Liao1b852fd2018-05-11 17:07:321017 '--no-file-view',
1018 action='store_true',
1019 help='Don\'t generate the file view in the coverage report. When there '
1020 'are large number of html files, the file view becomes heavy and may '
1021 'cause the browser to freeze, and this argument comes handy.')
1022
1023 arg_parser.add_argument(
Max Moroz1de68d72018-08-21 13:38:181024 '--no-component-view',
1025 action='store_true',
1026 help='Don\'t generate the component view in the coverage report.')
1027
1028 arg_parser.add_argument(
Yuke Liao082e99632018-05-18 15:40:401029 '--coverage-tools-dir',
1030 type=str,
1031 help='Path of the directory where LLVM coverage tools (llvm-cov, '
1032 'llvm-profdata) exist. This should be only needed if you are testing '
1033 'against a custom built clang revision. Otherwise, we pick coverage '
1034 'tools automatically from your current source checkout.')
1035
1036 arg_parser.add_argument(
Abhishek Arya1ec832c2017-12-05 18:06:591037 '-j',
1038 '--jobs',
1039 type=int,
1040 default=None,
1041 help='Run N jobs to build in parallel. If not specified, a default value '
Max Moroz06576292019-01-03 19:22:521042 'will be derived based on CPUs and goma availability. Please refer to '
1043 '\'autoninja -h\' for more details.')
Yuke Liao506e8822017-12-04 16:52:541044
Abhishek Arya1ec832c2017-12-05 18:06:591045 arg_parser.add_argument(
Sahel Sharify38cabdc2020-01-16 00:40:011046 '--format',
1047 type=str,
1048 default='html',
Akekawit Jitprasertf9cb6622021-08-24 17:48:021049 help='Output format of the "llvm-cov show/export" command. The '
1050 'supported formats are "text", "html" and "lcov".')
Sahel Sharify38cabdc2020-01-16 00:40:011051
1052 arg_parser.add_argument(
Yuke Liao481d3482018-01-29 19:17:101053 '-v',
1054 '--verbose',
1055 action='store_true',
1056 help='Prints additional output for diagnostics.')
1057
1058 arg_parser.add_argument(
1059 '-l', '--log_file', type=str, help='Redirects logs to a file.')
1060
1061 arg_parser.add_argument(
Abhishek Aryac19bc5ef2018-05-04 22:10:021062 'targets',
1063 nargs='+',
1064 help='The names of the test targets to run. If multiple run commands are '
1065 'specified using the -c/--command option, then the order of targets and '
1066 'commands must match, otherwise coverage generation will fail.')
Yuke Liao506e8822017-12-04 16:52:541067
1068 args = arg_parser.parse_args()
1069 return args
1070
1071
1072def Main():
1073 """Execute tool commands."""
Yuke Liao082e99632018-05-18 15:40:401074
Abhishek Arya64636af2018-05-04 14:42:131075 # Change directory to source root to aid in relative paths calculations.
1076 os.chdir(SRC_ROOT_PATH)
Abhishek Arya8a0751a2018-05-03 18:53:111077
pasthanaa4844112020-05-21 18:03:551078 # Setup coverage binaries even when script is called with empty params. This
1079 # is used by coverage bot for initial setup.
1080 if len(sys.argv) == 1:
Choongwoo Hanbd1aa952021-06-09 22:25:381081 subprocess.check_call([
Akekawit Jitprasert928671e2021-09-20 18:40:581082 sys.executable, 'tools/clang/scripts/update.py', '--package',
1083 'coverage_tools'
Choongwoo Hanbd1aa952021-06-09 22:25:381084 ])
pasthanaa4844112020-05-21 18:03:551085 print(__doc__)
1086 return
1087
Yuke Liao506e8822017-12-04 16:52:541088 args = _ParseCommandArguments()
Max Moroz1de68d72018-08-21 13:38:181089 coverage_utils.ConfigureLogging(verbose=args.verbose, log_file=args.log_file)
Yuke Liao082e99632018-05-18 15:40:401090 _ConfigureLLVMCoverageTools(args)
Abhishek Arya64636af2018-05-04 14:42:131091
Yuke Liao506e8822017-12-04 16:52:541092 global BUILD_DIR
Max Moroz1de68d72018-08-21 13:38:181093 BUILD_DIR = coverage_utils.GetFullPath(args.build_dir)
Abhishek Aryae5811afa2018-05-24 03:56:011094
Yuke Liao506e8822017-12-04 16:52:541095 global OUTPUT_DIR
Max Moroz1de68d72018-08-21 13:38:181096 OUTPUT_DIR = coverage_utils.GetFullPath(args.output_dir)
Yuke Liao506e8822017-12-04 16:52:541097
Abhishek Arya03911092018-05-21 16:42:351098 assert args.web_tests or args.command or args.profdata_file, (
Abhishek Arya64636af2018-05-04 14:42:131099 'Need to either provide commands to run using -c/--command option OR '
Abhishek Arya03911092018-05-21 16:42:351100 'provide prof-data file as input using -p/--profdata-file option OR '
1101 'run web tests using -wt/--run-web-tests.')
Yuke Liaoc60b2d02018-03-02 21:40:431102
Abhishek Arya64636af2018-05-04 14:42:131103 assert not args.command or (len(args.targets) == len(args.command)), (
1104 'Number of targets must be equal to the number of test commands.')
Yuke Liaoc60b2d02018-03-02 21:40:431105
Abhishek Arya1ec832c2017-12-05 18:06:591106 assert os.path.exists(BUILD_DIR), (
Abhishek Aryafb70b532018-05-06 17:47:401107 'Build directory: "%s" doesn\'t exist. '
1108 'Please run "gn gen" to generate.' % BUILD_DIR)
Abhishek Arya64636af2018-05-04 14:42:131109
Yuke Liaoc60b2d02018-03-02 21:40:431110 _ValidateCurrentPlatformIsSupported()
Yuke Liao506e8822017-12-04 16:52:541111 _ValidateBuildingWithClangCoverage()
Abhishek Arya16f059a2017-12-07 17:47:321112
1113 absolute_filter_paths = []
Yuke Liao66da1732017-12-05 22:19:421114 if args.filters:
Abhishek Arya16f059a2017-12-07 17:47:321115 absolute_filter_paths = _VerifyPathsAndReturnAbsolutes(args.filters)
Yuke Liao66da1732017-12-05 22:19:421116
Abhishek Aryae5811afa2018-05-24 03:56:011117 _SetupOutputDir()
Yuke Liao506e8822017-12-04 16:52:541118
Abhishek Arya03911092018-05-21 16:42:351119 # Get .profdata file and list of binary paths.
1120 if args.web_tests:
Prakhara6418512023-05-22 17:17:451121 commands = [_GetCommandForWebTests(args.targets, args.web_tests)]
Abhishek Arya03911092018-05-21 16:42:351122 profdata_file_path = _CreateCoverageProfileDataForTargets(
1123 args.targets, commands, args.jobs)
1124 binary_paths = [_GetBinaryPathForWebTests()]
1125 elif args.command:
1126 for i in range(len(args.command)):
1127 assert not 'run_web_tests.py' in args.command[i], (
1128 'run_web_tests.py is not supported via --command argument. '
1129 'Please use --run-web-tests argument instead.')
1130
Abhishek Arya64636af2018-05-04 14:42:131131 # A list of commands are provided. Run them to generate profdata file, and
1132 # create a list of binary paths from parsing commands.
1133 _VerifyTargetExecutablesAreInBuildDirectory(args.command)
1134 profdata_file_path = _CreateCoverageProfileDataForTargets(
1135 args.targets, args.command, args.jobs)
1136 binary_paths = [_GetBinaryPath(command) for command in args.command]
1137 else:
Julia Hansbrough57bd3fc2023-03-30 01:47:231138 # An input prof-data file(s) is already provided.
1139 if len(args.profdata_file) == 1:
1140 # If it's just one input file, use as-is.
Prakharf851c562023-05-23 19:32:401141 profdata_file_path = args.profdata_file[0]
Julia Hansbrough57bd3fc2023-03-30 01:47:231142 else:
1143 # Otherwise, there are multiple profdata files and we need to merge them.
1144 profdata_file_path = _CreateCoverageProfileDataFromTargetProfDataFiles(args.profdata_file)
1145 # Since input prof-data files were provided, we only need to calculate the
1146 # binary paths from here.
Abhishek Arya64636af2018-05-04 14:42:131147 binary_paths = _GetBinaryPathsFromTargets(args.targets, args.build_dir)
Yuke Liaoea228d02018-01-05 19:10:331148
Erik Chen283b92c72019-07-22 16:37:391149 # If the checkout uses the hermetic xcode binaries, then otool must be
1150 # directly invoked. The indirection via /usr/bin/otool won't work unless
1151 # there's an actual system install of Xcode.
1152 otool_path = None
1153 if sys.platform == 'darwin':
1154 hermetic_otool_path = os.path.join(
1155 SRC_ROOT_PATH, 'build', 'mac_files', 'xcode_binaries', 'Contents',
1156 'Developer', 'Toolchains', 'XcodeDefault.xctoolchain', 'usr', 'bin',
1157 'otool')
1158 if os.path.exists(hermetic_otool_path):
1159 otool_path = hermetic_otool_path
Ben Joyce88282362021-01-29 23:53:311160
1161 if _IsAndroid():
1162 binary_paths = _GetBinaryPathsForAndroid(args.targets)
1163 elif sys.platform.startswith('linux') or sys.platform.startswith('darwin'):
Brent McBrideb25b177a42020-05-11 18:13:061164 binary_paths.extend(
1165 coverage_utils.GetSharedLibraries(binary_paths, BUILD_DIR, otool_path))
Abhishek Arya78120bc2018-05-07 20:53:541166
Akekawit Jitprasertf9cb6622021-08-24 17:48:021167 assert args.format in ['html', 'lcov', 'text'], (
1168 '%s is not a valid output format for "llvm-cov show/export". Only '
1169 '"text", "html" and "lcov" formats are supported.' % (args.format))
Sahel Sharify38cabdc2020-01-16 00:40:011170 logging.info('Generating code coverage report in %s (this can take a while '
1171 'depending on size of target!).' % (args.format))
Max Moroz1de68d72018-08-21 13:38:181172 per_file_summary_data = _GeneratePerFileCoverageSummary(
Yuke Liao0e4c8682018-04-18 21:06:591173 binary_paths, profdata_file_path, absolute_filter_paths,
1174 args.ignore_filename_regex)
Akekawit Jitprasertf9cb6622021-08-24 17:48:021175
1176 if args.format == 'lcov':
1177 _GeneratePerFileLineByLineCoverageInLcov(
1178 binary_paths, profdata_file_path, absolute_filter_paths,
1179 args.ignore_filename_regex)
1180 return
1181
Sahel Sharify38cabdc2020-01-16 00:40:011182 _GeneratePerFileLineByLineCoverageInFormat(
1183 binary_paths, profdata_file_path, absolute_filter_paths,
1184 args.ignore_filename_regex, args.format)
Max Moroz1de68d72018-08-21 13:38:181185 component_mappings = None
1186 if not args.no_component_view:
Choongwoo Hanbd1aa952021-06-09 22:25:381187 component_mappings = json.load(urlopen(COMPONENT_MAPPING_URL))
Yuke Liaodd1ec0592018-02-02 01:26:371188
Max Moroz1de68d72018-08-21 13:38:181189 # Call prepare here.
1190 processor = coverage_utils.CoverageReportPostProcessor(
1191 OUTPUT_DIR,
1192 SRC_ROOT_PATH,
1193 per_file_summary_data,
1194 no_component_view=args.no_component_view,
1195 no_file_view=args.no_file_view,
1196 component_mappings=component_mappings)
Yuke Liaodd1ec0592018-02-02 01:26:371197
Sahel Sharify38cabdc2020-01-16 00:40:011198 if args.format == 'html':
1199 processor.PrepareHtmlReport()
Yuke Liao506e8822017-12-04 16:52:541200
Abhishek Arya1ec832c2017-12-05 18:06:591201
Yuke Liao506e8822017-12-04 16:52:541202if __name__ == '__main__':
1203 sys.exit(Main())