blob: 10dfa15111312107b0a2edc9b89fb26db67c3fd8 [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]78af8712013-01-14 10:37:1210import multiprocessing
[email protected]e185b7e82013-01-09 03:49:5711import os
[email protected]485fb232013-08-22 19:56:3312import random
[email protected]e2107bd2013-09-18 05:13:1013import re
[email protected]e185b7e82013-01-09 03:49:5714import shutil
[email protected]e185b7e82013-01-09 03:49:5715import sys
16
[email protected]c5282752013-06-07 23:14:3917import bb_utils
[email protected]b3873892013-07-10 04:57:1018import bb_annotations
[email protected]c5282752013-06-07 23:14:3919
[email protected]e185b7e82013-01-09 03:49:5720sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
[email protected]7849a332013-07-12 01:40:0921import provision_devices
[email protected]78af8712013-01-14 10:37:1222from pylib import android_commands
[email protected]e185b7e82013-01-09 03:49:5723from pylib import constants
[email protected]044d79b2014-04-10 19:37:3024from pylib.device import device_utils
[email protected]a8fea93f2013-01-10 04:00:0725from pylib.gtest import gtest_config
[email protected]e185b7e82013-01-09 03:49:5726
[email protected]dc8ec3f2013-09-07 07:18:1427CHROME_SRC_DIR = bb_utils.CHROME_SRC
[email protected]ae410722013-10-24 15:57:3628DIR_BUILD_ROOT = os.path.dirname(CHROME_SRC_DIR)
[email protected]dc8ec3f2013-09-07 07:18:1429CHROME_OUT_DIR = bb_utils.CHROME_OUT_DIR
[email protected]78af8712013-01-14 10:37:1230sys.path.append(os.path.join(
[email protected]dc8ec3f2013-09-07 07:18:1431 CHROME_SRC_DIR, 'third_party', 'android_testrunner'))
[email protected]78af8712013-01-14 10:37:1232import errors
33
[email protected]e185b7e82013-01-09 03:49:5734
[email protected]dc8ec3f2013-09-07 07:18:1435SLAVE_SCRIPTS_DIR = os.path.join(bb_utils.BB_BUILD_DIR, 'scripts', 'slave')
36LOGCAT_DIR = os.path.join(bb_utils.CHROME_OUT_DIR, 'logcat')
[email protected]4e622cee2013-09-17 18:32:1237GS_URL = 'https://storage.googleapis.com'
[email protected]e185b7e82013-01-09 03:49:5738
39# Describes an instrumation test suite:
40# test: Name of test we're running.
41# apk: apk to be installed.
42# apk_package: package for the apk to be installed.
43# test_apk: apk to run tests on.
44# test_data: data folder in format destination:source.
[email protected]37ee0c792013-08-06 19:10:1345# host_driven_root: The host-driven test root directory.
[email protected]74050272013-07-02 14:02:1546# annotation: Annotation of the tests to include.
47# exclude_annotation: The annotation of the tests to exclude.
[email protected]e185b7e82013-01-09 03:49:5748I_TEST = collections.namedtuple('InstrumentationTest', [
[email protected]74050272013-07-02 14:02:1549 'name', 'apk', 'apk_package', 'test_apk', 'test_data', 'host_driven_root',
50 'annotation', 'exclude_annotation', 'extra_flags'])
51
[email protected]f049a192013-10-10 01:11:2652
[email protected]ae410722013-10-24 15:57:3653def SrcPath(*path):
54 return os.path.join(CHROME_SRC_DIR, *path)
55
56
[email protected]74050272013-07-02 14:02:1557def I(name, apk, apk_package, test_apk, test_data, host_driven_root=None,
58 annotation=None, exclude_annotation=None, extra_flags=None):
59 return I_TEST(name, apk, apk_package, test_apk, test_data, host_driven_root,
60 annotation, exclude_annotation, extra_flags)
[email protected]e185b7e82013-01-09 03:49:5761
62INSTRUMENTATION_TESTS = dict((suite.name, suite) for suite in [
[email protected]74050272013-07-02 14:02:1563 I('ContentShell',
64 'ContentShell.apk',
65 'org.chromium.content_shell_apk',
66 'ContentShellTest',
67 'content:content/test/data/android/device_files'),
[email protected]efeb59e2014-03-12 01:31:2668 I('ChromeShell',
69 'ChromeShell.apk',
[email protected]34460fc2014-03-04 07:18:0070 'org.chromium.chrome.shell',
[email protected]efeb59e2014-03-12 01:31:2671 'ChromeShellTest',
[email protected]74050272013-07-02 14:02:1572 'chrome:chrome/test/data/android/device_files',
[email protected]efeb59e2014-03-12 01:31:2673 constants.CHROME_SHELL_HOST_DRIVEN_DIR),
[email protected]74050272013-07-02 14:02:1574 I('AndroidWebView',
75 'AndroidWebView.apk',
76 'org.chromium.android_webview.shell',
77 'AndroidWebViewTest',
78 'webview:android_webview/test/data/device_files'),
[email protected]e185b7e82013-01-09 03:49:5779 ])
80
[email protected]29f7e7c2014-04-24 00:55:2281VALID_TESTS = set(['chromedriver', 'gpu', 'telemetry_perf_unittests',
82 'ui', 'unit', 'webkit', 'webkit_layout', 'webrtc_chromium',
83 'webrtc_native'])
[email protected]e185b7e82013-01-09 03:49:5784
[email protected]c5282752013-06-07 23:14:3985RunCmd = bb_utils.RunCmd
[email protected]e185b7e82013-01-09 03:49:5786
87
[email protected]e7bd3412013-09-20 17:15:2888def _GetRevision(options):
89 """Get the SVN revision number.
90
91 Args:
92 options: options object.
93
94 Returns:
95 The revision number.
96 """
97 revision = options.build_properties.get('got_revision')
98 if not revision:
99 revision = options.build_properties.get('revision', 'testing')
100 return revision
101
102
[email protected]78af8712013-01-14 10:37:12103# multiprocessing map_async requires a top-level function for pickle library.
104def RebootDeviceSafe(device):
105 """Reboot a device, wait for it to start, and squelch timeout exceptions."""
106 try:
[email protected]044d79b2014-04-10 19:37:30107 device_utils.DeviceUtils(device).old_interface.Reboot(True)
[email protected]78af8712013-01-14 10:37:12108 except errors.DeviceUnresponsiveError as e:
109 return e
110
111
112def RebootDevices():
113 """Reboot all attached and online devices."""
[email protected]c94ae6b2013-01-14 21:38:34114 # Early return here to avoid presubmit dependence on adb,
115 # which might not exist in this checkout.
[email protected]c5282752013-06-07 23:14:39116 if bb_utils.TESTING:
[email protected]c94ae6b2013-01-14 21:38:34117 return
[email protected]044d79b2014-04-10 19:37:30118 devices = android_commands.GetAttachedDevices()
[email protected]78af8712013-01-14 10:37:12119 print 'Rebooting: %s' % devices
[email protected]c94ae6b2013-01-14 21:38:34120 if devices:
[email protected]78af8712013-01-14 10:37:12121 pool = multiprocessing.Pool(len(devices))
122 results = pool.map_async(RebootDeviceSafe, devices).get(99999)
123
124 for device, result in zip(devices, results):
125 if result:
126 print '%s failed to startup.' % device
127
128 if any(results):
[email protected]b3873892013-07-10 04:57:10129 bb_annotations.PrintWarning()
[email protected]78af8712013-01-14 10:37:12130 else:
131 print 'Reboots complete.'
132
133
[email protected]a8fea93f2013-01-10 04:00:07134def RunTestSuites(options, suites):
[email protected]fbe29322013-07-09 09:03:26135 """Manages an invocation of test_runner.py for gtests.
[email protected]e185b7e82013-01-09 03:49:57136
137 Args:
138 options: options object.
[email protected]9e689252013-07-30 20:14:36139 suites: List of suite names to run.
[email protected]e185b7e82013-01-09 03:49:57140 """
141 args = ['--verbose']
[email protected]e185b7e82013-01-09 03:49:57142 if options.target == 'Release':
143 args.append('--release')
144 if options.asan:
145 args.append('--tool=asan')
[email protected]18d59b82013-11-12 09:21:41146 if options.gtest_filter:
147 args.append('--gtest-filter=%s' % options.gtest_filter)
[email protected]a8fea93f2013-01-10 04:00:07148 for suite in suites:
[email protected]9e689252013-07-30 20:14:36149 bb_annotations.PrintNamedStep(suite)
150 cmd = ['build/android/test_runner.py', 'gtest', '-s', suite] + args
151 if suite == 'content_browsertests':
152 cmd.append('--num_retries=1')
[email protected]9324bff2013-03-13 04:09:27153 RunCmd(cmd)
[email protected]e185b7e82013-01-09 03:49:57154
[email protected]f049a192013-10-10 01:11:26155
[email protected]e7bd3412013-09-20 17:15:28156def RunChromeDriverTests(options):
[email protected]d8897f6c2013-03-05 00:27:16157 """Run all the steps for running chromedriver tests."""
[email protected]b3873892013-07-10 04:57:10158 bb_annotations.PrintNamedStep('chromedriver_annotation')
[email protected]d8897f6c2013-03-05 00:27:16159 RunCmd(['chrome/test/chromedriver/run_buildbot_steps.py',
[email protected]b1010d262013-11-27 22:01:28160 '--android-packages=%s,%s,%s,%s' %
[email protected]efeb59e2014-03-12 01:31:26161 ('chrome_shell',
[email protected]4418f022013-11-11 19:21:03162 'chrome_stable',
[email protected]b1010d262013-11-27 22:01:28163 'chrome_beta',
164 'chromedriver_webview_shell'),
[email protected]e7bd3412013-09-20 17:15:28165 '--revision=%s' % _GetRevision(options),
[email protected]fde07002013-09-20 21:02:39166 '--update-log'])
[email protected]d8897f6c2013-03-05 00:27:16167
[email protected]f049a192013-10-10 01:11:26168
[email protected]29f7e7c2014-04-24 00:55:22169def RunTelemetryPerfUnitTests(options):
170 """Runs the telemetry perf unit tests.
171
172 Args:
173 options: options object.
174 """
175 InstallApk(options, INSTRUMENTATION_TESTS['ChromeShell'], False)
176 args = ['--browser', 'android-chromium-testshell']
177 devices = android_commands.GetAttachedDevices()
178 if devices:
179 args = args + ['--device', devices[0]]
180 bb_annotations.PrintNamedStep('telemetry_perf_unittests')
181 RunCmd(['tools/perf/run_tests'] + args)
182
183
[email protected]a2a725242013-01-09 21:52:57184def InstallApk(options, test, print_step=False):
185 """Install an apk to all phones.
186
187 Args:
188 options: options object
189 test: An I_TEST namedtuple
190 print_step: Print a buildbot step
191 """
192 if print_step:
[email protected]b3873892013-07-10 04:57:10193 bb_annotations.PrintNamedStep('install_%s' % test.name.lower())
[email protected]6ca57512013-08-23 21:42:04194
[email protected]a2a725242013-01-09 21:52:57195 args = ['--apk', test.apk, '--apk_package', test.apk_package]
196 if options.target == 'Release':
[email protected]e185b7e82013-01-09 03:49:57197 args.append('--release')
198
[email protected]800673bf2013-05-14 17:15:30199 RunCmd(['build/android/adb_install_apk.py'] + args, halt_on_failure=True)
[email protected]e185b7e82013-01-09 03:49:57200
201
[email protected]acfaf4c2013-07-25 00:23:56202def RunInstrumentationSuite(options, test, flunk_on_failure=True,
[email protected]54c2d532013-08-24 01:36:24203 python_only=False, official_build=False):
[email protected]fbe29322013-07-09 09:03:26204 """Manages an invocation of test_runner.py for instrumentation tests.
[email protected]e185b7e82013-01-09 03:49:57205
206 Args:
207 options: options object
208 test: An I_TEST namedtuple
[email protected]acfaf4c2013-07-25 00:23:56209 flunk_on_failure: Flunk the step if tests fail.
210 Python: Run only host driven Python tests.
[email protected]54c2d532013-08-24 01:36:24211 official_build: Run official-build tests.
[email protected]e185b7e82013-01-09 03:49:57212 """
[email protected]b3873892013-07-10 04:57:10213 bb_annotations.PrintNamedStep('%s_instrumentation_tests' % test.name.lower())
[email protected]e185b7e82013-01-09 03:49:57214
[email protected]a2a725242013-01-09 21:52:57215 InstallApk(options, test)
[email protected]d1a0657c2013-04-10 22:38:59216 args = ['--test-apk', test.test_apk, '--test_data', test.test_data,
[email protected]fb7ab5e82013-07-26 18:31:20217 '--verbose']
[email protected]e185b7e82013-01-09 03:49:57218 if options.target == 'Release':
219 args.append('--release')
220 if options.asan:
221 args.append('--tool=asan')
[email protected]14f139f42013-07-24 18:41:58222 if options.flakiness_server:
[email protected]b796a772013-01-19 03:55:22223 args.append('--flakiness-dashboard-server=%s' %
[email protected]14f139f42013-07-24 18:41:58224 options.flakiness_server)
[email protected]485fb232013-08-22 19:56:33225 if options.coverage_bucket:
226 args.append('--coverage-dir=%s' % options.coverage_dir)
[email protected]8d8ca042013-02-14 19:29:17227 if test.host_driven_root:
[email protected]67954f822013-08-14 18:09:08228 args.append('--host-driven-root=%s' % test.host_driven_root)
[email protected]74050272013-07-02 14:02:15229 if test.annotation:
230 args.extend(['-A', test.annotation])
231 if test.exclude_annotation:
232 args.extend(['-E', test.exclude_annotation])
233 if test.extra_flags:
234 args.extend(test.extra_flags)
[email protected]acfaf4c2013-07-25 00:23:56235 if python_only:
236 args.append('-p')
[email protected]54c2d532013-08-24 01:36:24237 if official_build:
238 # The option needs to be assigned 'True' as it does not have an action
239 # associated with it.
240 args.append('--official-build')
[email protected]e185b7e82013-01-09 03:49:57241
[email protected]bdd22ff2013-07-17 17:21:12242 RunCmd(['build/android/test_runner.py', 'instrumentation'] + args,
243 flunk_on_failure=flunk_on_failure)
[email protected]e185b7e82013-01-09 03:49:57244
245
246def RunWebkitLint(target):
247 """Lint WebKit's TestExpectation files."""
[email protected]b3873892013-07-10 04:57:10248 bb_annotations.PrintNamedStep('webkit_lint')
[email protected]ae410722013-10-24 15:57:36249 RunCmd([SrcPath('webkit/tools/layout_tests/run_webkit_tests.py'),
[email protected]e185b7e82013-01-09 03:49:57250 '--lint-test-files',
251 '--chromium',
252 '--target', target])
253
254
255def RunWebkitLayoutTests(options):
256 """Run layout tests on an actual device."""
[email protected]b3873892013-07-10 04:57:10257 bb_annotations.PrintNamedStep('webkit_tests')
[email protected]22ee7002013-01-23 20:58:04258 cmd_args = [
[email protected]f049a192013-10-10 01:11:26259 '--no-show-results',
260 '--no-new-test-results',
261 '--full-results-html',
262 '--clobber-old-results',
263 '--exit-after-n-failures', '5000',
264 '--exit-after-n-crashes-or-timeouts', '100',
265 '--debug-rwt-logging',
266 '--results-directory', '../layout-test-results',
267 '--target', options.target,
268 '--builder-name', options.build_properties.get('buildername', ''),
269 '--build-number', str(options.build_properties.get('buildnumber', '')),
270 '--master-name', 'ChromiumWebkit', # TODO: Get this from the cfg.
271 '--build-name', options.build_properties.get('buildername', ''),
272 '--platform=android']
[email protected]22ee7002013-01-23 20:58:04273
274 for flag in 'test_results_server', 'driver_name', 'additional_drt_flag':
275 if flag in options.factory_properties:
276 cmd_args.extend(['--%s' % flag.replace('_', '-'),
277 options.factory_properties.get(flag)])
278
[email protected]2c39b292013-03-20 09:34:10279 for f in options.factory_properties.get('additional_expectations', []):
280 cmd_args.extend(
[email protected]dc8ec3f2013-09-07 07:18:14281 ['--additional-expectations=%s' % os.path.join(CHROME_SRC_DIR, *f)])
[email protected]2c39b292013-03-20 09:34:10282
283 # TODO(dpranke): Remove this block after
284 # https://codereview.chromium.org/12927002/ lands.
[email protected]22ee7002013-01-23 20:58:04285 for f in options.factory_properties.get('additional_expectations_files', []):
[email protected]62c5b982013-01-26 08:23:16286 cmd_args.extend(
[email protected]dc8ec3f2013-09-07 07:18:14287 ['--additional-expectations=%s' % os.path.join(CHROME_SRC_DIR, *f)])
[email protected]22ee7002013-01-23 20:58:04288
[email protected]ae410722013-10-24 15:57:36289 exit_code = RunCmd([SrcPath('webkit/tools/layout_tests/run_webkit_tests.py')]
290 + cmd_args)
[email protected]1782ef42013-10-18 21:07:33291 if exit_code == 255: # test_run_results.UNEXPECTED_ERROR_EXIT_STATUS
[email protected]f049a192013-10-10 01:11:26292 bb_annotations.PrintMsg('?? (crashed or hung)')
[email protected]1782ef42013-10-18 21:07:33293 elif exit_code == 254: # test_run_results.NO_DEVICES_EXIT_STATUS
[email protected]361229ac2013-10-17 18:57:15294 bb_annotations.PrintMsg('?? (no devices found)')
[email protected]1782ef42013-10-18 21:07:33295 elif exit_code == 253: # test_run_results.NO_TESTS_EXIT_STATUS
[email protected]361229ac2013-10-17 18:57:15296 bb_annotations.PrintMsg('?? (no tests found)')
[email protected]f049a192013-10-10 01:11:26297 else:
298 full_results_path = os.path.join('..', 'layout-test-results',
299 'full_results.json')
300 if os.path.exists(full_results_path):
301 full_results = json.load(open(full_results_path))
[email protected]e2782b82013-10-14 19:43:45302 unexpected_passes, unexpected_failures, unexpected_flakes = (
[email protected]f049a192013-10-10 01:11:26303 _ParseLayoutTestResults(full_results))
304 if unexpected_failures:
305 _PrintDashboardLink('failed', unexpected_failures,
306 max_tests=25)
307 elif unexpected_passes:
308 _PrintDashboardLink('unexpected passes', unexpected_passes,
309 max_tests=10)
310 if unexpected_flakes:
311 _PrintDashboardLink('unexpected flakes', unexpected_flakes,
312 max_tests=10)
[email protected]bc14cb12013-10-10 18:47:14313
314 if exit_code == 0 and (unexpected_passes or unexpected_flakes):
315 # If exit_code != 0, RunCmd() will have already printed an error.
316 bb_annotations.PrintWarning()
[email protected]f049a192013-10-10 01:11:26317 else:
[email protected]bc14cb12013-10-10 18:47:14318 bb_annotations.PrintError()
[email protected]f049a192013-10-10 01:11:26319 bb_annotations.PrintMsg('?? (results missing)')
[email protected]e185b7e82013-01-09 03:49:57320
[email protected]dc8ec3f2013-09-07 07:18:14321 if options.factory_properties.get('archive_webkit_results', False):
322 bb_annotations.PrintNamedStep('archive_webkit_results')
[email protected]613e5a32013-09-18 01:46:32323 base = 'https://storage.googleapis.com/chromium-layout-test-archives'
324 builder_name = options.build_properties.get('buildername', '')
325 build_number = str(options.build_properties.get('buildnumber', ''))
[email protected]f049a192013-10-10 01:11:26326 results_link = '%s/%s/%s/layout-test-results/results.html' % (
327 base, EscapeBuilderName(builder_name), build_number)
328 bb_annotations.PrintLink('results', results_link)
[email protected]e2107bd2013-09-18 05:13:10329 bb_annotations.PrintLink('(zip)', '%s/%s/%s/layout-test-results.zip' % (
330 base, EscapeBuilderName(builder_name), build_number))
[email protected]85db7daf32013-09-09 21:21:25331 gs_bucket = 'gs://chromium-layout-test-archives'
[email protected]dc8ec3f2013-09-07 07:18:14332 RunCmd([os.path.join(SLAVE_SCRIPTS_DIR, 'chromium',
333 'archive_layout_test_results.py'),
[email protected]f049a192013-10-10 01:11:26334 '--results-dir', '../../layout-test-results',
[email protected]f049a192013-10-10 01:11:26335 '--build-number', build_number,
336 '--builder-name', builder_name,
[email protected]ae410722013-10-24 15:57:36337 '--gs-bucket', gs_bucket],
338 cwd=DIR_BUILD_ROOT)
[email protected]f049a192013-10-10 01:11:26339
340
341def _ParseLayoutTestResults(results):
342 """Extract the failures from the test run."""
343 # Cloned from third_party/WebKit/Tools/Scripts/print-json-test-results
344 tests = _ConvertTrieToFlatPaths(results['tests'])
345 failures = {}
346 flakes = {}
347 passes = {}
348 for (test, result) in tests.iteritems():
349 if result.get('is_unexpected'):
[email protected]ff81fe112013-10-22 21:13:16350 actual_results = result['actual'].split()
351 expected_results = result['expected'].split()
352 if len(actual_results) > 1:
353 # We report the first failure type back, even if the second
354 # was more severe.
355 if actual_results[1] in expected_results:
356 flakes[test] = actual_results[0]
357 else:
358 failures[test] = actual_results[0]
359 elif actual_results[0] == 'PASS':
[email protected]f049a192013-10-10 01:11:26360 passes[test] = result
361 else:
[email protected]ff81fe112013-10-22 21:13:16362 failures[test] = actual_results[0]
[email protected]f049a192013-10-10 01:11:26363
364 return (passes, failures, flakes)
365
366
367def _ConvertTrieToFlatPaths(trie, prefix=None):
368 """Flatten the trie of failures into a list."""
369 # Cloned from third_party/WebKit/Tools/Scripts/print-json-test-results
370 result = {}
371 for name, data in trie.iteritems():
372 if prefix:
373 name = prefix + '/' + name
374
375 if len(data) and 'actual' not in data and 'expected' not in data:
376 result.update(_ConvertTrieToFlatPaths(data, name))
377 else:
378 result[name] = data
379
380 return result
381
382
383def _PrintDashboardLink(link_text, tests, max_tests):
384 """Add a link to the flakiness dashboard in the step annotations."""
385 if len(tests) > max_tests:
386 test_list_text = ' '.join(tests[:max_tests]) + ' and more'
387 else:
388 test_list_text = ' '.join(tests)
389
390 dashboard_base = ('http://test-results.appspot.com'
391 '/dashboards/flakiness_dashboard.html#'
392 'master=ChromiumWebkit&tests=')
393
394 bb_annotations.PrintLink('%d %s: %s' %
395 (len(tests), link_text, test_list_text),
396 dashboard_base + ','.join(tests))
[email protected]dc8ec3f2013-09-07 07:18:14397
[email protected]e185b7e82013-01-09 03:49:57398
[email protected]e2107bd2013-09-18 05:13:10399def EscapeBuilderName(builder_name):
400 return re.sub('[ ()]', '_', builder_name)
401
402
[email protected]74050272013-07-02 14:02:15403def SpawnLogcatMonitor():
404 shutil.rmtree(LOGCAT_DIR, ignore_errors=True)
[email protected]97d10322013-10-04 20:53:04405 bb_utils.SpawnCmd([
[email protected]dc8ec3f2013-09-07 07:18:14406 os.path.join(CHROME_SRC_DIR, 'build', 'android', 'adb_logcat_monitor.py'),
[email protected]74050272013-07-02 14:02:15407 LOGCAT_DIR])
408
409 # Wait for logcat_monitor to pull existing logcat
410 RunCmd(['sleep', '5'])
411
[email protected]f049a192013-10-10 01:11:26412
[email protected]74050272013-07-02 14:02:15413def ProvisionDevices(options):
[email protected]b3873892013-07-10 04:57:10414 bb_annotations.PrintNamedStep('provision_devices')
[email protected]abfec372013-08-16 07:22:16415
416 if not bb_utils.TESTING:
417 # Restart adb to work around bugs, sleep to wait for usb discovery.
[email protected]044d79b2014-04-10 19:37:30418 device_utils.DeviceUtils(None).old_interface.RestartAdbServer()
[email protected]abfec372013-08-16 07:22:16419 RunCmd(['sleep', '1'])
420
[email protected]4a3375d2014-01-08 12:56:50421 if not options.no_reboot:
[email protected]78af8712013-01-14 10:37:12422 RebootDevices()
[email protected]7849a332013-07-12 01:40:09423 provision_cmd = ['build/android/provision_devices.py', '-t', options.target]
424 if options.auto_reconnect:
425 provision_cmd.append('--auto-reconnect')
426 RunCmd(provision_cmd)
[email protected]78af8712013-01-14 10:37:12427
[email protected]74050272013-07-02 14:02:15428
[email protected]e5d85a72013-10-19 13:44:02429def DeviceStatusCheck(options):
[email protected]b3873892013-07-10 04:57:10430 bb_annotations.PrintNamedStep('device_status_check')
[email protected]e5d85a72013-10-19 13:44:02431 cmd = ['build/android/buildbot/bb_device_status_check.py']
432 if options.restart_usb:
433 cmd.append('--restart-usb')
434 RunCmd(cmd, halt_on_failure=True)
[email protected]693c54d2013-01-09 19:41:25435
[email protected]e185b7e82013-01-09 03:49:57436
[email protected]74050272013-07-02 14:02:15437def GetDeviceSetupStepCmds():
438 return [
[email protected]f049a192013-10-10 01:11:26439 ('device_status_check', DeviceStatusCheck),
[email protected]917cd320b2013-12-03 16:13:35440 ('provision_devices', ProvisionDevices),
[email protected]74050272013-07-02 14:02:15441 ]
[email protected]e185b7e82013-01-09 03:49:57442
[email protected]e185b7e82013-01-09 03:49:57443
[email protected]74050272013-07-02 14:02:15444def RunUnitTests(options):
[email protected]502362c72014-02-26 07:06:44445 suites = gtest_config.STABLE_TEST_SUITES
446 if options.asan:
447 suites = [s for s in suites
448 if s not in gtest_config.ASAN_EXCLUDED_TEST_SUITES]
449 RunTestSuites(options, suites)
[email protected]74050272013-07-02 14:02:15450
451
452def RunInstrumentationTests(options):
453 for test in INSTRUMENTATION_TESTS.itervalues():
454 RunInstrumentationSuite(options, test)
455
456
457def RunWebkitTests(options):
[email protected]130d0b572014-02-03 18:09:01458 RunTestSuites(options, ['webkit_unit_tests', 'blink_heap_unittests'])
[email protected]74050272013-07-02 14:02:15459 RunWebkitLint(options.target)
460
461
[email protected]640afed2013-10-21 08:18:29462def RunWebRTCChromiumTests(options):
463 RunTestSuites(options, gtest_config.WEBRTC_CHROMIUM_TEST_SUITES)
464
465
466def RunWebRTCNativeTests(options):
467 RunTestSuites(options, gtest_config.WEBRTC_NATIVE_TEST_SUITES)
[email protected]02bfada2013-08-12 05:00:52468
469
[email protected]a4b1ec972013-09-14 05:36:25470def RunGPUTests(options):
471 InstallApk(options, INSTRUMENTATION_TESTS['ContentShell'], False)
[email protected]fb9cd4bb2013-10-16 21:59:53472
[email protected]74448822013-10-22 16:40:53473 bb_annotations.PrintNamedStep('gpu_tests')
[email protected]7391b312013-12-12 17:06:01474 revision = _GetRevision(options)
[email protected]389234f2014-02-25 03:31:12475 RunCmd(['content/test/gpu/run_gpu_test.py',
[email protected]e66b5922014-01-07 20:10:04476 'pixel',
477 '--browser',
478 'android-content-shell',
479 '--build-revision',
480 str(revision),
481 '--upload-refimg-to-cloud-storage',
482 '--refimg-cloud-storage-bucket',
483 'chromium-gpu-archive/reference-images',
484 '--os-type',
485 'android',
486 '--test-machine-name',
487 EscapeBuilderName(
488 options.build_properties.get('buildername', 'noname'))])
[email protected]fb9cd4bb2013-10-16 21:59:53489
[email protected]cce70f02013-10-15 12:53:19490 bb_annotations.PrintNamedStep('webgl_conformance_tests')
[email protected]389234f2014-02-25 03:31:12491 RunCmd(['content/test/gpu/run_gpu_test.py',
[email protected]cce70f02013-10-15 12:53:19492 '--browser=android-content-shell', 'webgl_conformance',
493 '--webgl-conformance-version=1.0.1'])
[email protected]bb508f82013-09-06 06:42:24494
495
[email protected]74050272013-07-02 14:02:15496def GetTestStepCmds():
497 return [
498 ('chromedriver', RunChromeDriverTests),
[email protected]bb508f82013-09-06 06:42:24499 ('gpu', RunGPUTests),
[email protected]29f7e7c2014-04-24 00:55:22500 ('telemetry_perf_unittests', RunTelemetryPerfUnitTests),
[email protected]74050272013-07-02 14:02:15501 ('unit', RunUnitTests),
502 ('ui', RunInstrumentationTests),
503 ('webkit', RunWebkitTests),
[email protected]02bfada2013-08-12 05:00:52504 ('webkit_layout', RunWebkitLayoutTests),
[email protected]640afed2013-10-21 08:18:29505 ('webrtc_chromium', RunWebRTCChromiumTests),
506 ('webrtc_native', RunWebRTCNativeTests),
[email protected]74050272013-07-02 14:02:15507 ]
508
509
[email protected]c11a4682014-04-22 23:04:13510def MakeGSPath(options, gs_base_dir):
511 revision = _GetRevision(options)
512 bot_id = options.build_properties.get('buildername', 'testing')
513 randhash = hashlib.sha1(str(random.random())).hexdigest()
514 gs_path = '%s/%s/%s/%s' % (gs_base_dir, bot_id, revision, randhash)
515 return gs_path
516
[email protected]4e622cee2013-09-17 18:32:12517def UploadHTML(options, gs_base_dir, dir_to_upload, link_text,
518 link_rel_path='index.html', gs_url=GS_URL):
519 """Uploads directory at |dir_to_upload| to Google Storage and output a link.
[email protected]485fb232013-08-22 19:56:33520
521 Args:
522 options: Command line options.
[email protected]4e622cee2013-09-17 18:32:12523 gs_base_dir: The Google Storage base directory (e.g.
524 'chromium-code-coverage/java')
525 dir_to_upload: Absolute path to the directory to be uploaded.
526 link_text: Link text to be displayed on the step.
527 link_rel_path: Link path relative to |dir_to_upload|.
528 gs_url: Google storage URL.
[email protected]485fb232013-08-22 19:56:33529 """
[email protected]c11a4682014-04-22 23:04:13530 gs_path = MakeGSPath(options, gs_base_dir)
[email protected]4e622cee2013-09-17 18:32:12531 RunCmd([bb_utils.GSUTIL_PATH, 'cp', '-R', dir_to_upload, 'gs://%s' % gs_path])
532 bb_annotations.PrintLink(link_text,
[email protected]f049a192013-10-10 01:11:26533 '%s/%s/%s' % (gs_url, gs_path, link_rel_path))
[email protected]485fb232013-08-22 19:56:33534
535
536def GenerateJavaCoverageReport(options):
537 """Generates an HTML coverage report using EMMA and uploads it."""
538 bb_annotations.PrintNamedStep('java_coverage_report')
539
540 coverage_html = os.path.join(options.coverage_dir, 'coverage_html')
541 RunCmd(['build/android/generate_emma_html.py',
542 '--coverage-dir', options.coverage_dir,
[email protected]dc8ec3f2013-09-07 07:18:14543 '--metadata-dir', os.path.join(CHROME_OUT_DIR, options.target),
[email protected]a1f1abfe2013-08-27 22:02:43544 '--cleanup',
[email protected]485fb232013-08-22 19:56:33545 '--output', os.path.join(coverage_html, 'index.html')])
[email protected]4e622cee2013-09-17 18:32:12546 return coverage_html
[email protected]485fb232013-08-22 19:56:33547
548
[email protected]74050272013-07-02 14:02:15549def LogcatDump(options):
[email protected]e185b7e82013-01-09 03:49:57550 # Print logcat, kill logcat monitor
[email protected]b3873892013-07-10 04:57:10551 bb_annotations.PrintNamedStep('logcat_dump')
[email protected]dc8ec3f2013-09-07 07:18:14552 logcat_file = os.path.join(CHROME_OUT_DIR, options.target, 'full_log')
[email protected]46e095c2013-11-21 13:48:58553 RunCmd([SrcPath('build' , 'android', 'adb_logcat_printer.py'),
554 '--output-path', logcat_file, LOGCAT_DIR])
[email protected]c11a4682014-04-22 23:04:13555 gs_path = MakeGSPath(options, 'chromium-android/logcat_dumps')
556 RunCmd([bb_utils.GSUTIL_PATH, 'cp', logcat_file, 'gs://%s' % gs_path])
557 bb_annotations.PrintLink('logcat dump', '%s/%s' % (GS_URL, gs_path))
[email protected]e185b7e82013-01-09 03:49:57558
[email protected]74050272013-07-02 14:02:15559
[email protected]79d3d8d82014-02-05 13:47:04560def RunStackToolSteps(options):
561 """Run stack tool steps.
562
563 Stack tool is run for logcat dump, optionally for ASAN.
564 """
565 bb_annotations.PrintNamedStep('Run stack tool with logcat dump')
566 logcat_file = os.path.join(CHROME_OUT_DIR, options.target, 'full_log')
567 RunCmd([os.path.join(CHROME_SRC_DIR, 'third_party', 'android_platform',
568 'development', 'scripts', 'stack'),
569 '--more-info', logcat_file])
570 if options.asan_symbolize:
571 bb_annotations.PrintNamedStep('Run stack tool for ASAN')
572 RunCmd([
573 os.path.join(CHROME_SRC_DIR, 'build', 'android', 'asan_symbolize.py'),
574 '-l', logcat_file])
575
576
[email protected]74050272013-07-02 14:02:15577def GenerateTestReport(options):
[email protected]b3873892013-07-10 04:57:10578 bb_annotations.PrintNamedStep('test_report')
[email protected]e185b7e82013-01-09 03:49:57579 for report in glob.glob(
[email protected]dc8ec3f2013-09-07 07:18:14580 os.path.join(CHROME_OUT_DIR, options.target, 'test_logs', '*.log')):
[email protected]78af8712013-01-14 10:37:12581 RunCmd(['cat', report])
[email protected]e185b7e82013-01-09 03:49:57582 os.remove(report)
583
584
[email protected]74050272013-07-02 14:02:15585def MainTestWrapper(options):
[email protected]4cf098c2013-08-02 21:08:06586 try:
587 # Spawn logcat monitor
588 SpawnLogcatMonitor()
[email protected]74050272013-07-02 14:02:15589
[email protected]4cf098c2013-08-02 21:08:06590 # Run all device setup steps
591 for _, cmd in GetDeviceSetupStepCmds():
592 cmd(options)
[email protected]74050272013-07-02 14:02:15593
[email protected]4cf098c2013-08-02 21:08:06594 if options.install:
595 test_obj = INSTRUMENTATION_TESTS[options.install]
596 InstallApk(options, test_obj, print_step=True)
[email protected]74050272013-07-02 14:02:15597
[email protected]4cf098c2013-08-02 21:08:06598 if options.test_filter:
599 bb_utils.RunSteps(options.test_filter, GetTestStepCmds(), options)
[email protected]74050272013-07-02 14:02:15600
[email protected]485fb232013-08-22 19:56:33601 if options.coverage_bucket:
[email protected]4e622cee2013-09-17 18:32:12602 coverage_html = GenerateJavaCoverageReport(options)
603 UploadHTML(options, '%s/java' % options.coverage_bucket, coverage_html,
604 'Coverage Report')
[email protected]ec7b2222014-01-16 02:49:15605 shutil.rmtree(coverage_html, ignore_errors=True)
[email protected]485fb232013-08-22 19:56:33606
[email protected]4cf098c2013-08-02 21:08:06607 if options.experimental:
608 RunTestSuites(options, gtest_config.EXPERIMENTAL_TEST_SUITES)
[email protected]74050272013-07-02 14:02:15609
[email protected]4cf098c2013-08-02 21:08:06610 finally:
611 # Run all post test steps
612 LogcatDump(options)
[email protected]79d3d8d82014-02-05 13:47:04613 if not options.disable_stack_tool:
614 RunStackToolSteps(options)
[email protected]4cf098c2013-08-02 21:08:06615 GenerateTestReport(options)
616 # KillHostHeartbeat() has logic to check if heartbeat process is running,
617 # and kills only if it finds the process is running on the host.
618 provision_devices.KillHostHeartbeat()
[email protected]74050272013-07-02 14:02:15619
620
621def GetDeviceStepsOptParser():
[email protected]c5282752013-06-07 23:14:39622 parser = bb_utils.GetParser()
[email protected]e185b7e82013-01-09 03:49:57623 parser.add_option('--experimental', action='store_true',
624 help='Run experiemental tests')
625 parser.add_option('-f', '--test-filter', metavar='<filter>', default=[],
626 action='append',
627 help=('Run a test suite. Test suites: "%s"' %
628 '", "'.join(VALID_TESTS)))
[email protected]18d59b82013-11-12 09:21:41629 parser.add_option('--gtest-filter',
630 help='Filter for running a subset of tests of a gtest test')
[email protected]e185b7e82013-01-09 03:49:57631 parser.add_option('--asan', action='store_true', help='Run tests with asan.')
632 parser.add_option('--install', metavar='<apk name>',
633 help='Install an apk by name')
[email protected]4a3375d2014-01-08 12:56:50634 parser.add_option('--no-reboot', action='store_true',
635 help='Do not reboot devices during provisioning.')
[email protected]485fb232013-08-22 19:56:33636 parser.add_option('--coverage-bucket',
637 help=('Bucket name to store coverage results. Coverage is '
638 'only run if this is set.'))
[email protected]e5d85a72013-10-19 13:44:02639 parser.add_option('--restart-usb', action='store_true',
640 help='Restart usb ports before device status check.')
[email protected]14f139f42013-07-24 18:41:58641 parser.add_option(
642 '--flakiness-server',
[email protected]f049a192013-10-10 01:11:26643 help=('The flakiness dashboard server to which the results should be '
644 'uploaded.'))
[email protected]12f36c82013-03-29 06:21:13645 parser.add_option(
646 '--auto-reconnect', action='store_true',
647 help='Push script to device which restarts adbd on disconnections.')
[email protected]74050272013-07-02 14:02:15648 parser.add_option(
649 '--logcat-dump-output',
650 help='The logcat dump output will be "tee"-ed into this file')
[email protected]79d3d8d82014-02-05 13:47:04651 parser.add_option('--disable-stack-tool', action='store_true',
652 help='Do not run stack tool.')
653 parser.add_option('--asan-symbolize', action='store_true',
654 help='Run stack tool for ASAN')
[email protected]74050272013-07-02 14:02:15655 return parser
656
657
658def main(argv):
659 parser = GetDeviceStepsOptParser()
[email protected]e185b7e82013-01-09 03:49:57660 options, args = parser.parse_args(argv[1:])
661
[email protected]e185b7e82013-01-09 03:49:57662 if args:
[email protected]c5282752013-06-07 23:14:39663 return sys.exit('Unused args %s' % args)
[email protected]e185b7e82013-01-09 03:49:57664
665 unknown_tests = set(options.test_filter) - VALID_TESTS
666 if unknown_tests:
[email protected]c5282752013-06-07 23:14:39667 return sys.exit('Unknown tests %s' % list(unknown_tests))
[email protected]e185b7e82013-01-09 03:49:57668
669 setattr(options, 'target', options.factory_properties.get('target', 'Debug'))
[email protected]485fb232013-08-22 19:56:33670 if options.coverage_bucket:
671 setattr(options, 'coverage_dir',
[email protected]dc8ec3f2013-09-07 07:18:14672 os.path.join(CHROME_OUT_DIR, options.target, 'coverage'))
[email protected]e185b7e82013-01-09 03:49:57673
[email protected]e185b7e82013-01-09 03:49:57674 MainTestWrapper(options)
[email protected]e185b7e82013-01-09 03:49:57675
676
677if __name__ == '__main__':
678 sys.exit(main(sys.argv))