blob: e622653db99c4f14b032ba530ead9c42bfb876c4 [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.
507 profile_pattern_string = '%1m' if _IsFuzzerTarget(target) else '%4m'
Abhishek Arya1ec832c2017-12-05 18:06:59508 expected_profraw_file_name = os.extsep.join(
Nico Weber51e61c7d2023-12-12 17:32:46509 [target, profile_pattern_string, PROFRAW_FILE_EXTENSION])
Max Moroz1de68d72018-08-21 13:38:18510 expected_profraw_file_path = os.path.join(
511 coverage_utils.GetCoverageReportRootDirPath(OUTPUT_DIR),
512 expected_profraw_file_name)
Abhishek Aryabd0655d2018-05-21 19:55:24513 command = command.replace(LLVM_PROFILE_FILE_PATH_SUBSTITUTION,
514 expected_profraw_file_path)
Yuke Liao506e8822017-12-04 16:52:54515
Yuke Liaoa0c8c2f2018-02-28 20:14:10516 try:
Max Moroz7c5354f2018-05-06 00:03:48517 # Some fuzz targets or tests may write into stderr, redirect it as well.
Abhishek Arya03911092018-05-21 16:42:35518 with open(output_file_path, 'wb') as output_file_handle:
Sajjad Mirza0b96e002020-11-10 19:32:55519 subprocess.check_call(_SplitCommand(command),
520 stdout=output_file_handle,
521 stderr=subprocess.STDOUT,
522 env=_GetEnvironmentVars(expected_profraw_file_path))
Yuke Liaoa0c8c2f2018-02-28 20:14:10523 except subprocess.CalledProcessError as e:
Abhishek Arya03911092018-05-21 16:42:35524 logging.warning('Command: "%s" exited with non-zero return code.', command)
Yuke Liaoa0c8c2f2018-02-28 20:14:10525
Abhishek Arya03911092018-05-21 16:42:35526 return open(output_file_path, 'rb').read()
Yuke Liaoa0c8c2f2018-02-28 20:14:10527
528
Yuke Liao27349c92018-03-22 21:10:01529def _IsFuzzerTarget(target):
530 """Returns true if the target is a fuzzer target."""
531 build_args = _GetBuildArgs()
532 use_libfuzzer = ('use_libfuzzer' in build_args and
533 build_args['use_libfuzzer'] == 'true')
Adrian Taylor9470000f2023-03-10 16:18:25534 use_centipede = ('use_centipede' in build_args
535 and build_args['use_centipede'] == 'true')
536 return (use_libfuzzer or use_centipede) and target.endswith('_fuzzer')
Yuke Liao27349c92018-03-22 21:10:01537
538
Abhishek Arya03911092018-05-21 16:42:35539def _ExecuteIOSCommand(command, output_file_path):
Yuke Liaoa0c8c2f2018-02-28 20:14:10540 """Runs a single iOS command and generates a profraw data file.
541
542 iOS application doesn't have write access to folders outside of the app, so
543 it's impossible to instruct the app to flush the profraw data file to the
544 desired location. The profraw data file will be generated somewhere within the
545 application's Documents folder, and the full path can be obtained by parsing
546 the output.
547 """
Yuke Liaob2926832018-03-02 17:34:29548 assert _IsIOSCommand(command)
549
550 # After running tests, iossim generates a profraw data file, it won't be
551 # needed anyway, so dump it into the OUTPUT_DIR to avoid polluting the
552 # checkout.
553 iossim_profraw_file_path = os.path.join(
554 OUTPUT_DIR, os.extsep.join(['iossim', PROFRAW_FILE_EXTENSION]))
Abhishek Aryabd0655d2018-05-21 19:55:24555 command = command.replace(LLVM_PROFILE_FILE_PATH_SUBSTITUTION,
556 iossim_profraw_file_path)
Yuke Liaoa0c8c2f2018-02-28 20:14:10557
558 try:
Abhishek Arya03911092018-05-21 16:42:35559 with open(output_file_path, 'wb') as output_file_handle:
Sajjad Mirza0b96e002020-11-10 19:32:55560 subprocess.check_call(_SplitCommand(command),
561 stdout=output_file_handle,
562 stderr=subprocess.STDOUT,
563 env=_GetEnvironmentVars(iossim_profraw_file_path))
Yuke Liaoa0c8c2f2018-02-28 20:14:10564 except subprocess.CalledProcessError as e:
565 # iossim emits non-zero return code even if tests run successfully, so
566 # ignore the return code.
Abhishek Arya03911092018-05-21 16:42:35567 pass
Yuke Liaoa0c8c2f2018-02-28 20:14:10568
Abhishek Arya03911092018-05-21 16:42:35569 return open(output_file_path, 'rb').read()
Yuke Liaoa0c8c2f2018-02-28 20:14:10570
571
572def _GetProfrawDataFileByParsingOutput(output):
573 """Returns the path to the profraw data file obtained by parsing the output.
574
575 The output of running the test target has no format, but it is guaranteed to
576 have a single line containing the path to the generated profraw data file.
577 NOTE: This should only be called when target os is iOS.
578 """
Yuke Liaob2926832018-03-02 17:34:29579 assert _IsIOS()
Yuke Liaoa0c8c2f2018-02-28 20:14:10580
Yuke Liaob2926832018-03-02 17:34:29581 output_by_lines = ''.join(output).splitlines()
582 profraw_file_pattern = re.compile('.*Coverage data at (.*coverage\.profraw).')
Yuke Liaoa0c8c2f2018-02-28 20:14:10583
584 for line in output_by_lines:
Yuke Liaob2926832018-03-02 17:34:29585 result = profraw_file_pattern.match(line)
586 if result:
587 return result.group(1)
Yuke Liaoa0c8c2f2018-02-28 20:14:10588
589 assert False, ('No profraw data file was generated, did you call '
590 'coverage_util::ConfigureCoverageReportPath() in test setup? '
591 'Please refer to base/test/test_support_ios.mm for example.')
Yuke Liao506e8822017-12-04 16:52:54592
593
Abhishek Aryac19bc5ef2018-05-04 22:10:02594def _CreateCoverageProfileDataFromTargetProfDataFiles(profdata_file_paths):
595 """Returns a relative path to coverage profdata file by merging target
596 profdata files.
Yuke Liao506e8822017-12-04 16:52:54597
598 Args:
Abhishek Aryac19bc5ef2018-05-04 22:10:02599 profdata_file_paths: A list of relative paths to the profdata data files
600 that are to be merged.
Yuke Liao506e8822017-12-04 16:52:54601
602 Returns:
Abhishek Aryac19bc5ef2018-05-04 22:10:02603 A relative path to the merged coverage profdata file.
Yuke Liao506e8822017-12-04 16:52:54604
605 Raises:
Abhishek Aryac19bc5ef2018-05-04 22:10:02606 CalledProcessError: An error occurred merging profdata files.
Yuke Liao506e8822017-12-04 16:52:54607 """
Abhishek Aryafb70b532018-05-06 17:47:40608 logging.info('Creating the coverage profile data file.')
609 logging.debug('Merging target profraw files to create target profdata file.')
Max Moroz7c5354f2018-05-06 00:03:48610 profdata_file_path = _GetProfdataFilePath()
Yuke Liao506e8822017-12-04 16:52:54611 try:
Abhishek Arya1ec832c2017-12-05 18:06:59612 subprocess_cmd = [
613 LLVM_PROFDATA_PATH, 'merge', '-o', profdata_file_path, '-sparse=true'
614 ]
Abhishek Aryac19bc5ef2018-05-04 22:10:02615 subprocess_cmd.extend(profdata_file_paths)
Abhishek Aryae5811afa2018-05-24 03:56:01616
617 output = subprocess.check_output(subprocess_cmd)
Max Moroz1de68d72018-08-21 13:38:18618 logging.debug('Merge output: %s', output)
Abhishek Aryac19bc5ef2018-05-04 22:10:02619 except subprocess.CalledProcessError as error:
Abhishek Aryad35de7e2018-05-10 22:23:04620 logging.error(
621 'Failed to merge target profdata files to create coverage profdata. %s',
622 FILE_BUG_MESSAGE)
Abhishek Aryac19bc5ef2018-05-04 22:10:02623 raise error
624
Abhishek Aryafb70b532018-05-06 17:47:40625 logging.debug('Finished merging target profdata files.')
626 logging.info('Code coverage profile data is created as: "%s".',
Abhishek Aryac19bc5ef2018-05-04 22:10:02627 profdata_file_path)
628 return profdata_file_path
629
630
631def _CreateTargetProfDataFileFromProfRawFiles(target, profraw_file_paths):
632 """Returns a relative path to target profdata file by merging target
633 profraw files.
634
635 Args:
636 profraw_file_paths: A list of relative paths to the profdata data files
637 that are to be merged.
638
639 Returns:
640 A relative path to the merged coverage profdata file.
641
642 Raises:
643 CalledProcessError: An error occurred merging profdata files.
644 """
Abhishek Aryafb70b532018-05-06 17:47:40645 logging.info('Creating target profile data file.')
646 logging.debug('Merging target profraw files to create target profdata file.')
Abhishek Aryac19bc5ef2018-05-04 22:10:02647 profdata_file_path = os.path.join(OUTPUT_DIR, '%s.profdata' % target)
648
649 try:
650 subprocess_cmd = [
651 LLVM_PROFDATA_PATH, 'merge', '-o', profdata_file_path, '-sparse=true'
652 ]
Yuke Liao506e8822017-12-04 16:52:54653 subprocess_cmd.extend(profraw_file_paths)
Abhishek Aryae5811afa2018-05-24 03:56:01654 output = subprocess.check_output(subprocess_cmd)
Max Moroz1de68d72018-08-21 13:38:18655 logging.debug('Merge output: %s', output)
Yuke Liao506e8822017-12-04 16:52:54656 except subprocess.CalledProcessError as error:
Abhishek Aryad35de7e2018-05-10 22:23:04657 logging.error(
658 'Failed to merge target profraw files to create target profdata.')
Yuke Liao506e8822017-12-04 16:52:54659 raise error
660
Abhishek Aryafb70b532018-05-06 17:47:40661 logging.debug('Finished merging target profraw files.')
662 logging.info('Target "%s" profile data is created as: "%s".', target,
Yuke Liao481d3482018-01-29 19:17:10663 profdata_file_path)
Yuke Liao506e8822017-12-04 16:52:54664 return profdata_file_path
665
666
Yuke Liao0e4c8682018-04-18 21:06:59667def _GeneratePerFileCoverageSummary(binary_paths, profdata_file_path, filters,
668 ignore_filename_regex):
Yuke Liaoea228d02018-01-05 19:10:33669 """Generates per file coverage summary using "llvm-cov export" command."""
670 # llvm-cov export [options] -instr-profile PROFILE BIN [-object BIN,...]
671 # [[-object BIN]] [SOURCES].
672 # NOTE: For object files, the first one is specified as a positional argument,
673 # and the rest are specified as keyword argument.
Yuke Liao481d3482018-01-29 19:17:10674 logging.debug('Generating per-file code coverage summary using "llvm-cov '
Abhishek Aryafb70b532018-05-06 17:47:40675 'export -summary-only" command.')
Sajjad Mirza07f52332020-11-11 01:50:47676 for path in binary_paths:
677 if not os.path.exists(path):
678 logging.error("Binary %s does not exist", path)
Yuke Liaoea228d02018-01-05 19:10:33679 subprocess_cmd = [
680 LLVM_COV_PATH, 'export', '-summary-only',
Choongwoo Han56752522021-06-10 17:38:34681 '-compilation-dir={}'.format(BUILD_DIR),
Yuke Liaoea228d02018-01-05 19:10:33682 '-instr-profile=' + profdata_file_path, binary_paths[0]
683 ]
684 subprocess_cmd.extend(
685 ['-object=' + binary_path for binary_path in binary_paths[1:]])
Yuke Liaob2926832018-03-02 17:34:29686 _AddArchArgumentForIOSIfNeeded(subprocess_cmd, len(binary_paths))
Yuke Liaoea228d02018-01-05 19:10:33687 subprocess_cmd.extend(filters)
Yuke Liao0e4c8682018-04-18 21:06:59688 if ignore_filename_regex:
689 subprocess_cmd.append('-ignore-filename-regex=%s' % ignore_filename_regex)
Yuke Liaoea228d02018-01-05 19:10:33690
Max Moroz7c5354f2018-05-06 00:03:48691 export_output = subprocess.check_output(subprocess_cmd)
692
693 # Write output on the disk to be used by code coverage bot.
Prakhar65d63832021-06-16 23:01:37694 with open(_GetSummaryFilePath(), 'wb') as f:
Max Moroz7c5354f2018-05-06 00:03:48695 f.write(export_output)
696
Max Moroz1de68d72018-08-21 13:38:18697 return export_output
Yuke Liaoea228d02018-01-05 19:10:33698
699
Yuke Liaob2926832018-03-02 17:34:29700def _AddArchArgumentForIOSIfNeeded(cmd_list, num_archs):
701 """Appends -arch arguments to the command list if it's ios platform.
702
703 iOS binaries are universal binaries, and require specifying the architecture
704 to use, and one architecture needs to be specified for each binary.
705 """
706 if _IsIOS():
707 cmd_list.extend(['-arch=x86_64'] * num_archs)
708
709
Yuke Liao506e8822017-12-04 16:52:54710def _GetBinaryPath(command):
711 """Returns a relative path to the binary to be run by the command.
712
Yuke Liao545db322018-02-15 17:12:01713 Currently, following types of commands are supported (e.g. url_unittests):
714 1. Run test binary direcly: "out/coverage/url_unittests <arguments>"
715 2. Use xvfb.
716 2.1. "python testing/xvfb.py out/coverage/url_unittests <arguments>"
717 2.2. "testing/xvfb.py out/coverage/url_unittests <arguments>"
Yuke Liao92107f02018-03-07 01:44:37718 3. Use iossim to run tests on iOS platform, please refer to testing/iossim.mm
719 for its usage.
Yuke Liaoa0c8c2f2018-02-28 20:14:10720 3.1. "out/Coverage-iphonesimulator/iossim
Yuke Liao92107f02018-03-07 01:44:37721 <iossim_arguments> -c <app_arguments>
722 out/Coverage-iphonesimulator/url_unittests.app"
723
Yuke Liao506e8822017-12-04 16:52:54724 Args:
725 command: A command used to run a target.
726
727 Returns:
728 A relative path to the binary.
729 """
Yuke Liao545db322018-02-15 17:12:01730 xvfb_script_name = os.extsep.join(['xvfb', 'py'])
731
Sajjad Mirza0b96e002020-11-10 19:32:55732 command_parts = _SplitCommand(command)
Yuke Liao545db322018-02-15 17:12:01733 if os.path.basename(command_parts[0]) == 'python':
734 assert os.path.basename(command_parts[1]) == xvfb_script_name, (
Abhishek Aryafb70b532018-05-06 17:47:40735 'This tool doesn\'t understand the command: "%s".' % command)
Yuke Liao545db322018-02-15 17:12:01736 return command_parts[2]
737
738 if os.path.basename(command_parts[0]) == xvfb_script_name:
739 return command_parts[1]
740
Yuke Liaob2926832018-03-02 17:34:29741 if _IsIOSCommand(command):
Yuke Liaoa0c8c2f2018-02-28 20:14:10742 # For a given application bundle, the binary resides in the bundle and has
743 # the same name with the application without the .app extension.
Artem Titarenko2b464952018-11-07 17:22:02744 app_path = command_parts[1].rstrip(os.path.sep)
Yuke Liaoa0c8c2f2018-02-28 20:14:10745 app_name = os.path.splitext(os.path.basename(app_path))[0]
746 return os.path.join(app_path, app_name)
747
Sajjad Mirza07f52332020-11-11 01:50:47748 if coverage_utils.GetHostPlatform() == 'win' \
749 and not command_parts[0].endswith('.exe'):
750 return command_parts[0] + '.exe'
751
Yuke Liaob2926832018-03-02 17:34:29752 return command_parts[0]
Yuke Liao506e8822017-12-04 16:52:54753
754
Yuke Liaob2926832018-03-02 17:34:29755def _IsIOSCommand(command):
Yuke Liaoa0c8c2f2018-02-28 20:14:10756 """Returns true if command is used to run tests on iOS platform."""
Sajjad Mirza0b96e002020-11-10 19:32:55757 return os.path.basename(_SplitCommand(command)[0]) == 'iossim'
Yuke Liaoa0c8c2f2018-02-28 20:14:10758
759
Yuke Liao95d13d72017-12-07 18:18:50760def _VerifyTargetExecutablesAreInBuildDirectory(commands):
761 """Verifies that the target executables specified in the commands are inside
762 the given build directory."""
Yuke Liao506e8822017-12-04 16:52:54763 for command in commands:
764 binary_path = _GetBinaryPath(command)
Max Moroz1de68d72018-08-21 13:38:18765 binary_absolute_path = coverage_utils.GetFullPath(binary_path)
Abhishek Arya03911092018-05-21 16:42:35766 assert binary_absolute_path.startswith(BUILD_DIR + os.sep), (
Yuke Liao95d13d72017-12-07 18:18:50767 'Target executable "%s" in command: "%s" is outside of '
768 'the given build directory: "%s".' % (binary_path, command, BUILD_DIR))
Yuke Liao506e8822017-12-04 16:52:54769
770
771def _ValidateBuildingWithClangCoverage():
772 """Asserts that targets are built with Clang coverage enabled."""
Yuke Liao80afff32018-03-07 01:26:20773 build_args = _GetBuildArgs()
Yuke Liao506e8822017-12-04 16:52:54774
775 if (CLANG_COVERAGE_BUILD_ARG not in build_args or
776 build_args[CLANG_COVERAGE_BUILD_ARG] != 'true'):
Abhishek Arya1ec832c2017-12-05 18:06:59777 assert False, ('\'{} = true\' is required in args.gn.'
778 ).format(CLANG_COVERAGE_BUILD_ARG)
Yuke Liao506e8822017-12-04 16:52:54779
780
Yuke Liaoc60b2d02018-03-02 21:40:43781def _ValidateCurrentPlatformIsSupported():
782 """Asserts that this script suports running on the current platform"""
783 target_os = _GetTargetOS()
784 if target_os:
785 current_platform = target_os
786 else:
Max Moroz1de68d72018-08-21 13:38:18787 current_platform = coverage_utils.GetHostPlatform()
Yuke Liaoc60b2d02018-03-02 21:40:43788
Ben Joyce88282362021-01-29 23:53:31789 supported_platforms = ['android', 'chromeos', 'ios', 'linux', 'mac', 'win']
790 assert current_platform in supported_platforms, ('Coverage is only'
791 'supported on %s' %
792 supported_platforms)
Yuke Liaoc60b2d02018-03-02 21:40:43793
794
Yuke Liao80afff32018-03-07 01:26:20795def _GetBuildArgs():
Yuke Liao506e8822017-12-04 16:52:54796 """Parses args.gn file and returns results as a dictionary.
797
798 Returns:
799 A dictionary representing the build args.
800 """
Yuke Liao80afff32018-03-07 01:26:20801 global _BUILD_ARGS
802 if _BUILD_ARGS is not None:
803 return _BUILD_ARGS
804
805 _BUILD_ARGS = {}
Yuke Liao506e8822017-12-04 16:52:54806 build_args_path = os.path.join(BUILD_DIR, 'args.gn')
807 assert os.path.exists(build_args_path), ('"%s" is not a build directory, '
808 'missing args.gn file.' % BUILD_DIR)
809 with open(build_args_path) as build_args_file:
810 build_args_lines = build_args_file.readlines()
811
Yuke Liao506e8822017-12-04 16:52:54812 for build_arg_line in build_args_lines:
813 build_arg_without_comments = build_arg_line.split('#')[0]
814 key_value_pair = build_arg_without_comments.split('=')
815 if len(key_value_pair) != 2:
816 continue
817
818 key = key_value_pair[0].strip()
Yuke Liaoc60b2d02018-03-02 21:40:43819
820 # Values are wrapped within a pair of double-quotes, so remove the leading
821 # and trailing double-quotes.
822 value = key_value_pair[1].strip().strip('"')
Yuke Liao80afff32018-03-07 01:26:20823 _BUILD_ARGS[key] = value
Yuke Liao506e8822017-12-04 16:52:54824
Yuke Liao80afff32018-03-07 01:26:20825 return _BUILD_ARGS
Yuke Liao506e8822017-12-04 16:52:54826
827
Abhishek Arya16f059a2017-12-07 17:47:32828def _VerifyPathsAndReturnAbsolutes(paths):
829 """Verifies that the paths specified in |paths| exist and returns absolute
830 versions.
Yuke Liao66da1732017-12-05 22:19:42831
832 Args:
833 paths: A list of files or directories.
834 """
Abhishek Arya16f059a2017-12-07 17:47:32835 absolute_paths = []
Yuke Liao66da1732017-12-05 22:19:42836 for path in paths:
Abhishek Arya16f059a2017-12-07 17:47:32837 absolute_path = os.path.join(SRC_ROOT_PATH, path)
838 assert os.path.exists(absolute_path), ('Path: "%s" doesn\'t exist.' % path)
839
840 absolute_paths.append(absolute_path)
841
842 return absolute_paths
Yuke Liao66da1732017-12-05 22:19:42843
844
Abhishek Arya64636af2018-05-04 14:42:13845def _GetBinaryPathsFromTargets(targets, build_dir):
846 """Return binary paths from target names."""
Ben Joyce88282362021-01-29 23:53:31847 # TODO(crbug.com/899974): Derive output binary from target build definitions
848 # rather than assuming that it is always the same name.
Abhishek Arya64636af2018-05-04 14:42:13849 binary_paths = []
850 for target in targets:
851 binary_path = os.path.join(build_dir, target)
Max Moroz1de68d72018-08-21 13:38:18852 if coverage_utils.GetHostPlatform() == 'win':
Abhishek Arya64636af2018-05-04 14:42:13853 binary_path += '.exe'
854
855 if os.path.exists(binary_path):
856 binary_paths.append(binary_path)
857 else:
858 logging.warning(
Abhishek Aryafb70b532018-05-06 17:47:40859 'Target binary "%s" not found in build directory, skipping.',
Abhishek Arya64636af2018-05-04 14:42:13860 os.path.basename(binary_path))
861
862 return binary_paths
863
864
Prakhara6418512023-05-22 17:17:45865def _GetCommandForWebTests(targets, arguments):
Abhishek Arya03911092018-05-21 16:42:35866 """Return command to run for blink web tests."""
Prakhara6418512023-05-22 17:17:45867 assert len(targets) == 1, "Only one wpt target can be run"
868 target = targets[0]
869 expected_profraw_file_name = os.extsep.join(
Nico Weber51e61c7d2023-12-12 17:32:46870 [target, '%2m', PROFRAW_FILE_EXTENSION])
Prakhara6418512023-05-22 17:17:45871 expected_profraw_file_path = os.path.join(
872 coverage_utils.GetCoverageReportRootDirPath(OUTPUT_DIR),
873 expected_profraw_file_name)
874
Dirk Pranke34c093a42021-03-25 19:19:05875 cpu_count = multiprocessing.cpu_count()
876 if sys.platform == 'win32':
877 # TODO(crbug.com/1190269) - we can't use more than 56
878 # cores on Windows or Python3 may hang.
879 cpu_count = min(cpu_count, 56)
880 cpu_count = max(1, cpu_count // 2)
881
Abhishek Arya03911092018-05-21 16:42:35882 command_list = [
Abhishek Arya03911092018-05-21 16:42:35883 'third_party/blink/tools/run_web_tests.py',
884 '--additional-driver-flag=--no-sandbox',
Prakhara6418512023-05-22 17:17:45885 '--additional-env-var=LLVM_PROFILE_FILE=%s' % expected_profraw_file_path,
Dirk Pranke34c093a42021-03-25 19:19:05886 '--child-processes=%d' % cpu_count, '--disable-breakpad',
887 '--no-show-results', '--skip-failing-tests',
Weizhong Xia91b53362022-01-05 17:13:35888 '--target=%s' % os.path.basename(BUILD_DIR), '--timeout-ms=30000'
Abhishek Arya03911092018-05-21 16:42:35889 ]
890 if arguments.strip():
891 command_list.append(arguments)
892 return ' '.join(command_list)
893
894
Ben Joyce88282362021-01-29 23:53:31895def _GetBinaryPathsForAndroid(targets):
896 """Return binary paths used when running android tests."""
897 # TODO(crbug.com/899974): Implement approach that doesn't assume .so file is
898 # based on the target's name.
899 android_binaries = set()
900 for target in targets:
901 so_library_path = os.path.join(BUILD_DIR, 'lib.unstripped',
902 'lib%s__library.so' % target)
903 if os.path.exists(so_library_path):
904 android_binaries.add(so_library_path)
905
906 return list(android_binaries)
907
908
Abhishek Arya03911092018-05-21 16:42:35909def _GetBinaryPathForWebTests():
910 """Return binary path used to run blink web tests."""
Max Moroz1de68d72018-08-21 13:38:18911 host_platform = coverage_utils.GetHostPlatform()
Abhishek Arya03911092018-05-21 16:42:35912 if host_platform == 'win':
913 return os.path.join(BUILD_DIR, 'content_shell.exe')
914 elif host_platform == 'linux':
915 return os.path.join(BUILD_DIR, 'content_shell')
916 elif host_platform == 'mac':
917 return os.path.join(BUILD_DIR, 'Content Shell.app', 'Contents', 'MacOS',
918 'Content Shell')
919 else:
920 assert False, 'This platform is not supported for web tests.'
921
922
Abhishek Aryae5811afa2018-05-24 03:56:01923def _SetupOutputDir():
924 """Setup output directory."""
925 if os.path.exists(OUTPUT_DIR):
926 shutil.rmtree(OUTPUT_DIR)
927
928 # Creates |OUTPUT_DIR| and its platform sub-directory.
Max Moroz1de68d72018-08-21 13:38:18929 os.makedirs(coverage_utils.GetCoverageReportRootDirPath(OUTPUT_DIR))
Abhishek Aryae5811afa2018-05-24 03:56:01930
931
Yuke Liaoabfbba42019-06-11 16:03:59932def _SetMacXcodePath():
933 """Set DEVELOPER_DIR to the path to hermetic Xcode.app on Mac OS X."""
934 if sys.platform != 'darwin':
935 return
936
937 xcode_path = os.path.join(SRC_ROOT_PATH, 'build', 'mac_files', 'Xcode.app')
938 if os.path.exists(xcode_path):
939 os.environ['DEVELOPER_DIR'] = xcode_path
940
941
Yuke Liao506e8822017-12-04 16:52:54942def _ParseCommandArguments():
943 """Adds and parses relevant arguments for tool comands.
944
945 Returns:
946 A dictionary representing the arguments.
947 """
948 arg_parser = argparse.ArgumentParser()
949 arg_parser.usage = __doc__
950
Abhishek Arya1ec832c2017-12-05 18:06:59951 arg_parser.add_argument(
952 '-b',
953 '--build-dir',
954 type=str,
955 required=True,
956 help='The build directory, the path needs to be relative to the root of '
957 'the checkout.')
Yuke Liao506e8822017-12-04 16:52:54958
Abhishek Arya1ec832c2017-12-05 18:06:59959 arg_parser.add_argument(
960 '-o',
961 '--output-dir',
962 type=str,
963 required=True,
964 help='Output directory for generated artifacts.')
Yuke Liao506e8822017-12-04 16:52:54965
Abhishek Arya1ec832c2017-12-05 18:06:59966 arg_parser.add_argument(
967 '-c',
968 '--command',
969 action='append',
Abhishek Arya64636af2018-05-04 14:42:13970 required=False,
Abhishek Arya1ec832c2017-12-05 18:06:59971 help='Commands used to run test targets, one test target needs one and '
972 'only one command, when specifying commands, one should assume the '
Abhishek Arya64636af2018-05-04 14:42:13973 'current working directory is the root of the checkout. This option is '
974 'incompatible with -p/--profdata-file option.')
975
976 arg_parser.add_argument(
Abhishek Arya03911092018-05-21 16:42:35977 '-wt',
978 '--web-tests',
979 nargs='?',
980 type=str,
981 const=' ',
982 required=False,
983 help='Run blink web tests. Support passing arguments to run_web_tests.py')
984
985 arg_parser.add_argument(
Abhishek Arya64636af2018-05-04 14:42:13986 '-p',
987 '--profdata-file',
988 type=str,
Prakharb8527802023-04-20 09:48:46989 action='append',
Abhishek Arya64636af2018-05-04 14:42:13990 required=False,
Prakharb8527802023-04-20 09:48:46991 help=
992 'Path(s) to profdata file(s) to use for generating code coverage reports. '
993 'This can be useful if you generated the profdata file seperately in '
994 'your own test harness. This option is ignored if run command(s) are '
995 'already provided above using -c/--command option.')
Yuke Liao506e8822017-12-04 16:52:54996
Abhishek Arya1ec832c2017-12-05 18:06:59997 arg_parser.add_argument(
Yuke Liao66da1732017-12-05 22:19:42998 '-f',
999 '--filters',
1000 action='append',
Abhishek Arya16f059a2017-12-07 17:47:321001 required=False,
Yuke Liao66da1732017-12-05 22:19:421002 help='Directories or files to get code coverage for, and all files under '
1003 'the directories are included recursively.')
1004
1005 arg_parser.add_argument(
Yuke Liao0e4c8682018-04-18 21:06:591006 '-i',
1007 '--ignore-filename-regex',
1008 type=str,
1009 help='Skip source code files with file paths that match the given '
1010 'regular expression. For example, use -i=\'.*/out/.*|.*/third_party/.*\' '
1011 'to exclude files in third_party/ and out/ folders from the report.')
1012
1013 arg_parser.add_argument(
Yuke Liao1b852fd2018-05-11 17:07:321014 '--no-file-view',
1015 action='store_true',
1016 help='Don\'t generate the file view in the coverage report. When there '
1017 'are large number of html files, the file view becomes heavy and may '
1018 'cause the browser to freeze, and this argument comes handy.')
1019
1020 arg_parser.add_argument(
Max Moroz1de68d72018-08-21 13:38:181021 '--no-component-view',
1022 action='store_true',
1023 help='Don\'t generate the component view in the coverage report.')
1024
1025 arg_parser.add_argument(
Yuke Liao082e99632018-05-18 15:40:401026 '--coverage-tools-dir',
1027 type=str,
1028 help='Path of the directory where LLVM coverage tools (llvm-cov, '
1029 'llvm-profdata) exist. This should be only needed if you are testing '
1030 'against a custom built clang revision. Otherwise, we pick coverage '
1031 'tools automatically from your current source checkout.')
1032
1033 arg_parser.add_argument(
Abhishek Arya1ec832c2017-12-05 18:06:591034 '-j',
1035 '--jobs',
1036 type=int,
1037 default=None,
1038 help='Run N jobs to build in parallel. If not specified, a default value '
Max Moroz06576292019-01-03 19:22:521039 'will be derived based on CPUs and goma availability. Please refer to '
1040 '\'autoninja -h\' for more details.')
Yuke Liao506e8822017-12-04 16:52:541041
Abhishek Arya1ec832c2017-12-05 18:06:591042 arg_parser.add_argument(
Sahel Sharify38cabdc2020-01-16 00:40:011043 '--format',
1044 type=str,
1045 default='html',
Akekawit Jitprasertf9cb6622021-08-24 17:48:021046 help='Output format of the "llvm-cov show/export" command. The '
1047 'supported formats are "text", "html" and "lcov".')
Sahel Sharify38cabdc2020-01-16 00:40:011048
1049 arg_parser.add_argument(
Yuke Liao481d3482018-01-29 19:17:101050 '-v',
1051 '--verbose',
1052 action='store_true',
1053 help='Prints additional output for diagnostics.')
1054
1055 arg_parser.add_argument(
1056 '-l', '--log_file', type=str, help='Redirects logs to a file.')
1057
1058 arg_parser.add_argument(
Abhishek Aryac19bc5ef2018-05-04 22:10:021059 'targets',
1060 nargs='+',
1061 help='The names of the test targets to run. If multiple run commands are '
1062 'specified using the -c/--command option, then the order of targets and '
1063 'commands must match, otherwise coverage generation will fail.')
Yuke Liao506e8822017-12-04 16:52:541064
1065 args = arg_parser.parse_args()
1066 return args
1067
1068
1069def Main():
1070 """Execute tool commands."""
Yuke Liao082e99632018-05-18 15:40:401071
Abhishek Arya64636af2018-05-04 14:42:131072 # Change directory to source root to aid in relative paths calculations.
1073 os.chdir(SRC_ROOT_PATH)
Abhishek Arya8a0751a2018-05-03 18:53:111074
pasthanaa4844112020-05-21 18:03:551075 # Setup coverage binaries even when script is called with empty params. This
1076 # is used by coverage bot for initial setup.
1077 if len(sys.argv) == 1:
Choongwoo Hanbd1aa952021-06-09 22:25:381078 subprocess.check_call([
Akekawit Jitprasert928671e2021-09-20 18:40:581079 sys.executable, 'tools/clang/scripts/update.py', '--package',
1080 'coverage_tools'
Choongwoo Hanbd1aa952021-06-09 22:25:381081 ])
pasthanaa4844112020-05-21 18:03:551082 print(__doc__)
1083 return
1084
Yuke Liao506e8822017-12-04 16:52:541085 args = _ParseCommandArguments()
Max Moroz1de68d72018-08-21 13:38:181086 coverage_utils.ConfigureLogging(verbose=args.verbose, log_file=args.log_file)
Yuke Liao082e99632018-05-18 15:40:401087 _ConfigureLLVMCoverageTools(args)
Abhishek Arya64636af2018-05-04 14:42:131088
Yuke Liao506e8822017-12-04 16:52:541089 global BUILD_DIR
Max Moroz1de68d72018-08-21 13:38:181090 BUILD_DIR = coverage_utils.GetFullPath(args.build_dir)
Abhishek Aryae5811afa2018-05-24 03:56:011091
Yuke Liao506e8822017-12-04 16:52:541092 global OUTPUT_DIR
Max Moroz1de68d72018-08-21 13:38:181093 OUTPUT_DIR = coverage_utils.GetFullPath(args.output_dir)
Yuke Liao506e8822017-12-04 16:52:541094
Abhishek Arya03911092018-05-21 16:42:351095 assert args.web_tests or args.command or args.profdata_file, (
Abhishek Arya64636af2018-05-04 14:42:131096 'Need to either provide commands to run using -c/--command option OR '
Abhishek Arya03911092018-05-21 16:42:351097 'provide prof-data file as input using -p/--profdata-file option OR '
1098 'run web tests using -wt/--run-web-tests.')
Yuke Liaoc60b2d02018-03-02 21:40:431099
Abhishek Arya64636af2018-05-04 14:42:131100 assert not args.command or (len(args.targets) == len(args.command)), (
1101 'Number of targets must be equal to the number of test commands.')
Yuke Liaoc60b2d02018-03-02 21:40:431102
Abhishek Arya1ec832c2017-12-05 18:06:591103 assert os.path.exists(BUILD_DIR), (
Abhishek Aryafb70b532018-05-06 17:47:401104 'Build directory: "%s" doesn\'t exist. '
1105 'Please run "gn gen" to generate.' % BUILD_DIR)
Abhishek Arya64636af2018-05-04 14:42:131106
Yuke Liaoc60b2d02018-03-02 21:40:431107 _ValidateCurrentPlatformIsSupported()
Yuke Liao506e8822017-12-04 16:52:541108 _ValidateBuildingWithClangCoverage()
Abhishek Arya16f059a2017-12-07 17:47:321109
1110 absolute_filter_paths = []
Yuke Liao66da1732017-12-05 22:19:421111 if args.filters:
Abhishek Arya16f059a2017-12-07 17:47:321112 absolute_filter_paths = _VerifyPathsAndReturnAbsolutes(args.filters)
Yuke Liao66da1732017-12-05 22:19:421113
Abhishek Aryae5811afa2018-05-24 03:56:011114 _SetupOutputDir()
Yuke Liao506e8822017-12-04 16:52:541115
Abhishek Arya03911092018-05-21 16:42:351116 # Get .profdata file and list of binary paths.
1117 if args.web_tests:
Prakhara6418512023-05-22 17:17:451118 commands = [_GetCommandForWebTests(args.targets, args.web_tests)]
Abhishek Arya03911092018-05-21 16:42:351119 profdata_file_path = _CreateCoverageProfileDataForTargets(
1120 args.targets, commands, args.jobs)
1121 binary_paths = [_GetBinaryPathForWebTests()]
1122 elif args.command:
1123 for i in range(len(args.command)):
1124 assert not 'run_web_tests.py' in args.command[i], (
1125 'run_web_tests.py is not supported via --command argument. '
1126 'Please use --run-web-tests argument instead.')
1127
Abhishek Arya64636af2018-05-04 14:42:131128 # A list of commands are provided. Run them to generate profdata file, and
1129 # create a list of binary paths from parsing commands.
1130 _VerifyTargetExecutablesAreInBuildDirectory(args.command)
1131 profdata_file_path = _CreateCoverageProfileDataForTargets(
1132 args.targets, args.command, args.jobs)
1133 binary_paths = [_GetBinaryPath(command) for command in args.command]
1134 else:
Julia Hansbrough57bd3fc2023-03-30 01:47:231135 # An input prof-data file(s) is already provided.
1136 if len(args.profdata_file) == 1:
1137 # If it's just one input file, use as-is.
Prakharf851c562023-05-23 19:32:401138 profdata_file_path = args.profdata_file[0]
Julia Hansbrough57bd3fc2023-03-30 01:47:231139 else:
1140 # Otherwise, there are multiple profdata files and we need to merge them.
1141 profdata_file_path = _CreateCoverageProfileDataFromTargetProfDataFiles(args.profdata_file)
1142 # Since input prof-data files were provided, we only need to calculate the
1143 # binary paths from here.
Abhishek Arya64636af2018-05-04 14:42:131144 binary_paths = _GetBinaryPathsFromTargets(args.targets, args.build_dir)
Yuke Liaoea228d02018-01-05 19:10:331145
Erik Chen283b92c72019-07-22 16:37:391146 # If the checkout uses the hermetic xcode binaries, then otool must be
1147 # directly invoked. The indirection via /usr/bin/otool won't work unless
1148 # there's an actual system install of Xcode.
1149 otool_path = None
1150 if sys.platform == 'darwin':
1151 hermetic_otool_path = os.path.join(
1152 SRC_ROOT_PATH, 'build', 'mac_files', 'xcode_binaries', 'Contents',
1153 'Developer', 'Toolchains', 'XcodeDefault.xctoolchain', 'usr', 'bin',
1154 'otool')
1155 if os.path.exists(hermetic_otool_path):
1156 otool_path = hermetic_otool_path
Ben Joyce88282362021-01-29 23:53:311157
1158 if _IsAndroid():
1159 binary_paths = _GetBinaryPathsForAndroid(args.targets)
1160 elif sys.platform.startswith('linux') or sys.platform.startswith('darwin'):
Brent McBrideb25b177a42020-05-11 18:13:061161 binary_paths.extend(
1162 coverage_utils.GetSharedLibraries(binary_paths, BUILD_DIR, otool_path))
Abhishek Arya78120bc2018-05-07 20:53:541163
Akekawit Jitprasertf9cb6622021-08-24 17:48:021164 assert args.format in ['html', 'lcov', 'text'], (
1165 '%s is not a valid output format for "llvm-cov show/export". Only '
1166 '"text", "html" and "lcov" formats are supported.' % (args.format))
Sahel Sharify38cabdc2020-01-16 00:40:011167 logging.info('Generating code coverage report in %s (this can take a while '
1168 'depending on size of target!).' % (args.format))
Max Moroz1de68d72018-08-21 13:38:181169 per_file_summary_data = _GeneratePerFileCoverageSummary(
Yuke Liao0e4c8682018-04-18 21:06:591170 binary_paths, profdata_file_path, absolute_filter_paths,
1171 args.ignore_filename_regex)
Akekawit Jitprasertf9cb6622021-08-24 17:48:021172
1173 if args.format == 'lcov':
1174 _GeneratePerFileLineByLineCoverageInLcov(
1175 binary_paths, profdata_file_path, absolute_filter_paths,
1176 args.ignore_filename_regex)
1177 return
1178
Sahel Sharify38cabdc2020-01-16 00:40:011179 _GeneratePerFileLineByLineCoverageInFormat(
1180 binary_paths, profdata_file_path, absolute_filter_paths,
1181 args.ignore_filename_regex, args.format)
Max Moroz1de68d72018-08-21 13:38:181182 component_mappings = None
1183 if not args.no_component_view:
Choongwoo Hanbd1aa952021-06-09 22:25:381184 component_mappings = json.load(urlopen(COMPONENT_MAPPING_URL))
Yuke Liaodd1ec0592018-02-02 01:26:371185
Max Moroz1de68d72018-08-21 13:38:181186 # Call prepare here.
1187 processor = coverage_utils.CoverageReportPostProcessor(
1188 OUTPUT_DIR,
1189 SRC_ROOT_PATH,
1190 per_file_summary_data,
1191 no_component_view=args.no_component_view,
1192 no_file_view=args.no_file_view,
1193 component_mappings=component_mappings)
Yuke Liaodd1ec0592018-02-02 01:26:371194
Sahel Sharify38cabdc2020-01-16 00:40:011195 if args.format == 'html':
1196 processor.PrepareHtmlReport()
Yuke Liao506e8822017-12-04 16:52:541197
Abhishek Arya1ec832c2017-12-05 18:06:591198
Yuke Liao506e8822017-12-04 16:52:541199if __name__ == '__main__':
1200 sys.exit(Main())