blob: 3aae66c93fa67a1fa91e7d93dac2e6fa6bdbd20a [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]78af8712013-01-14 10:37:129import multiprocessing
[email protected]e185b7e82013-01-09 03:49:5710import os
[email protected]485fb232013-08-22 19:56:3311import random
[email protected]e185b7e82013-01-09 03:49:5712import shutil
[email protected]e185b7e82013-01-09 03:49:5713import sys
14
[email protected]c5282752013-06-07 23:14:3915import bb_utils
[email protected]b3873892013-07-10 04:57:1016import bb_annotations
[email protected]c5282752013-06-07 23:14:3917
[email protected]e185b7e82013-01-09 03:49:5718sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
[email protected]7849a332013-07-12 01:40:0919import provision_devices
[email protected]78af8712013-01-14 10:37:1220from pylib import android_commands
[email protected]e185b7e82013-01-09 03:49:5721from pylib import constants
[email protected]a8fea93f2013-01-10 04:00:0722from pylib.gtest import gtest_config
[email protected]e185b7e82013-01-09 03:49:5723
[email protected]dc8ec3f2013-09-07 07:18:1424CHROME_SRC_DIR = bb_utils.CHROME_SRC
25CHROME_OUT_DIR = bb_utils.CHROME_OUT_DIR
[email protected]78af8712013-01-14 10:37:1226sys.path.append(os.path.join(
[email protected]dc8ec3f2013-09-07 07:18:1427 CHROME_SRC_DIR, 'third_party', 'android_testrunner'))
[email protected]78af8712013-01-14 10:37:1228import errors
29
[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]e185b7e82013-01-09 03:49:5734
35# Describes an instrumation test suite:
36# test: Name of test we're running.
37# apk: apk to be installed.
38# apk_package: package for the apk to be installed.
39# test_apk: apk to run tests on.
40# test_data: data folder in format destination:source.
[email protected]37ee0c792013-08-06 19:10:1341# host_driven_root: The host-driven test root directory.
[email protected]74050272013-07-02 14:02:1542# annotation: Annotation of the tests to include.
43# exclude_annotation: The annotation of the tests to exclude.
[email protected]e185b7e82013-01-09 03:49:5744I_TEST = collections.namedtuple('InstrumentationTest', [
[email protected]74050272013-07-02 14:02:1545 'name', 'apk', 'apk_package', 'test_apk', 'test_data', 'host_driven_root',
46 'annotation', 'exclude_annotation', 'extra_flags'])
47
48def I(name, apk, apk_package, test_apk, test_data, host_driven_root=None,
49 annotation=None, exclude_annotation=None, extra_flags=None):
50 return I_TEST(name, apk, apk_package, test_apk, test_data, host_driven_root,
51 annotation, exclude_annotation, extra_flags)
[email protected]e185b7e82013-01-09 03:49:5752
53INSTRUMENTATION_TESTS = dict((suite.name, suite) for suite in [
[email protected]74050272013-07-02 14:02:1554 I('ContentShell',
55 'ContentShell.apk',
56 'org.chromium.content_shell_apk',
57 'ContentShellTest',
58 'content:content/test/data/android/device_files'),
59 I('ChromiumTestShell',
60 'ChromiumTestShell.apk',
61 'org.chromium.chrome.testshell',
62 'ChromiumTestShellTest',
63 'chrome:chrome/test/data/android/device_files',
64 constants.CHROMIUM_TEST_SHELL_HOST_DRIVEN_DIR),
65 I('AndroidWebView',
66 'AndroidWebView.apk',
67 'org.chromium.android_webview.shell',
68 'AndroidWebViewTest',
69 'webview:android_webview/test/data/device_files'),
[email protected]e185b7e82013-01-09 03:49:5770 ])
71
[email protected]bb508f82013-09-06 06:42:2472VALID_TESTS = set(['chromedriver', 'gpu', 'ui', 'unit', 'webkit',
73 'webkit_layout', 'webrtc'])
[email protected]e185b7e82013-01-09 03:49:5774
[email protected]c5282752013-06-07 23:14:3975RunCmd = bb_utils.RunCmd
[email protected]e185b7e82013-01-09 03:49:5776
77
[email protected]78af8712013-01-14 10:37:1278# multiprocessing map_async requires a top-level function for pickle library.
79def RebootDeviceSafe(device):
80 """Reboot a device, wait for it to start, and squelch timeout exceptions."""
81 try:
82 android_commands.AndroidCommands(device).Reboot(True)
83 except errors.DeviceUnresponsiveError as e:
84 return e
85
86
87def RebootDevices():
88 """Reboot all attached and online devices."""
[email protected]c94ae6b2013-01-14 21:38:3489 # Early return here to avoid presubmit dependence on adb,
90 # which might not exist in this checkout.
[email protected]c5282752013-06-07 23:14:3991 if bb_utils.TESTING:
[email protected]c94ae6b2013-01-14 21:38:3492 return
[email protected]30bd2912013-07-20 06:18:1193 devices = android_commands.GetAttachedDevices(emulator=False)
[email protected]78af8712013-01-14 10:37:1294 print 'Rebooting: %s' % devices
[email protected]c94ae6b2013-01-14 21:38:3495 if devices:
[email protected]78af8712013-01-14 10:37:1296 pool = multiprocessing.Pool(len(devices))
97 results = pool.map_async(RebootDeviceSafe, devices).get(99999)
98
99 for device, result in zip(devices, results):
100 if result:
101 print '%s failed to startup.' % device
102
103 if any(results):
[email protected]b3873892013-07-10 04:57:10104 bb_annotations.PrintWarning()
[email protected]78af8712013-01-14 10:37:12105 else:
106 print 'Reboots complete.'
107
108
[email protected]a8fea93f2013-01-10 04:00:07109def RunTestSuites(options, suites):
[email protected]fbe29322013-07-09 09:03:26110 """Manages an invocation of test_runner.py for gtests.
[email protected]e185b7e82013-01-09 03:49:57111
112 Args:
113 options: options object.
[email protected]9e689252013-07-30 20:14:36114 suites: List of suite names to run.
[email protected]e185b7e82013-01-09 03:49:57115 """
116 args = ['--verbose']
[email protected]e185b7e82013-01-09 03:49:57117 if options.target == 'Release':
118 args.append('--release')
119 if options.asan:
120 args.append('--tool=asan')
[email protected]a8fea93f2013-01-10 04:00:07121 for suite in suites:
[email protected]9e689252013-07-30 20:14:36122 bb_annotations.PrintNamedStep(suite)
123 cmd = ['build/android/test_runner.py', 'gtest', '-s', suite] + args
124 if suite == 'content_browsertests':
125 cmd.append('--num_retries=1')
[email protected]9324bff2013-03-13 04:09:27126 RunCmd(cmd)
[email protected]e185b7e82013-01-09 03:49:57127
[email protected]74050272013-07-02 14:02:15128def RunChromeDriverTests(_):
[email protected]d8897f6c2013-03-05 00:27:16129 """Run all the steps for running chromedriver tests."""
[email protected]b3873892013-07-10 04:57:10130 bb_annotations.PrintNamedStep('chromedriver_annotation')
[email protected]d8897f6c2013-03-05 00:27:16131 RunCmd(['chrome/test/chromedriver/run_buildbot_steps.py',
[email protected]eb9f5a32013-08-22 19:46:02132 '--android-packages=%s,%s,%s' %
133 (constants.CHROMIUM_TEST_SHELL_PACKAGE,
134 constants.CHROME_STABLE_PACKAGE,
135 constants.CHROME_BETA_PACKAGE)])
[email protected]d8897f6c2013-03-05 00:27:16136
[email protected]a2a725242013-01-09 21:52:57137def InstallApk(options, test, print_step=False):
138 """Install an apk to all phones.
139
140 Args:
141 options: options object
142 test: An I_TEST namedtuple
143 print_step: Print a buildbot step
144 """
145 if print_step:
[email protected]b3873892013-07-10 04:57:10146 bb_annotations.PrintNamedStep('install_%s' % test.name.lower())
[email protected]6ca57512013-08-23 21:42:04147 # TODO(gkanwar): Quick hack to make sure AndroidWebViewTest.apk is replaced
148 # before AndroidWebView.apk is. This can be removed once the bots cycle.
149 args = ['--apk', '%s.apk' % test.test_apk]
150 if options.target == 'Release':
151 args.append('--release')
152
153 RunCmd(['build/android/adb_install_apk.py'] + args, halt_on_failure=True)
154
[email protected]a2a725242013-01-09 21:52:57155 args = ['--apk', test.apk, '--apk_package', test.apk_package]
156 if options.target == 'Release':
[email protected]e185b7e82013-01-09 03:49:57157 args.append('--release')
158
[email protected]800673bf2013-05-14 17:15:30159 RunCmd(['build/android/adb_install_apk.py'] + args, halt_on_failure=True)
[email protected]e185b7e82013-01-09 03:49:57160
161
[email protected]acfaf4c2013-07-25 00:23:56162def RunInstrumentationSuite(options, test, flunk_on_failure=True,
[email protected]54c2d532013-08-24 01:36:24163 python_only=False, official_build=False):
[email protected]fbe29322013-07-09 09:03:26164 """Manages an invocation of test_runner.py for instrumentation tests.
[email protected]e185b7e82013-01-09 03:49:57165
166 Args:
167 options: options object
168 test: An I_TEST namedtuple
[email protected]acfaf4c2013-07-25 00:23:56169 flunk_on_failure: Flunk the step if tests fail.
170 Python: Run only host driven Python tests.
[email protected]54c2d532013-08-24 01:36:24171 official_build: Run official-build tests.
[email protected]e185b7e82013-01-09 03:49:57172 """
[email protected]b3873892013-07-10 04:57:10173 bb_annotations.PrintNamedStep('%s_instrumentation_tests' % test.name.lower())
[email protected]e185b7e82013-01-09 03:49:57174
[email protected]a2a725242013-01-09 21:52:57175 InstallApk(options, test)
[email protected]d1a0657c2013-04-10 22:38:59176 args = ['--test-apk', test.test_apk, '--test_data', test.test_data,
[email protected]fb7ab5e82013-07-26 18:31:20177 '--verbose']
[email protected]e185b7e82013-01-09 03:49:57178 if options.target == 'Release':
179 args.append('--release')
180 if options.asan:
181 args.append('--tool=asan')
[email protected]14f139f42013-07-24 18:41:58182 if options.flakiness_server:
[email protected]b796a772013-01-19 03:55:22183 args.append('--flakiness-dashboard-server=%s' %
[email protected]14f139f42013-07-24 18:41:58184 options.flakiness_server)
[email protected]485fb232013-08-22 19:56:33185 if options.coverage_bucket:
186 args.append('--coverage-dir=%s' % options.coverage_dir)
[email protected]8d8ca042013-02-14 19:29:17187 if test.host_driven_root:
[email protected]67954f822013-08-14 18:09:08188 args.append('--host-driven-root=%s' % test.host_driven_root)
[email protected]74050272013-07-02 14:02:15189 if test.annotation:
190 args.extend(['-A', test.annotation])
191 if test.exclude_annotation:
192 args.extend(['-E', test.exclude_annotation])
193 if test.extra_flags:
194 args.extend(test.extra_flags)
[email protected]acfaf4c2013-07-25 00:23:56195 if python_only:
196 args.append('-p')
[email protected]54c2d532013-08-24 01:36:24197 if official_build:
198 # The option needs to be assigned 'True' as it does not have an action
199 # associated with it.
200 args.append('--official-build')
[email protected]e185b7e82013-01-09 03:49:57201
[email protected]bdd22ff2013-07-17 17:21:12202 RunCmd(['build/android/test_runner.py', 'instrumentation'] + args,
203 flunk_on_failure=flunk_on_failure)
[email protected]e185b7e82013-01-09 03:49:57204
205
206def RunWebkitLint(target):
207 """Lint WebKit's TestExpectation files."""
[email protected]b3873892013-07-10 04:57:10208 bb_annotations.PrintNamedStep('webkit_lint')
[email protected]e185b7e82013-01-09 03:49:57209 RunCmd(['webkit/tools/layout_tests/run_webkit_tests.py',
210 '--lint-test-files',
211 '--chromium',
212 '--target', target])
213
214
215def RunWebkitLayoutTests(options):
216 """Run layout tests on an actual device."""
[email protected]b3873892013-07-10 04:57:10217 bb_annotations.PrintNamedStep('webkit_tests')
[email protected]22ee7002013-01-23 20:58:04218 cmd_args = [
219 '--no-show-results',
220 '--no-new-test-results',
221 '--full-results-html',
222 '--clobber-old-results',
223 '--exit-after-n-failures', '5000',
224 '--exit-after-n-crashes-or-timeouts', '100',
225 '--debug-rwt-logging',
[email protected]dc8ec3f2013-09-07 07:18:14226 '--results-directory', '../layout-test-results',
[email protected]22ee7002013-01-23 20:58:04227 '--target', options.target,
228 '--builder-name', options.build_properties.get('buildername', ''),
[email protected]0b793d62013-05-20 22:00:39229 '--build-number', str(options.build_properties.get('buildnumber', '')),
[email protected]22ee7002013-01-23 20:58:04230 '--master-name', options.build_properties.get('mastername', ''),
231 '--build-name', options.build_properties.get('buildername', ''),
[email protected]a1c7d2e2013-07-15 14:55:13232 '--platform=android']
[email protected]22ee7002013-01-23 20:58:04233
234 for flag in 'test_results_server', 'driver_name', 'additional_drt_flag':
235 if flag in options.factory_properties:
236 cmd_args.extend(['--%s' % flag.replace('_', '-'),
237 options.factory_properties.get(flag)])
238
[email protected]2c39b292013-03-20 09:34:10239 for f in options.factory_properties.get('additional_expectations', []):
240 cmd_args.extend(
[email protected]dc8ec3f2013-09-07 07:18:14241 ['--additional-expectations=%s' % os.path.join(CHROME_SRC_DIR, *f)])
[email protected]2c39b292013-03-20 09:34:10242
243 # TODO(dpranke): Remove this block after
244 # https://codereview.chromium.org/12927002/ lands.
[email protected]22ee7002013-01-23 20:58:04245 for f in options.factory_properties.get('additional_expectations_files', []):
[email protected]62c5b982013-01-26 08:23:16246 cmd_args.extend(
[email protected]dc8ec3f2013-09-07 07:18:14247 ['--additional-expectations=%s' % os.path.join(CHROME_SRC_DIR, *f)])
[email protected]22ee7002013-01-23 20:58:04248
[email protected]f9e7ddb2013-08-20 14:36:59249 RunCmd(['webkit/tools/layout_tests/run_webkit_tests.py'] + cmd_args)
[email protected]e185b7e82013-01-09 03:49:57250
[email protected]dc8ec3f2013-09-07 07:18:14251 if options.factory_properties.get('archive_webkit_results', False):
252 bb_annotations.PrintNamedStep('archive_webkit_results')
[email protected]85db7daf32013-09-09 21:21:25253 gs_bucket = 'gs://chromium-layout-test-archives'
[email protected]dc8ec3f2013-09-07 07:18:14254 RunCmd([os.path.join(SLAVE_SCRIPTS_DIR, 'chromium',
255 'archive_layout_test_results.py'),
[email protected]dbb41dc2013-09-09 22:25:52256 '--results-dir', '../../layout-test-results',
[email protected]dc8ec3f2013-09-07 07:18:14257 '--build-dir', CHROME_OUT_DIR,
258 '--build-number', str(options.build_properties.get('buildnumber', '')),
259 '--builder-name', options.build_properties.get('buildername', ''),
260 '--gs-bucket', gs_bucket])
261
[email protected]e185b7e82013-01-09 03:49:57262
[email protected]74050272013-07-02 14:02:15263def SpawnLogcatMonitor():
264 shutil.rmtree(LOGCAT_DIR, ignore_errors=True)
265 bb_utils.SpawnCmd([
[email protected]dc8ec3f2013-09-07 07:18:14266 os.path.join(CHROME_SRC_DIR, 'build', 'android', 'adb_logcat_monitor.py'),
[email protected]74050272013-07-02 14:02:15267 LOGCAT_DIR])
268
269 # Wait for logcat_monitor to pull existing logcat
270 RunCmd(['sleep', '5'])
271
272def ProvisionDevices(options):
[email protected]b3873892013-07-10 04:57:10273 bb_annotations.PrintNamedStep('provision_devices')
[email protected]abfec372013-08-16 07:22:16274
275 if not bb_utils.TESTING:
276 # Restart adb to work around bugs, sleep to wait for usb discovery.
277 adb = android_commands.AndroidCommands()
278 adb.RestartAdbServer()
279 RunCmd(['sleep', '1'])
280
[email protected]78af8712013-01-14 10:37:12281 if options.reboot:
282 RebootDevices()
[email protected]7849a332013-07-12 01:40:09283 provision_cmd = ['build/android/provision_devices.py', '-t', options.target]
284 if options.auto_reconnect:
285 provision_cmd.append('--auto-reconnect')
286 RunCmd(provision_cmd)
[email protected]78af8712013-01-14 10:37:12287
[email protected]74050272013-07-02 14:02:15288
289def DeviceStatusCheck(_):
[email protected]b3873892013-07-10 04:57:10290 bb_annotations.PrintNamedStep('device_status_check')
[email protected]37a6a382013-07-17 02:37:07291 RunCmd(['build/android/buildbot/bb_device_status_check.py'],
292 halt_on_failure=True)
[email protected]693c54d2013-01-09 19:41:25293
[email protected]e185b7e82013-01-09 03:49:57294
[email protected]74050272013-07-02 14:02:15295def GetDeviceSetupStepCmds():
296 return [
297 ('provision_devices', ProvisionDevices),
[email protected]0ff5fca2013-08-26 19:54:15298 ('device_status_check', DeviceStatusCheck),
[email protected]74050272013-07-02 14:02:15299 ]
[email protected]e185b7e82013-01-09 03:49:57300
[email protected]e185b7e82013-01-09 03:49:57301
[email protected]74050272013-07-02 14:02:15302def RunUnitTests(options):
303 RunTestSuites(options, gtest_config.STABLE_TEST_SUITES)
304
305
306def RunInstrumentationTests(options):
307 for test in INSTRUMENTATION_TESTS.itervalues():
308 RunInstrumentationSuite(options, test)
309
310
311def RunWebkitTests(options):
[email protected]9e689252013-07-30 20:14:36312 RunTestSuites(options, ['webkit_unit_tests'])
[email protected]74050272013-07-02 14:02:15313 RunWebkitLint(options.target)
314
315
[email protected]02bfada2013-08-12 05:00:52316def RunWebRTCTests(options):
317 RunTestSuites(options, gtest_config.WEBRTC_TEST_SUITES)
318
319
[email protected]a4b1ec972013-09-14 05:36:25320def RunGPUTests(options):
321 InstallApk(options, INSTRUMENTATION_TESTS['ContentShell'], False)
[email protected]bb508f82013-09-06 06:42:24322 bb_annotations.PrintNamedStep('gpu_tests')
323 RunCmd(['content/test/gpu/run_gpu_test',
324 '--browser=android-content-shell', 'pixel'])
325
326
[email protected]74050272013-07-02 14:02:15327def GetTestStepCmds():
328 return [
329 ('chromedriver', RunChromeDriverTests),
[email protected]bb508f82013-09-06 06:42:24330 ('gpu', RunGPUTests),
[email protected]74050272013-07-02 14:02:15331 ('unit', RunUnitTests),
332 ('ui', RunInstrumentationTests),
333 ('webkit', RunWebkitTests),
[email protected]02bfada2013-08-12 05:00:52334 ('webkit_layout', RunWebkitLayoutTests),
335 ('webrtc', RunWebRTCTests),
[email protected]74050272013-07-02 14:02:15336 ]
337
338
[email protected]4e622cee2013-09-17 18:32:12339def UploadHTML(options, gs_base_dir, dir_to_upload, link_text,
340 link_rel_path='index.html', gs_url=GS_URL):
341 """Uploads directory at |dir_to_upload| to Google Storage and output a link.
[email protected]485fb232013-08-22 19:56:33342
343 Args:
344 options: Command line options.
[email protected]4e622cee2013-09-17 18:32:12345 gs_base_dir: The Google Storage base directory (e.g.
346 'chromium-code-coverage/java')
347 dir_to_upload: Absolute path to the directory to be uploaded.
348 link_text: Link text to be displayed on the step.
349 link_rel_path: Link path relative to |dir_to_upload|.
350 gs_url: Google storage URL.
[email protected]485fb232013-08-22 19:56:33351 """
[email protected]e6a5eee2013-08-23 05:27:08352 revision = options.build_properties.get('got_revision')
353 if not revision:
354 revision = options.build_properties.get('revision', 'testing')
[email protected]485fb232013-08-22 19:56:33355 bot_id = options.build_properties.get('buildername', 'testing')
356 randhash = hashlib.sha1(str(random.random())).hexdigest()
[email protected]4e622cee2013-09-17 18:32:12357 gs_path = '%s/%s/%s/%s' % (gs_base_dir, bot_id, revision, randhash)
358 RunCmd([bb_utils.GSUTIL_PATH, 'cp', '-R', dir_to_upload, 'gs://%s' % gs_path])
359 bb_annotations.PrintLink(link_text,
360 '%s/%s/%s' % (gs_url, gs_path, link_rel_path))
[email protected]485fb232013-08-22 19:56:33361
362
363def GenerateJavaCoverageReport(options):
364 """Generates an HTML coverage report using EMMA and uploads it."""
365 bb_annotations.PrintNamedStep('java_coverage_report')
366
367 coverage_html = os.path.join(options.coverage_dir, 'coverage_html')
368 RunCmd(['build/android/generate_emma_html.py',
369 '--coverage-dir', options.coverage_dir,
[email protected]dc8ec3f2013-09-07 07:18:14370 '--metadata-dir', os.path.join(CHROME_OUT_DIR, options.target),
[email protected]a1f1abfe2013-08-27 22:02:43371 '--cleanup',
[email protected]485fb232013-08-22 19:56:33372 '--output', os.path.join(coverage_html, 'index.html')])
[email protected]4e622cee2013-09-17 18:32:12373 return coverage_html
[email protected]485fb232013-08-22 19:56:33374
375
[email protected]74050272013-07-02 14:02:15376def LogcatDump(options):
[email protected]e185b7e82013-01-09 03:49:57377 # Print logcat, kill logcat monitor
[email protected]b3873892013-07-10 04:57:10378 bb_annotations.PrintNamedStep('logcat_dump')
[email protected]dc8ec3f2013-09-07 07:18:14379 logcat_file = os.path.join(CHROME_OUT_DIR, options.target, 'full_log')
[email protected]74050272013-07-02 14:02:15380 with open(logcat_file, 'w') as f:
381 RunCmd([
[email protected]dc8ec3f2013-09-07 07:18:14382 os.path.join(CHROME_SRC_DIR, 'build', 'android',
383 'adb_logcat_printer.py'),
[email protected]74050272013-07-02 14:02:15384 LOGCAT_DIR], stdout=f)
385 RunCmd(['cat', logcat_file])
[email protected]e185b7e82013-01-09 03:49:57386
[email protected]74050272013-07-02 14:02:15387
388def GenerateTestReport(options):
[email protected]b3873892013-07-10 04:57:10389 bb_annotations.PrintNamedStep('test_report')
[email protected]e185b7e82013-01-09 03:49:57390 for report in glob.glob(
[email protected]dc8ec3f2013-09-07 07:18:14391 os.path.join(CHROME_OUT_DIR, options.target, 'test_logs', '*.log')):
[email protected]78af8712013-01-14 10:37:12392 RunCmd(['cat', report])
[email protected]e185b7e82013-01-09 03:49:57393 os.remove(report)
394
395
[email protected]74050272013-07-02 14:02:15396def MainTestWrapper(options):
[email protected]4cf098c2013-08-02 21:08:06397 try:
398 # Spawn logcat monitor
399 SpawnLogcatMonitor()
[email protected]74050272013-07-02 14:02:15400
[email protected]4cf098c2013-08-02 21:08:06401 # Run all device setup steps
402 for _, cmd in GetDeviceSetupStepCmds():
403 cmd(options)
[email protected]74050272013-07-02 14:02:15404
[email protected]4cf098c2013-08-02 21:08:06405 if options.install:
406 test_obj = INSTRUMENTATION_TESTS[options.install]
407 InstallApk(options, test_obj, print_step=True)
[email protected]74050272013-07-02 14:02:15408
[email protected]4cf098c2013-08-02 21:08:06409 if options.test_filter:
410 bb_utils.RunSteps(options.test_filter, GetTestStepCmds(), options)
[email protected]74050272013-07-02 14:02:15411
[email protected]485fb232013-08-22 19:56:33412 if options.coverage_bucket:
[email protected]4e622cee2013-09-17 18:32:12413 coverage_html = GenerateJavaCoverageReport(options)
414 UploadHTML(options, '%s/java' % options.coverage_bucket, coverage_html,
415 'Coverage Report')
[email protected]485fb232013-08-22 19:56:33416
[email protected]4cf098c2013-08-02 21:08:06417 if options.experimental:
418 RunTestSuites(options, gtest_config.EXPERIMENTAL_TEST_SUITES)
[email protected]74050272013-07-02 14:02:15419
[email protected]4cf098c2013-08-02 21:08:06420 finally:
421 # Run all post test steps
422 LogcatDump(options)
423 GenerateTestReport(options)
424 # KillHostHeartbeat() has logic to check if heartbeat process is running,
425 # and kills only if it finds the process is running on the host.
426 provision_devices.KillHostHeartbeat()
[email protected]74050272013-07-02 14:02:15427
428
429def GetDeviceStepsOptParser():
[email protected]c5282752013-06-07 23:14:39430 parser = bb_utils.GetParser()
[email protected]e185b7e82013-01-09 03:49:57431 parser.add_option('--experimental', action='store_true',
432 help='Run experiemental tests')
433 parser.add_option('-f', '--test-filter', metavar='<filter>', default=[],
434 action='append',
435 help=('Run a test suite. Test suites: "%s"' %
436 '", "'.join(VALID_TESTS)))
437 parser.add_option('--asan', action='store_true', help='Run tests with asan.')
438 parser.add_option('--install', metavar='<apk name>',
439 help='Install an apk by name')
[email protected]78af8712013-01-14 10:37:12440 parser.add_option('--reboot', action='store_true',
441 help='Reboot devices before running tests')
[email protected]485fb232013-08-22 19:56:33442 parser.add_option('--coverage-bucket',
443 help=('Bucket name to store coverage results. Coverage is '
444 'only run if this is set.'))
[email protected]14f139f42013-07-24 18:41:58445 parser.add_option(
446 '--flakiness-server',
447 help='The flakiness dashboard server to which the results should be '
448 'uploaded.')
[email protected]12f36c82013-03-29 06:21:13449 parser.add_option(
450 '--auto-reconnect', action='store_true',
451 help='Push script to device which restarts adbd on disconnections.')
[email protected]74050272013-07-02 14:02:15452 parser.add_option(
453 '--logcat-dump-output',
454 help='The logcat dump output will be "tee"-ed into this file')
455
456 return parser
457
458
459def main(argv):
460 parser = GetDeviceStepsOptParser()
[email protected]e185b7e82013-01-09 03:49:57461 options, args = parser.parse_args(argv[1:])
462
[email protected]e185b7e82013-01-09 03:49:57463 if args:
[email protected]c5282752013-06-07 23:14:39464 return sys.exit('Unused args %s' % args)
[email protected]e185b7e82013-01-09 03:49:57465
466 unknown_tests = set(options.test_filter) - VALID_TESTS
467 if unknown_tests:
[email protected]c5282752013-06-07 23:14:39468 return sys.exit('Unknown tests %s' % list(unknown_tests))
[email protected]e185b7e82013-01-09 03:49:57469
470 setattr(options, 'target', options.factory_properties.get('target', 'Debug'))
[email protected]485fb232013-08-22 19:56:33471 if options.coverage_bucket:
472 setattr(options, 'coverage_dir',
[email protected]dc8ec3f2013-09-07 07:18:14473 os.path.join(CHROME_OUT_DIR, options.target, 'coverage'))
[email protected]e185b7e82013-01-09 03:49:57474
[email protected]e185b7e82013-01-09 03:49:57475 MainTestWrapper(options)
[email protected]e185b7e82013-01-09 03:49:57476
477
478if __name__ == '__main__':
479 sys.exit(main(sys.argv))