blob: 93b19e6724bbd2748fdb79d367fba630fd82aee0 [file] [log] [blame]
[email protected]e185b7e82013-01-09 03:49:571#!/usr/bin/env python
2# Copyright (c) 2013 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import collections
7import glob
[email protected]485fb232013-08-22 19:56:338import hashlib
[email protected]f049a192013-10-10 01:11:269import json
[email protected]e185b7e82013-01-09 03:49:5710import os
[email protected]485fb232013-08-22 19:56:3311import random
[email protected]e2107bd2013-09-18 05:13:1012import re
[email protected]e185b7e82013-01-09 03:49:5713import shutil
[email protected]e185b7e82013-01-09 03:49:5714import sys
15
[email protected]c5282752013-06-07 23:14:3916import bb_utils
[email protected]b3873892013-07-10 04:57:1017import bb_annotations
[email protected]c5282752013-06-07 23:14:3918
[email protected]e185b7e82013-01-09 03:49:5719sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
jbudorickd28554a2016-01-11 16:22:5920import devil_chromium
[email protected]7849a332013-07-12 01:40:0921import provision_devices
jbudorick061629442015-09-03 18:00:5722from devil.android import device_utils
[email protected]e185b7e82013-01-09 03:49:5723from pylib import constants
jbudorick605b8932015-09-18 18:57:3924from pylib.gtest import gtest_config
[email protected]e185b7e82013-01-09 03:49:5725
[email protected]dc8ec3f2013-09-07 07:18:1426CHROME_SRC_DIR = bb_utils.CHROME_SRC
[email protected]ae410722013-10-24 15:57:3627DIR_BUILD_ROOT = os.path.dirname(CHROME_SRC_DIR)
[email protected]dc8ec3f2013-09-07 07:18:1428CHROME_OUT_DIR = bb_utils.CHROME_OUT_DIR
dprankeec3eb0a2014-09-26 21:42:5629BLINK_SCRIPTS_DIR = 'third_party/WebKit/Tools/Scripts'
[email protected]e185b7e82013-01-09 03:49:5730
[email protected]dc8ec3f2013-09-07 07:18:1431SLAVE_SCRIPTS_DIR = os.path.join(bb_utils.BB_BUILD_DIR, 'scripts', 'slave')
32LOGCAT_DIR = os.path.join(bb_utils.CHROME_OUT_DIR, 'logcat')
[email protected]4e622cee2013-09-17 18:32:1233GS_URL = 'https://storage.googleapis.com'
[email protected]c79bc8a2014-04-24 03:39:5234GS_AUTH_URL = 'https://storage.cloud.google.com'
[email protected]e185b7e82013-01-09 03:49:5735
36# Describes an instrumation test suite:
37# test: Name of test we're running.
38# apk: apk to be installed.
39# apk_package: package for the apk to be installed.
40# test_apk: apk to run tests on.
41# test_data: data folder in format destination:source.
[email protected]37ee0c792013-08-06 19:10:1342# host_driven_root: The host-driven test root directory.
[email protected]74050272013-07-02 14:02:1543# annotation: Annotation of the tests to include.
44# exclude_annotation: The annotation of the tests to exclude.
[email protected]e185b7e82013-01-09 03:49:5745I_TEST = collections.namedtuple('InstrumentationTest', [
jbudoricke4bb2b82015-02-09 18:35:0046 'name', 'apk', 'apk_package', 'test_apk', 'test_data', 'isolate_file_path',
47 'host_driven_root', 'annotation', 'exclude_annotation', 'extra_flags'])
[email protected]74050272013-07-02 14:02:1548
[email protected]f049a192013-10-10 01:11:2649
[email protected]ae410722013-10-24 15:57:3650def SrcPath(*path):
51 return os.path.join(CHROME_SRC_DIR, *path)
52
jbudorick605b8932015-09-18 18:57:3953
jbudoricke4bb2b82015-02-09 18:35:0054def I(name, apk, apk_package, test_apk, test_data, isolate_file_path=None,
55 host_driven_root=None, annotation=None, exclude_annotation=None,
56 extra_flags=None):
57 return I_TEST(name, apk, apk_package, test_apk, test_data, isolate_file_path,
58 host_driven_root, annotation, exclude_annotation, extra_flags)
[email protected]e185b7e82013-01-09 03:49:5759
60INSTRUMENTATION_TESTS = dict((suite.name, suite) for suite in [
[email protected]74050272013-07-02 14:02:1561 I('ContentShell',
62 'ContentShell.apk',
63 'org.chromium.content_shell_apk',
jbudorick34902132014-12-09 14:24:5664 'ContentShellTest',
jbudoricke4bb2b82015-02-09 18:35:0065 'content:content/test/data/android/device_files',
stip5d2e8c42016-04-25 23:38:1766 isolate_file_path='content/content_shell_test_data.isolate'),
gmanikpure842795722015-09-16 00:07:2967 I('ChromePublic',
68 'ChromePublic.apk',
69 'org.chromium.chrome',
70 'ChromePublicTest',
71 'chrome:chrome/test/data/android/device_files',
72 isolate_file_path='chrome/chrome_public_test_apk.isolate'),
[email protected]74050272013-07-02 14:02:1573 I('AndroidWebView',
74 'AndroidWebView.apk',
75 'org.chromium.android_webview.shell',
jbudorick34902132014-12-09 14:24:5676 'AndroidWebViewTest',
jbudoricke4bb2b82015-02-09 18:35:0077 'webview:android_webview/test/data/device_files',
stip5274ed62016-04-26 21:14:5478 isolate_file_path='android_webview/android_webview_test_data.isolate'),
mikecase94c8f1ad3b2014-10-27 23:09:3679 I('ChromeSyncShell',
80 'ChromeSyncShell.apk',
81 'org.chromium.chrome.browser.sync',
jbudorick34902132014-12-09 14:24:5682 'ChromeSyncShellTest',
83 None),
[email protected]e185b7e82013-01-09 03:49:5784 ])
85
jbudorickc574b1b2014-12-04 18:21:2886InstallablePackage = collections.namedtuple('InstallablePackage', [
87 'name', 'apk', 'apk_package'])
88
89INSTALLABLE_PACKAGES = dict((package.name, package) for package in (
90 [InstallablePackage(i.name, i.apk, i.apk_package)
91 for i in INSTRUMENTATION_TESTS.itervalues()] +
92 [InstallablePackage('ChromeDriverWebViewShell',
93 'ChromeDriverWebViewShell.apk',
94 'org.chromium.chromedriver_webview_shell')]))
95
jbudorick71a24982015-05-11 19:12:5696VALID_TESTS = set([
97 'base_junit_tests',
98 'chromedriver',
jbudorick71a24982015-05-11 19:12:5699 'components_browsertests',
100 'gfx_unittests',
dyen35c791f2015-05-12 19:25:13101 'gl_unittests',
jbudorick71a24982015-05-11 19:12:56102 'gpu',
103 'python_unittests',
jbudorick71a24982015-05-11 19:12:56104 'ui',
105 'unit',
106 'webkit',
107 'webkit_layout'
108])
[email protected]e185b7e82013-01-09 03:49:57109
[email protected]c5282752013-06-07 23:14:39110RunCmd = bb_utils.RunCmd
[email protected]e185b7e82013-01-09 03:49:57111
112
[email protected]e7bd3412013-09-20 17:15:28113def _GetRevision(options):
114 """Get the SVN revision number.
115
116 Args:
117 options: options object.
118
119 Returns:
120 The revision number.
121 """
122 revision = options.build_properties.get('got_revision')
123 if not revision:
124 revision = options.build_properties.get('revision', 'testing')
125 return revision
126
127
[email protected]f762c1202014-08-13 09:36:34128def _RunTest(options, cmd, suite):
129 """Run test command with runtest.py.
130
131 Args:
132 options: options object.
133 cmd: the command to run.
134 suite: test name.
135 """
136 property_args = bb_utils.EncodeProperties(options)
137 args = [os.path.join(SLAVE_SCRIPTS_DIR, 'runtest.py')] + property_args
138 args += ['--test-platform', 'android']
139 if options.factory_properties.get('generate_gtest_json'):
140 args.append('--generate-json-file')
141 args += ['-o', 'gtest-results/%s' % suite,
142 '--annotate', 'gtest',
143 '--build-number', str(options.build_properties.get('buildnumber',
144 '')),
145 '--builder-name', options.build_properties.get('buildername', '')]
146 if options.target == 'Release':
147 args += ['--target', 'Release']
148 else:
149 args += ['--target', 'Debug']
mikecase97d50b62014-11-14 18:33:52150 if options.flakiness_server:
151 args += ['--flakiness-dashboard-server=%s' %
152 options.flakiness_server]
[email protected]f762c1202014-08-13 09:36:34153 args += cmd
154 RunCmd(args, cwd=DIR_BUILD_ROOT)
155
156
[email protected]0ceb14992014-05-24 00:37:26157def RunTestSuites(options, suites, suites_options=None):
[email protected]fbe29322013-07-09 09:03:26158 """Manages an invocation of test_runner.py for gtests.
[email protected]e185b7e82013-01-09 03:49:57159
160 Args:
161 options: options object.
[email protected]9e689252013-07-30 20:14:36162 suites: List of suite names to run.
[email protected]0ceb14992014-05-24 00:37:26163 suites_options: Command line options dictionary for particular suites.
164 For example,
165 {'content_browsertests', ['--num_retries=1', '--release']}
166 will add the options only to content_browsertests.
[email protected]e185b7e82013-01-09 03:49:57167 """
[email protected]0ceb14992014-05-24 00:37:26168
169 if not suites_options:
170 suites_options = {}
171
jbudoricka583ba32015-09-11 17:23:19172 args = ['--verbose', '--blacklist-file', 'out/bad_devices.json']
[email protected]e185b7e82013-01-09 03:49:57173 if options.target == 'Release':
174 args.append('--release')
175 if options.asan:
176 args.append('--tool=asan')
[email protected]18d59b82013-11-12 09:21:41177 if options.gtest_filter:
178 args.append('--gtest-filter=%s' % options.gtest_filter)
[email protected]0ceb14992014-05-24 00:37:26179
[email protected]a8fea93f2013-01-10 04:00:07180 for suite in suites:
[email protected]9e689252013-07-30 20:14:36181 bb_annotations.PrintNamedStep(suite)
[email protected]f762c1202014-08-13 09:36:34182 cmd = [suite] + args
[email protected]0ceb14992014-05-24 00:37:26183 cmd += suites_options.get(suite, [])
jbudorickc4b6b6512015-04-23 21:30:28184 if suite == 'content_browsertests' or suite == 'components_browsertests':
[email protected]9e689252013-07-30 20:14:36185 cmd.append('--num_retries=1')
[email protected]f762c1202014-08-13 09:36:34186 _RunTest(options, cmd, suite)
[email protected]e185b7e82013-01-09 03:49:57187
[email protected]f049a192013-10-10 01:11:26188
jbudorick8548f23e2015-05-11 14:08:14189def RunJunitSuite(suite):
jbudorick08e45a92015-05-11 21:27:03190 bb_annotations.PrintNamedStep(suite)
jbudorick8548f23e2015-05-11 14:08:14191 RunCmd(['build/android/test_runner.py', 'junit', '-s', suite])
192
193
[email protected]e7bd3412013-09-20 17:15:28194def RunChromeDriverTests(options):
[email protected]d8897f6c2013-03-05 00:27:16195 """Run all the steps for running chromedriver tests."""
[email protected]b3873892013-07-10 04:57:10196 bb_annotations.PrintNamedStep('chromedriver_annotation')
[email protected]d8897f6c2013-03-05 00:27:16197 RunCmd(['chrome/test/chromedriver/run_buildbot_steps.py',
gmanikpure842795722015-09-16 00:07:29198 '--android-packages=%s,%s,%s,%s' %
199 ('chromium',
200 'chrome_stable',
[email protected]b1010d262013-11-27 22:01:28201 'chrome_beta',
202 'chromedriver_webview_shell'),
[email protected]e7bd3412013-09-20 17:15:28203 '--revision=%s' % _GetRevision(options),
[email protected]fde07002013-09-20 21:02:39204 '--update-log'])
[email protected]d8897f6c2013-03-05 00:27:16205
[email protected]29f7e7c2014-04-24 00:55:22206
[email protected]a2a725242013-01-09 21:52:57207def InstallApk(options, test, print_step=False):
208 """Install an apk to all phones.
209
210 Args:
211 options: options object
212 test: An I_TEST namedtuple
213 print_step: Print a buildbot step
214 """
215 if print_step:
[email protected]b3873892013-07-10 04:57:10216 bb_annotations.PrintNamedStep('install_%s' % test.name.lower())
[email protected]6ca57512013-08-23 21:42:04217
jbudoricka583ba32015-09-11 17:23:19218 args = [
219 '--apk_package', test.apk_package,
220 '--blacklist-file', 'out/bad_devices.json',
221 ]
[email protected]a2a725242013-01-09 21:52:57222 if options.target == 'Release':
[email protected]e185b7e82013-01-09 03:49:57223 args.append('--release')
[email protected]068b9cb42014-06-08 20:11:16224 args.append(test.apk)
[email protected]e185b7e82013-01-09 03:49:57225
[email protected]800673bf2013-05-14 17:15:30226 RunCmd(['build/android/adb_install_apk.py'] + args, halt_on_failure=True)
[email protected]e185b7e82013-01-09 03:49:57227
228
[email protected]acfaf4c2013-07-25 00:23:56229def RunInstrumentationSuite(options, test, flunk_on_failure=True,
[email protected]54c2d532013-08-24 01:36:24230 python_only=False, official_build=False):
[email protected]fbe29322013-07-09 09:03:26231 """Manages an invocation of test_runner.py for instrumentation tests.
[email protected]e185b7e82013-01-09 03:49:57232
233 Args:
234 options: options object
235 test: An I_TEST namedtuple
[email protected]acfaf4c2013-07-25 00:23:56236 flunk_on_failure: Flunk the step if tests fail.
237 Python: Run only host driven Python tests.
[email protected]54c2d532013-08-24 01:36:24238 official_build: Run official-build tests.
[email protected]e185b7e82013-01-09 03:49:57239 """
[email protected]b3873892013-07-10 04:57:10240 bb_annotations.PrintNamedStep('%s_instrumentation_tests' % test.name.lower())
[email protected]e185b7e82013-01-09 03:49:57241
[email protected]10955d32014-04-30 11:22:41242 if test.apk:
243 InstallApk(options, test)
jbudoricka583ba32015-09-11 17:23:19244 args = [
245 '--test-apk', test.test_apk, '--verbose',
246 '--blacklist-file', 'out/bad_devices.json'
247 ]
[email protected]10955d32014-04-30 11:22:41248 if test.test_data:
249 args.extend(['--test_data', test.test_data])
[email protected]e185b7e82013-01-09 03:49:57250 if options.target == 'Release':
251 args.append('--release')
252 if options.asan:
253 args.append('--tool=asan')
[email protected]14f139f42013-07-24 18:41:58254 if options.flakiness_server:
[email protected]b796a772013-01-19 03:55:22255 args.append('--flakiness-dashboard-server=%s' %
[email protected]14f139f42013-07-24 18:41:58256 options.flakiness_server)
[email protected]485fb232013-08-22 19:56:33257 if options.coverage_bucket:
258 args.append('--coverage-dir=%s' % options.coverage_dir)
jbudoricke4bb2b82015-02-09 18:35:00259 if test.isolate_file_path:
260 args.append('--isolate-file-path=%s' % test.isolate_file_path)
[email protected]8d8ca042013-02-14 19:29:17261 if test.host_driven_root:
[email protected]67954f822013-08-14 18:09:08262 args.append('--host-driven-root=%s' % test.host_driven_root)
[email protected]74050272013-07-02 14:02:15263 if test.annotation:
264 args.extend(['-A', test.annotation])
265 if test.exclude_annotation:
266 args.extend(['-E', test.exclude_annotation])
267 if test.extra_flags:
268 args.extend(test.extra_flags)
[email protected]acfaf4c2013-07-25 00:23:56269 if python_only:
270 args.append('-p')
[email protected]54c2d532013-08-24 01:36:24271 if official_build:
272 # The option needs to be assigned 'True' as it does not have an action
273 # associated with it.
274 args.append('--official-build')
[email protected]e185b7e82013-01-09 03:49:57275
[email protected]bdd22ff2013-07-17 17:21:12276 RunCmd(['build/android/test_runner.py', 'instrumentation'] + args,
277 flunk_on_failure=flunk_on_failure)
[email protected]e185b7e82013-01-09 03:49:57278
279
fdegans7b06b612014-09-26 09:50:53280def RunWebkitLint():
[email protected]e185b7e82013-01-09 03:49:57281 """Lint WebKit's TestExpectation files."""
[email protected]b3873892013-07-10 04:57:10282 bb_annotations.PrintNamedStep('webkit_lint')
dprankeec3eb0a2014-09-26 21:42:56283 RunCmd([SrcPath(os.path.join(BLINK_SCRIPTS_DIR, 'lint-test-expectations'))])
[email protected]e185b7e82013-01-09 03:49:57284
285
286def RunWebkitLayoutTests(options):
287 """Run layout tests on an actual device."""
[email protected]b3873892013-07-10 04:57:10288 bb_annotations.PrintNamedStep('webkit_tests')
[email protected]22ee7002013-01-23 20:58:04289 cmd_args = [
[email protected]f049a192013-10-10 01:11:26290 '--no-show-results',
291 '--no-new-test-results',
292 '--full-results-html',
293 '--clobber-old-results',
294 '--exit-after-n-failures', '5000',
295 '--exit-after-n-crashes-or-timeouts', '100',
296 '--debug-rwt-logging',
297 '--results-directory', '../layout-test-results',
298 '--target', options.target,
299 '--builder-name', options.build_properties.get('buildername', ''),
300 '--build-number', str(options.build_properties.get('buildnumber', '')),
301 '--master-name', 'ChromiumWebkit', # TODO: Get this from the cfg.
302 '--build-name', options.build_properties.get('buildername', ''),
303 '--platform=android']
[email protected]22ee7002013-01-23 20:58:04304
hendrikw1904804a2015-04-17 18:44:51305 for flag in 'test_results_server', 'driver_name', 'additional_driver_flag':
[email protected]22ee7002013-01-23 20:58:04306 if flag in options.factory_properties:
307 cmd_args.extend(['--%s' % flag.replace('_', '-'),
308 options.factory_properties.get(flag)])
309
[email protected]2c39b292013-03-20 09:34:10310 for f in options.factory_properties.get('additional_expectations', []):
311 cmd_args.extend(
[email protected]dc8ec3f2013-09-07 07:18:14312 ['--additional-expectations=%s' % os.path.join(CHROME_SRC_DIR, *f)])
[email protected]2c39b292013-03-20 09:34:10313
314 # TODO(dpranke): Remove this block after
315 # https://codereview.chromium.org/12927002/ lands.
[email protected]22ee7002013-01-23 20:58:04316 for f in options.factory_properties.get('additional_expectations_files', []):
[email protected]62c5b982013-01-26 08:23:16317 cmd_args.extend(
[email protected]dc8ec3f2013-09-07 07:18:14318 ['--additional-expectations=%s' % os.path.join(CHROME_SRC_DIR, *f)])
[email protected]22ee7002013-01-23 20:58:04319
ager158f2842014-09-26 06:07:24320 exit_code = RunCmd(
dprankeec3eb0a2014-09-26 21:42:56321 [SrcPath(os.path.join(BLINK_SCRIPTS_DIR, 'run-webkit-tests'))] + cmd_args)
[email protected]1782ef42013-10-18 21:07:33322 if exit_code == 255: # test_run_results.UNEXPECTED_ERROR_EXIT_STATUS
[email protected]f049a192013-10-10 01:11:26323 bb_annotations.PrintMsg('?? (crashed or hung)')
[email protected]1782ef42013-10-18 21:07:33324 elif exit_code == 254: # test_run_results.NO_DEVICES_EXIT_STATUS
[email protected]361229ac2013-10-17 18:57:15325 bb_annotations.PrintMsg('?? (no devices found)')
[email protected]1782ef42013-10-18 21:07:33326 elif exit_code == 253: # test_run_results.NO_TESTS_EXIT_STATUS
[email protected]361229ac2013-10-17 18:57:15327 bb_annotations.PrintMsg('?? (no tests found)')
[email protected]f049a192013-10-10 01:11:26328 else:
329 full_results_path = os.path.join('..', 'layout-test-results',
330 'full_results.json')
331 if os.path.exists(full_results_path):
332 full_results = json.load(open(full_results_path))
[email protected]e2782b82013-10-14 19:43:45333 unexpected_passes, unexpected_failures, unexpected_flakes = (
[email protected]f049a192013-10-10 01:11:26334 _ParseLayoutTestResults(full_results))
335 if unexpected_failures:
dpranked7cae312015-02-08 02:40:54336 _PrintDashboardLink('failed', unexpected_failures.keys(),
[email protected]f049a192013-10-10 01:11:26337 max_tests=25)
338 elif unexpected_passes:
dpranked7cae312015-02-08 02:40:54339 _PrintDashboardLink('unexpected passes', unexpected_passes.keys(),
[email protected]f049a192013-10-10 01:11:26340 max_tests=10)
341 if unexpected_flakes:
dpranked7cae312015-02-08 02:40:54342 _PrintDashboardLink('unexpected flakes', unexpected_flakes.keys(),
[email protected]f049a192013-10-10 01:11:26343 max_tests=10)
[email protected]bc14cb12013-10-10 18:47:14344
345 if exit_code == 0 and (unexpected_passes or unexpected_flakes):
346 # If exit_code != 0, RunCmd() will have already printed an error.
347 bb_annotations.PrintWarning()
[email protected]f049a192013-10-10 01:11:26348 else:
[email protected]bc14cb12013-10-10 18:47:14349 bb_annotations.PrintError()
[email protected]f049a192013-10-10 01:11:26350 bb_annotations.PrintMsg('?? (results missing)')
[email protected]e185b7e82013-01-09 03:49:57351
[email protected]dc8ec3f2013-09-07 07:18:14352 if options.factory_properties.get('archive_webkit_results', False):
353 bb_annotations.PrintNamedStep('archive_webkit_results')
[email protected]613e5a32013-09-18 01:46:32354 base = 'https://storage.googleapis.com/chromium-layout-test-archives'
355 builder_name = options.build_properties.get('buildername', '')
356 build_number = str(options.build_properties.get('buildnumber', ''))
[email protected]f049a192013-10-10 01:11:26357 results_link = '%s/%s/%s/layout-test-results/results.html' % (
358 base, EscapeBuilderName(builder_name), build_number)
359 bb_annotations.PrintLink('results', results_link)
[email protected]e2107bd2013-09-18 05:13:10360 bb_annotations.PrintLink('(zip)', '%s/%s/%s/layout-test-results.zip' % (
361 base, EscapeBuilderName(builder_name), build_number))
[email protected]85db7daf32013-09-09 21:21:25362 gs_bucket = 'gs://chromium-layout-test-archives'
[email protected]dc8ec3f2013-09-07 07:18:14363 RunCmd([os.path.join(SLAVE_SCRIPTS_DIR, 'chromium',
364 'archive_layout_test_results.py'),
[email protected]f049a192013-10-10 01:11:26365 '--results-dir', '../../layout-test-results',
[email protected]f049a192013-10-10 01:11:26366 '--build-number', build_number,
367 '--builder-name', builder_name,
[email protected]ae410722013-10-24 15:57:36368 '--gs-bucket', gs_bucket],
369 cwd=DIR_BUILD_ROOT)
[email protected]f049a192013-10-10 01:11:26370
371
372def _ParseLayoutTestResults(results):
373 """Extract the failures from the test run."""
374 # Cloned from third_party/WebKit/Tools/Scripts/print-json-test-results
375 tests = _ConvertTrieToFlatPaths(results['tests'])
376 failures = {}
377 flakes = {}
378 passes = {}
379 for (test, result) in tests.iteritems():
380 if result.get('is_unexpected'):
[email protected]ff81fe112013-10-22 21:13:16381 actual_results = result['actual'].split()
382 expected_results = result['expected'].split()
383 if len(actual_results) > 1:
384 # We report the first failure type back, even if the second
385 # was more severe.
386 if actual_results[1] in expected_results:
387 flakes[test] = actual_results[0]
388 else:
389 failures[test] = actual_results[0]
390 elif actual_results[0] == 'PASS':
[email protected]f049a192013-10-10 01:11:26391 passes[test] = result
392 else:
[email protected]ff81fe112013-10-22 21:13:16393 failures[test] = actual_results[0]
[email protected]f049a192013-10-10 01:11:26394
395 return (passes, failures, flakes)
396
397
398def _ConvertTrieToFlatPaths(trie, prefix=None):
399 """Flatten the trie of failures into a list."""
400 # Cloned from third_party/WebKit/Tools/Scripts/print-json-test-results
401 result = {}
402 for name, data in trie.iteritems():
403 if prefix:
404 name = prefix + '/' + name
405
406 if len(data) and 'actual' not in data and 'expected' not in data:
407 result.update(_ConvertTrieToFlatPaths(data, name))
408 else:
409 result[name] = data
410
411 return result
412
413
414def _PrintDashboardLink(link_text, tests, max_tests):
415 """Add a link to the flakiness dashboard in the step annotations."""
416 if len(tests) > max_tests:
417 test_list_text = ' '.join(tests[:max_tests]) + ' and more'
418 else:
419 test_list_text = ' '.join(tests)
420
421 dashboard_base = ('http://test-results.appspot.com'
422 '/dashboards/flakiness_dashboard.html#'
423 'master=ChromiumWebkit&tests=')
424
425 bb_annotations.PrintLink('%d %s: %s' %
426 (len(tests), link_text, test_list_text),
427 dashboard_base + ','.join(tests))
[email protected]dc8ec3f2013-09-07 07:18:14428
[email protected]e185b7e82013-01-09 03:49:57429
[email protected]e2107bd2013-09-18 05:13:10430def EscapeBuilderName(builder_name):
431 return re.sub('[ ()]', '_', builder_name)
432
433
[email protected]74050272013-07-02 14:02:15434def SpawnLogcatMonitor():
435 shutil.rmtree(LOGCAT_DIR, ignore_errors=True)
[email protected]97d10322013-10-04 20:53:04436 bb_utils.SpawnCmd([
[email protected]dc8ec3f2013-09-07 07:18:14437 os.path.join(CHROME_SRC_DIR, 'build', 'android', 'adb_logcat_monitor.py'),
[email protected]74050272013-07-02 14:02:15438 LOGCAT_DIR])
439
440 # Wait for logcat_monitor to pull existing logcat
441 RunCmd(['sleep', '5'])
442
[email protected]f049a192013-10-10 01:11:26443
[email protected]74050272013-07-02 14:02:15444def ProvisionDevices(options):
[email protected]b3873892013-07-10 04:57:10445 bb_annotations.PrintNamedStep('provision_devices')
[email protected]abfec372013-08-16 07:22:16446
447 if not bb_utils.TESTING:
448 # Restart adb to work around bugs, sleep to wait for usb discovery.
[email protected]781c58a2014-05-14 05:32:16449 device_utils.RestartServer()
[email protected]abfec372013-08-16 07:22:16450 RunCmd(['sleep', '1'])
jbudoricka583ba32015-09-11 17:23:19451 provision_cmd = [
452 'build/android/provision_devices.py', '-t', options.target,
453 '--blacklist-file', 'out/bad_devices.json'
454 ]
[email protected]7849a332013-07-12 01:40:09455 if options.auto_reconnect:
456 provision_cmd.append('--auto-reconnect')
[email protected]3356038b2014-06-17 02:40:13457 if options.skip_wipe:
458 provision_cmd.append('--skip-wipe')
jbudorick9669e5b2015-03-09 16:29:07459 if options.disable_location:
460 provision_cmd.append('--disable-location')
[email protected]7b54a8722014-07-17 21:51:21461 RunCmd(provision_cmd, halt_on_failure=True)
[email protected]78af8712013-01-14 10:37:12462
[email protected]74050272013-07-02 14:02:15463
[email protected]e5d85a72013-10-19 13:44:02464def DeviceStatusCheck(options):
[email protected]b3873892013-07-10 04:57:10465 bb_annotations.PrintNamedStep('device_status_check')
jbudoricka583ba32015-09-11 17:23:19466 cmd = [
467 'build/android/buildbot/bb_device_status_check.py',
468 '--blacklist-file', 'out/bad_devices.json',
469 ]
[email protected]e5d85a72013-10-19 13:44:02470 if options.restart_usb:
471 cmd.append('--restart-usb')
472 RunCmd(cmd, halt_on_failure=True)
[email protected]693c54d2013-01-09 19:41:25473
[email protected]e185b7e82013-01-09 03:49:57474
[email protected]74050272013-07-02 14:02:15475def GetDeviceSetupStepCmds():
476 return [
[email protected]f049a192013-10-10 01:11:26477 ('device_status_check', DeviceStatusCheck),
[email protected]917cd320b2013-12-03 16:13:35478 ('provision_devices', ProvisionDevices),
[email protected]74050272013-07-02 14:02:15479 ]
[email protected]e185b7e82013-01-09 03:49:57480
[email protected]e185b7e82013-01-09 03:49:57481
[email protected]74050272013-07-02 14:02:15482def RunUnitTests(options):
jbudorick605b8932015-09-18 18:57:39483 suites = gtest_config.STABLE_TEST_SUITES
[email protected]502362c72014-02-26 07:06:44484 if options.asan:
485 suites = [s for s in suites
jbudorick605b8932015-09-18 18:57:39486 if s not in gtest_config.ASAN_EXCLUDED_TEST_SUITES]
[email protected]502362c72014-02-26 07:06:44487 RunTestSuites(options, suites)
[email protected]74050272013-07-02 14:02:15488
489
490def RunInstrumentationTests(options):
491 for test in INSTRUMENTATION_TESTS.itervalues():
492 RunInstrumentationSuite(options, test)
493
494
495def RunWebkitTests(options):
[email protected]130d0b572014-02-03 18:09:01496 RunTestSuites(options, ['webkit_unit_tests', 'blink_heap_unittests'])
fdegans7b06b612014-09-26 09:50:53497 RunWebkitLint()
[email protected]74050272013-07-02 14:02:15498
499
[email protected]a4b1ec972013-09-14 05:36:25500def RunGPUTests(options):
bpastened20f4772016-04-20 15:37:58501 exit_code = 0
[email protected]9047cd182014-05-29 01:04:06502 revision = _GetRevision(options)
[email protected]5117f5d2014-05-29 16:59:16503 builder_name = options.build_properties.get('buildername', 'noname')
504
505 bb_annotations.PrintNamedStep('pixel_tests')
bpastened20f4772016-04-20 15:37:58506 exit_code = RunCmd(['content/test/gpu/run_gpu_test.py',
507 'pixel', '-v',
508 '--browser',
509 'android-content-shell',
510 '--build-revision',
511 str(revision),
512 '--upload-refimg-to-cloud-storage',
513 '--refimg-cloud-storage-bucket',
514 'chromium-gpu-archive/reference-images',
515 '--os-type',
516 'android',
517 '--test-machine-name',
518 EscapeBuilderName(builder_name),
519 '--android-blacklist-file',
520 'out/bad_devices.json']) or exit_code
[email protected]fb9cd4bb2013-10-16 21:59:53521
[email protected]cce70f02013-10-15 12:53:19522 bb_annotations.PrintNamedStep('webgl_conformance_tests')
bpastened20f4772016-04-20 15:37:58523 exit_code = RunCmd(['content/test/gpu/run_gpu_test.py', '-v',
524 '--browser=android-content-shell', 'webgl_conformance',
525 '--webgl-conformance-version=1.0.1',
526 '--android-blacklist-file',
527 'out/bad_devices.json']) or exit_code
[email protected]bb508f82013-09-06 06:42:24528
sieversb44610f2015-05-05 23:06:17529 bb_annotations.PrintNamedStep('android_webview_webgl_conformance_tests')
bpastened20f4772016-04-20 15:37:58530 exit_code = RunCmd(['content/test/gpu/run_gpu_test.py', '-v',
531 '--browser=android-webview-shell', 'webgl_conformance',
532 '--webgl-conformance-version=1.0.1',
533 '--android-blacklist-file',
534 'out/bad_devices.json']) or exit_code
sieversb44610f2015-05-05 23:06:17535
[email protected]876cb602014-05-31 04:49:15536 bb_annotations.PrintNamedStep('gpu_rasterization_tests')
bpastened20f4772016-04-20 15:37:58537 exit_code = RunCmd(['content/test/gpu/run_gpu_test.py',
538 'gpu_rasterization', '-v',
539 '--browser',
540 'android-content-shell',
541 '--build-revision',
542 str(revision),
543 '--test-machine-name',
544 EscapeBuilderName(builder_name),
545 '--android-blacklist-file',
546 'out/bad_devices.json']) or exit_code
547
548 return exit_code
[email protected]876cb602014-05-31 04:49:15549
[email protected]bb508f82013-09-06 06:42:24550
jbudorick256fd532014-10-24 01:50:13551def RunPythonUnitTests(_options):
552 for suite in constants.PYTHON_UNIT_TEST_SUITES:
553 bb_annotations.PrintNamedStep(suite)
554 RunCmd(['build/android/test_runner.py', 'python', '-s', suite])
555
556
[email protected]74050272013-07-02 14:02:15557def GetTestStepCmds():
558 return [
jbudorick8548f23e2015-05-11 14:08:14559 ('base_junit_tests',
560 lambda _options: RunJunitSuite('base_junit_tests')),
[email protected]74050272013-07-02 14:02:15561 ('chromedriver', RunChromeDriverTests),
jbudorickc4b6b6512015-04-23 21:30:28562 ('components_browsertests',
563 lambda options: RunTestSuites(options, ['components_browsertests'])),
tfarina43d93532015-05-11 18:04:07564 ('gfx_unittests',
565 lambda options: RunTestSuites(options, ['gfx_unittests'])),
dyen35c791f2015-05-12 19:25:13566 ('gl_unittests',
567 lambda options: RunTestSuites(options, ['gl_unittests'])),
[email protected]bb508f82013-09-06 06:42:24568 ('gpu', RunGPUTests),
jbudorick256fd532014-10-24 01:50:13569 ('python_unittests', RunPythonUnitTests),
[email protected]74050272013-07-02 14:02:15570 ('ui', RunInstrumentationTests),
mikecase0178d482014-08-27 21:58:18571 ('unit', RunUnitTests),
[email protected]74050272013-07-02 14:02:15572 ('webkit', RunWebkitTests),
[email protected]02bfada2013-08-12 05:00:52573 ('webkit_layout', RunWebkitLayoutTests),
[email protected]74050272013-07-02 14:02:15574 ]
575
576
[email protected]c11a4682014-04-22 23:04:13577def MakeGSPath(options, gs_base_dir):
578 revision = _GetRevision(options)
579 bot_id = options.build_properties.get('buildername', 'testing')
580 randhash = hashlib.sha1(str(random.random())).hexdigest()
581 gs_path = '%s/%s/%s/%s' % (gs_base_dir, bot_id, revision, randhash)
[email protected]c79bc8a2014-04-24 03:39:52582 # remove double slashes, happens with blank revisions and confuses gsutil
583 gs_path = re.sub('/+', '/', gs_path)
[email protected]c11a4682014-04-22 23:04:13584 return gs_path
585
[email protected]4e622cee2013-09-17 18:32:12586def UploadHTML(options, gs_base_dir, dir_to_upload, link_text,
587 link_rel_path='index.html', gs_url=GS_URL):
588 """Uploads directory at |dir_to_upload| to Google Storage and output a link.
[email protected]485fb232013-08-22 19:56:33589
590 Args:
591 options: Command line options.
[email protected]4e622cee2013-09-17 18:32:12592 gs_base_dir: The Google Storage base directory (e.g.
593 'chromium-code-coverage/java')
594 dir_to_upload: Absolute path to the directory to be uploaded.
595 link_text: Link text to be displayed on the step.
596 link_rel_path: Link path relative to |dir_to_upload|.
597 gs_url: Google storage URL.
[email protected]485fb232013-08-22 19:56:33598 """
[email protected]c11a4682014-04-22 23:04:13599 gs_path = MakeGSPath(options, gs_base_dir)
[email protected]4e622cee2013-09-17 18:32:12600 RunCmd([bb_utils.GSUTIL_PATH, 'cp', '-R', dir_to_upload, 'gs://%s' % gs_path])
601 bb_annotations.PrintLink(link_text,
[email protected]f049a192013-10-10 01:11:26602 '%s/%s/%s' % (gs_url, gs_path, link_rel_path))
[email protected]485fb232013-08-22 19:56:33603
604
605def GenerateJavaCoverageReport(options):
606 """Generates an HTML coverage report using EMMA and uploads it."""
607 bb_annotations.PrintNamedStep('java_coverage_report')
608
609 coverage_html = os.path.join(options.coverage_dir, 'coverage_html')
610 RunCmd(['build/android/generate_emma_html.py',
611 '--coverage-dir', options.coverage_dir,
[email protected]dc8ec3f2013-09-07 07:18:14612 '--metadata-dir', os.path.join(CHROME_OUT_DIR, options.target),
[email protected]a1f1abfe2013-08-27 22:02:43613 '--cleanup',
[email protected]485fb232013-08-22 19:56:33614 '--output', os.path.join(coverage_html, 'index.html')])
[email protected]4e622cee2013-09-17 18:32:12615 return coverage_html
[email protected]485fb232013-08-22 19:56:33616
617
[email protected]74050272013-07-02 14:02:15618def LogcatDump(options):
[email protected]e185b7e82013-01-09 03:49:57619 # Print logcat, kill logcat monitor
[email protected]b3873892013-07-10 04:57:10620 bb_annotations.PrintNamedStep('logcat_dump')
[email protected]6fe4d062014-05-03 00:07:30621 logcat_file = os.path.join(CHROME_OUT_DIR, options.target, 'full_log.txt')
jbudorick0f77e962014-11-19 15:41:29622 RunCmd([SrcPath('build', 'android', 'adb_logcat_printer.py'),
[email protected]46e095c2013-11-21 13:48:58623 '--output-path', logcat_file, LOGCAT_DIR])
[email protected]c11a4682014-04-22 23:04:13624 gs_path = MakeGSPath(options, 'chromium-android/logcat_dumps')
[email protected]6fe4d062014-05-03 00:07:30625 RunCmd([bb_utils.GSUTIL_PATH, 'cp', '-z', 'txt', logcat_file,
626 'gs://%s' % gs_path])
[email protected]c79bc8a2014-04-24 03:39:52627 bb_annotations.PrintLink('logcat dump', '%s/%s' % (GS_AUTH_URL, gs_path))
[email protected]e185b7e82013-01-09 03:49:57628
[email protected]74050272013-07-02 14:02:15629
[email protected]79d3d8d82014-02-05 13:47:04630def RunStackToolSteps(options):
631 """Run stack tool steps.
632
633 Stack tool is run for logcat dump, optionally for ASAN.
634 """
635 bb_annotations.PrintNamedStep('Run stack tool with logcat dump')
agrievea952a112016-02-09 18:29:44636 build_dir = os.path.join(CHROME_OUT_DIR, options.target)
637 logcat_file = os.path.join(build_dir, 'full_log.txt')
[email protected]79d3d8d82014-02-05 13:47:04638 RunCmd([os.path.join(CHROME_SRC_DIR, 'third_party', 'android_platform',
639 'development', 'scripts', 'stack'),
agrievea952a112016-02-09 18:29:44640 '--output-directory', build_dir,
flackra48994182016-02-08 19:42:24641 '--more-info', logcat_file])
[email protected]79d3d8d82014-02-05 13:47:04642 if options.asan_symbolize:
643 bb_annotations.PrintNamedStep('Run stack tool for ASAN')
644 RunCmd([
645 os.path.join(CHROME_SRC_DIR, 'build', 'android', 'asan_symbolize.py'),
agrievea952a112016-02-09 18:29:44646 '--output-directory', build_dir,
flackra48994182016-02-08 19:42:24647 '-l', logcat_file])
[email protected]79d3d8d82014-02-05 13:47:04648
649
[email protected]74050272013-07-02 14:02:15650def GenerateTestReport(options):
[email protected]b3873892013-07-10 04:57:10651 bb_annotations.PrintNamedStep('test_report')
[email protected]e185b7e82013-01-09 03:49:57652 for report in glob.glob(
[email protected]dc8ec3f2013-09-07 07:18:14653 os.path.join(CHROME_OUT_DIR, options.target, 'test_logs', '*.log')):
[email protected]78af8712013-01-14 10:37:12654 RunCmd(['cat', report])
[email protected]e185b7e82013-01-09 03:49:57655 os.remove(report)
656
657
[email protected]74050272013-07-02 14:02:15658def MainTestWrapper(options):
bpastened20f4772016-04-20 15:37:58659 exit_code = 0
[email protected]4cf098c2013-08-02 21:08:06660 try:
661 # Spawn logcat monitor
662 SpawnLogcatMonitor()
[email protected]74050272013-07-02 14:02:15663
[email protected]4cf098c2013-08-02 21:08:06664 # Run all device setup steps
665 for _, cmd in GetDeviceSetupStepCmds():
666 cmd(options)
[email protected]74050272013-07-02 14:02:15667
[email protected]4cf098c2013-08-02 21:08:06668 if options.install:
jbudorick7da88de62014-12-03 21:46:03669 for i in options.install:
jbudorickc574b1b2014-12-04 18:21:28670 install_obj = INSTALLABLE_PACKAGES[i]
671 InstallApk(options, install_obj, print_step=True)
[email protected]74050272013-07-02 14:02:15672
[email protected]4cf098c2013-08-02 21:08:06673 if options.test_filter:
bpastened20f4772016-04-20 15:37:58674 exit_code = bb_utils.RunSteps(
675 options.test_filter, GetTestStepCmds(), options) or exit_code
[email protected]74050272013-07-02 14:02:15676
[email protected]485fb232013-08-22 19:56:33677 if options.coverage_bucket:
[email protected]4e622cee2013-09-17 18:32:12678 coverage_html = GenerateJavaCoverageReport(options)
679 UploadHTML(options, '%s/java' % options.coverage_bucket, coverage_html,
680 'Coverage Report')
[email protected]ec7b2222014-01-16 02:49:15681 shutil.rmtree(coverage_html, ignore_errors=True)
[email protected]485fb232013-08-22 19:56:33682
[email protected]4cf098c2013-08-02 21:08:06683 if options.experimental:
bpastened20f4772016-04-20 15:37:58684 exit_code = RunTestSuites(
685 options, gtest_config.EXPERIMENTAL_TEST_SUITES) or exit_code
686
687 return exit_code
[email protected]74050272013-07-02 14:02:15688
[email protected]4cf098c2013-08-02 21:08:06689 finally:
690 # Run all post test steps
691 LogcatDump(options)
[email protected]79d3d8d82014-02-05 13:47:04692 if not options.disable_stack_tool:
693 RunStackToolSteps(options)
[email protected]4cf098c2013-08-02 21:08:06694 GenerateTestReport(options)
695 # KillHostHeartbeat() has logic to check if heartbeat process is running,
696 # and kills only if it finds the process is running on the host.
697 provision_devices.KillHostHeartbeat()
[email protected]773c4f02014-08-12 19:05:22698 if options.cleanup:
699 shutil.rmtree(os.path.join(CHROME_OUT_DIR, options.target),
700 ignore_errors=True)
[email protected]74050272013-07-02 14:02:15701
702
703def GetDeviceStepsOptParser():
[email protected]c5282752013-06-07 23:14:39704 parser = bb_utils.GetParser()
[email protected]e185b7e82013-01-09 03:49:57705 parser.add_option('--experimental', action='store_true',
706 help='Run experiemental tests')
707 parser.add_option('-f', '--test-filter', metavar='<filter>', default=[],
708 action='append',
709 help=('Run a test suite. Test suites: "%s"' %
710 '", "'.join(VALID_TESTS)))
[email protected]18d59b82013-11-12 09:21:41711 parser.add_option('--gtest-filter',
712 help='Filter for running a subset of tests of a gtest test')
[email protected]e185b7e82013-01-09 03:49:57713 parser.add_option('--asan', action='store_true', help='Run tests with asan.')
jbudorick7da88de62014-12-03 21:46:03714 parser.add_option('--install', metavar='<apk name>', action="append",
[email protected]e185b7e82013-01-09 03:49:57715 help='Install an apk by name')
[email protected]4a3375d2014-01-08 12:56:50716 parser.add_option('--no-reboot', action='store_true',
717 help='Do not reboot devices during provisioning.')
[email protected]485fb232013-08-22 19:56:33718 parser.add_option('--coverage-bucket',
719 help=('Bucket name to store coverage results. Coverage is '
720 'only run if this is set.'))
[email protected]e5d85a72013-10-19 13:44:02721 parser.add_option('--restart-usb', action='store_true',
722 help='Restart usb ports before device status check.')
[email protected]14f139f42013-07-24 18:41:58723 parser.add_option(
724 '--flakiness-server',
[email protected]f049a192013-10-10 01:11:26725 help=('The flakiness dashboard server to which the results should be '
726 'uploaded.'))
[email protected]12f36c82013-03-29 06:21:13727 parser.add_option(
728 '--auto-reconnect', action='store_true',
729 help='Push script to device which restarts adbd on disconnections.')
[email protected]3356038b2014-06-17 02:40:13730 parser.add_option('--skip-wipe', action='store_true',
731 help='Do not wipe devices during provisioning.')
jbudorick9669e5b2015-03-09 16:29:07732 parser.add_option('--disable-location', action='store_true',
733 help='Disable location settings.')
[email protected]74050272013-07-02 14:02:15734 parser.add_option(
735 '--logcat-dump-output',
736 help='The logcat dump output will be "tee"-ed into this file')
[email protected]29826042014-06-06 19:00:05737 # During processing perf bisects, a seperate working directory created under
738 # which builds are produced. Therefore we should look for relevent output
739 # file under this directory.(/b/build/slave/<slave_name>/build/bisect/src/out)
740 parser.add_option(
741 '--chrome-output-dir',
742 help='Chrome output directory to be used while bisecting.')
743
jbudorick0f77e962014-11-19 15:41:29744 parser.add_option('--disable-stack-tool', action='store_true',
[email protected]79d3d8d82014-02-05 13:47:04745 help='Do not run stack tool.')
jbudorick0f77e962014-11-19 15:41:29746 parser.add_option('--asan-symbolize', action='store_true',
[email protected]79d3d8d82014-02-05 13:47:04747 help='Run stack tool for ASAN')
[email protected]773c4f02014-08-12 19:05:22748 parser.add_option('--cleanup', action='store_true',
749 help='Delete out/<target> directory at the end of the run.')
[email protected]74050272013-07-02 14:02:15750 return parser
751
752
753def main(argv):
754 parser = GetDeviceStepsOptParser()
[email protected]e185b7e82013-01-09 03:49:57755 options, args = parser.parse_args(argv[1:])
756
jbudorickd28554a2016-01-11 16:22:59757 devil_chromium.Initialize()
758
[email protected]e185b7e82013-01-09 03:49:57759 if args:
[email protected]c5282752013-06-07 23:14:39760 return sys.exit('Unused args %s' % args)
[email protected]e185b7e82013-01-09 03:49:57761
762 unknown_tests = set(options.test_filter) - VALID_TESTS
763 if unknown_tests:
[email protected]c5282752013-06-07 23:14:39764 return sys.exit('Unknown tests %s' % list(unknown_tests))
[email protected]e185b7e82013-01-09 03:49:57765
766 setattr(options, 'target', options.factory_properties.get('target', 'Debug'))
[email protected]29826042014-06-06 19:00:05767
jbudorick58b4d362015-09-08 16:44:59768 # pylint: disable=global-statement
[email protected]29826042014-06-06 19:00:05769 if options.chrome_output_dir:
770 global CHROME_OUT_DIR
771 global LOGCAT_DIR
772 CHROME_OUT_DIR = options.chrome_output_dir
773 LOGCAT_DIR = os.path.join(CHROME_OUT_DIR, 'logcat')
774
[email protected]485fb232013-08-22 19:56:33775 if options.coverage_bucket:
776 setattr(options, 'coverage_dir',
[email protected]dc8ec3f2013-09-07 07:18:14777 os.path.join(CHROME_OUT_DIR, options.target, 'coverage'))
[email protected]e185b7e82013-01-09 03:49:57778
bpastened20f4772016-04-20 15:37:58779 return MainTestWrapper(options)
[email protected]e185b7e82013-01-09 03:49:57780
781
782if __name__ == '__main__':
783 sys.exit(main(sys.argv))