[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 1 | #!/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 | |
| 6 | import collections |
| 7 | import glob |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 8 | import hashlib |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 9 | import multiprocessing |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 10 | import os |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 11 | import random |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 12 | import shutil |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 13 | import sys |
| 14 | |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 15 | import bb_utils |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 16 | import bb_annotations |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 17 | |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 18 | sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
[email protected] | 7849a33 | 2013-07-12 01:40:09 | [diff] [blame] | 19 | import provision_devices |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 20 | from pylib import android_commands |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 21 | from pylib import constants |
[email protected] | a8fea93f | 2013-01-10 04:00:07 | [diff] [blame] | 22 | from pylib.gtest import gtest_config |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 23 | |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 24 | CHROME_SRC_DIR = bb_utils.CHROME_SRC |
| 25 | CHROME_OUT_DIR = bb_utils.CHROME_OUT_DIR |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 26 | sys.path.append(os.path.join( |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 27 | CHROME_SRC_DIR, 'third_party', 'android_testrunner')) |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 28 | import errors |
| 29 | |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 30 | |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 31 | SLAVE_SCRIPTS_DIR = os.path.join(bb_utils.BB_BUILD_DIR, 'scripts', 'slave') |
| 32 | LOGCAT_DIR = os.path.join(bb_utils.CHROME_OUT_DIR, 'logcat') |
[email protected] | 4e622cee | 2013-09-17 18:32:12 | [diff] [blame^] | 33 | GS_URL = 'https://storage.googleapis.com' |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 34 | |
| 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] | 37ee0c79 | 2013-08-06 19:10:13 | [diff] [blame] | 41 | # host_driven_root: The host-driven test root directory. |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 42 | # annotation: Annotation of the tests to include. |
| 43 | # exclude_annotation: The annotation of the tests to exclude. |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 44 | I_TEST = collections.namedtuple('InstrumentationTest', [ |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 45 | 'name', 'apk', 'apk_package', 'test_apk', 'test_data', 'host_driven_root', |
| 46 | 'annotation', 'exclude_annotation', 'extra_flags']) |
| 47 | |
| 48 | def 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] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 52 | |
| 53 | INSTRUMENTATION_TESTS = dict((suite.name, suite) for suite in [ |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 54 | 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] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 70 | ]) |
| 71 | |
[email protected] | bb508f8 | 2013-09-06 06:42:24 | [diff] [blame] | 72 | VALID_TESTS = set(['chromedriver', 'gpu', 'ui', 'unit', 'webkit', |
| 73 | 'webkit_layout', 'webrtc']) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 74 | |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 75 | RunCmd = bb_utils.RunCmd |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 76 | |
| 77 | |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 78 | # multiprocessing map_async requires a top-level function for pickle library. |
| 79 | def 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 | |
| 87 | def RebootDevices(): |
| 88 | """Reboot all attached and online devices.""" |
[email protected] | c94ae6b | 2013-01-14 21:38:34 | [diff] [blame] | 89 | # Early return here to avoid presubmit dependence on adb, |
| 90 | # which might not exist in this checkout. |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 91 | if bb_utils.TESTING: |
[email protected] | c94ae6b | 2013-01-14 21:38:34 | [diff] [blame] | 92 | return |
[email protected] | 30bd291 | 2013-07-20 06:18:11 | [diff] [blame] | 93 | devices = android_commands.GetAttachedDevices(emulator=False) |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 94 | print 'Rebooting: %s' % devices |
[email protected] | c94ae6b | 2013-01-14 21:38:34 | [diff] [blame] | 95 | if devices: |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 96 | 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] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 104 | bb_annotations.PrintWarning() |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 105 | else: |
| 106 | print 'Reboots complete.' |
| 107 | |
| 108 | |
[email protected] | a8fea93f | 2013-01-10 04:00:07 | [diff] [blame] | 109 | def RunTestSuites(options, suites): |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 110 | """Manages an invocation of test_runner.py for gtests. |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 111 | |
| 112 | Args: |
| 113 | options: options object. |
[email protected] | 9e68925 | 2013-07-30 20:14:36 | [diff] [blame] | 114 | suites: List of suite names to run. |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 115 | """ |
| 116 | args = ['--verbose'] |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 117 | if options.target == 'Release': |
| 118 | args.append('--release') |
| 119 | if options.asan: |
| 120 | args.append('--tool=asan') |
[email protected] | a8fea93f | 2013-01-10 04:00:07 | [diff] [blame] | 121 | for suite in suites: |
[email protected] | 9e68925 | 2013-07-30 20:14:36 | [diff] [blame] | 122 | 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] | 9324bff | 2013-03-13 04:09:27 | [diff] [blame] | 126 | RunCmd(cmd) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 127 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 128 | def RunChromeDriverTests(_): |
[email protected] | d8897f6c | 2013-03-05 00:27:16 | [diff] [blame] | 129 | """Run all the steps for running chromedriver tests.""" |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 130 | bb_annotations.PrintNamedStep('chromedriver_annotation') |
[email protected] | d8897f6c | 2013-03-05 00:27:16 | [diff] [blame] | 131 | RunCmd(['chrome/test/chromedriver/run_buildbot_steps.py', |
[email protected] | eb9f5a3 | 2013-08-22 19:46:02 | [diff] [blame] | 132 | '--android-packages=%s,%s,%s' % |
| 133 | (constants.CHROMIUM_TEST_SHELL_PACKAGE, |
| 134 | constants.CHROME_STABLE_PACKAGE, |
| 135 | constants.CHROME_BETA_PACKAGE)]) |
[email protected] | d8897f6c | 2013-03-05 00:27:16 | [diff] [blame] | 136 | |
[email protected] | a2a72524 | 2013-01-09 21:52:57 | [diff] [blame] | 137 | def 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] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 146 | bb_annotations.PrintNamedStep('install_%s' % test.name.lower()) |
[email protected] | 6ca5751 | 2013-08-23 21:42:04 | [diff] [blame] | 147 | # 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] | a2a72524 | 2013-01-09 21:52:57 | [diff] [blame] | 155 | args = ['--apk', test.apk, '--apk_package', test.apk_package] |
| 156 | if options.target == 'Release': |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 157 | args.append('--release') |
| 158 | |
[email protected] | 800673bf | 2013-05-14 17:15:30 | [diff] [blame] | 159 | RunCmd(['build/android/adb_install_apk.py'] + args, halt_on_failure=True) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 160 | |
| 161 | |
[email protected] | acfaf4c | 2013-07-25 00:23:56 | [diff] [blame] | 162 | def RunInstrumentationSuite(options, test, flunk_on_failure=True, |
[email protected] | 54c2d53 | 2013-08-24 01:36:24 | [diff] [blame] | 163 | python_only=False, official_build=False): |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 164 | """Manages an invocation of test_runner.py for instrumentation tests. |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 165 | |
| 166 | Args: |
| 167 | options: options object |
| 168 | test: An I_TEST namedtuple |
[email protected] | acfaf4c | 2013-07-25 00:23:56 | [diff] [blame] | 169 | flunk_on_failure: Flunk the step if tests fail. |
| 170 | Python: Run only host driven Python tests. |
[email protected] | 54c2d53 | 2013-08-24 01:36:24 | [diff] [blame] | 171 | official_build: Run official-build tests. |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 172 | """ |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 173 | bb_annotations.PrintNamedStep('%s_instrumentation_tests' % test.name.lower()) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 174 | |
[email protected] | a2a72524 | 2013-01-09 21:52:57 | [diff] [blame] | 175 | InstallApk(options, test) |
[email protected] | d1a0657c | 2013-04-10 22:38:59 | [diff] [blame] | 176 | args = ['--test-apk', test.test_apk, '--test_data', test.test_data, |
[email protected] | fb7ab5e8 | 2013-07-26 18:31:20 | [diff] [blame] | 177 | '--verbose'] |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 178 | if options.target == 'Release': |
| 179 | args.append('--release') |
| 180 | if options.asan: |
| 181 | args.append('--tool=asan') |
[email protected] | 14f139f4 | 2013-07-24 18:41:58 | [diff] [blame] | 182 | if options.flakiness_server: |
[email protected] | b796a77 | 2013-01-19 03:55:22 | [diff] [blame] | 183 | args.append('--flakiness-dashboard-server=%s' % |
[email protected] | 14f139f4 | 2013-07-24 18:41:58 | [diff] [blame] | 184 | options.flakiness_server) |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 185 | if options.coverage_bucket: |
| 186 | args.append('--coverage-dir=%s' % options.coverage_dir) |
[email protected] | 8d8ca04 | 2013-02-14 19:29:17 | [diff] [blame] | 187 | if test.host_driven_root: |
[email protected] | 67954f82 | 2013-08-14 18:09:08 | [diff] [blame] | 188 | args.append('--host-driven-root=%s' % test.host_driven_root) |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 189 | 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] | acfaf4c | 2013-07-25 00:23:56 | [diff] [blame] | 195 | if python_only: |
| 196 | args.append('-p') |
[email protected] | 54c2d53 | 2013-08-24 01:36:24 | [diff] [blame] | 197 | 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] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 201 | |
[email protected] | bdd22ff | 2013-07-17 17:21:12 | [diff] [blame] | 202 | RunCmd(['build/android/test_runner.py', 'instrumentation'] + args, |
| 203 | flunk_on_failure=flunk_on_failure) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 204 | |
| 205 | |
| 206 | def RunWebkitLint(target): |
| 207 | """Lint WebKit's TestExpectation files.""" |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 208 | bb_annotations.PrintNamedStep('webkit_lint') |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 209 | RunCmd(['webkit/tools/layout_tests/run_webkit_tests.py', |
| 210 | '--lint-test-files', |
| 211 | '--chromium', |
| 212 | '--target', target]) |
| 213 | |
| 214 | |
| 215 | def RunWebkitLayoutTests(options): |
| 216 | """Run layout tests on an actual device.""" |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 217 | bb_annotations.PrintNamedStep('webkit_tests') |
[email protected] | 22ee700 | 2013-01-23 20:58:04 | [diff] [blame] | 218 | 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] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 226 | '--results-directory', '../layout-test-results', |
[email protected] | 22ee700 | 2013-01-23 20:58:04 | [diff] [blame] | 227 | '--target', options.target, |
| 228 | '--builder-name', options.build_properties.get('buildername', ''), |
[email protected] | 0b793d6 | 2013-05-20 22:00:39 | [diff] [blame] | 229 | '--build-number', str(options.build_properties.get('buildnumber', '')), |
[email protected] | 22ee700 | 2013-01-23 20:58:04 | [diff] [blame] | 230 | '--master-name', options.build_properties.get('mastername', ''), |
| 231 | '--build-name', options.build_properties.get('buildername', ''), |
[email protected] | a1c7d2e | 2013-07-15 14:55:13 | [diff] [blame] | 232 | '--platform=android'] |
[email protected] | 22ee700 | 2013-01-23 20:58:04 | [diff] [blame] | 233 | |
| 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] | 2c39b29 | 2013-03-20 09:34:10 | [diff] [blame] | 239 | for f in options.factory_properties.get('additional_expectations', []): |
| 240 | cmd_args.extend( |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 241 | ['--additional-expectations=%s' % os.path.join(CHROME_SRC_DIR, *f)]) |
[email protected] | 2c39b29 | 2013-03-20 09:34:10 | [diff] [blame] | 242 | |
| 243 | # TODO(dpranke): Remove this block after |
| 244 | # https://codereview.chromium.org/12927002/ lands. |
[email protected] | 22ee700 | 2013-01-23 20:58:04 | [diff] [blame] | 245 | for f in options.factory_properties.get('additional_expectations_files', []): |
[email protected] | 62c5b98 | 2013-01-26 08:23:16 | [diff] [blame] | 246 | cmd_args.extend( |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 247 | ['--additional-expectations=%s' % os.path.join(CHROME_SRC_DIR, *f)]) |
[email protected] | 22ee700 | 2013-01-23 20:58:04 | [diff] [blame] | 248 | |
[email protected] | f9e7ddb | 2013-08-20 14:36:59 | [diff] [blame] | 249 | RunCmd(['webkit/tools/layout_tests/run_webkit_tests.py'] + cmd_args) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 250 | |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 251 | if options.factory_properties.get('archive_webkit_results', False): |
| 252 | bb_annotations.PrintNamedStep('archive_webkit_results') |
[email protected] | 85db7daf3 | 2013-09-09 21:21:25 | [diff] [blame] | 253 | gs_bucket = 'gs://chromium-layout-test-archives' |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 254 | RunCmd([os.path.join(SLAVE_SCRIPTS_DIR, 'chromium', |
| 255 | 'archive_layout_test_results.py'), |
[email protected] | dbb41dc | 2013-09-09 22:25:52 | [diff] [blame] | 256 | '--results-dir', '../../layout-test-results', |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 257 | '--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] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 262 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 263 | def SpawnLogcatMonitor(): |
| 264 | shutil.rmtree(LOGCAT_DIR, ignore_errors=True) |
| 265 | bb_utils.SpawnCmd([ |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 266 | os.path.join(CHROME_SRC_DIR, 'build', 'android', 'adb_logcat_monitor.py'), |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 267 | LOGCAT_DIR]) |
| 268 | |
| 269 | # Wait for logcat_monitor to pull existing logcat |
| 270 | RunCmd(['sleep', '5']) |
| 271 | |
| 272 | def ProvisionDevices(options): |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 273 | bb_annotations.PrintNamedStep('provision_devices') |
[email protected] | abfec37 | 2013-08-16 07:22:16 | [diff] [blame] | 274 | |
| 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] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 281 | if options.reboot: |
| 282 | RebootDevices() |
[email protected] | 7849a33 | 2013-07-12 01:40:09 | [diff] [blame] | 283 | 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] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 287 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 288 | |
| 289 | def DeviceStatusCheck(_): |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 290 | bb_annotations.PrintNamedStep('device_status_check') |
[email protected] | 37a6a38 | 2013-07-17 02:37:07 | [diff] [blame] | 291 | RunCmd(['build/android/buildbot/bb_device_status_check.py'], |
| 292 | halt_on_failure=True) |
[email protected] | 693c54d | 2013-01-09 19:41:25 | [diff] [blame] | 293 | |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 294 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 295 | def GetDeviceSetupStepCmds(): |
| 296 | return [ |
| 297 | ('provision_devices', ProvisionDevices), |
[email protected] | 0ff5fca | 2013-08-26 19:54:15 | [diff] [blame] | 298 | ('device_status_check', DeviceStatusCheck), |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 299 | ] |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 300 | |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 301 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 302 | def RunUnitTests(options): |
| 303 | RunTestSuites(options, gtest_config.STABLE_TEST_SUITES) |
| 304 | |
| 305 | |
| 306 | def RunInstrumentationTests(options): |
| 307 | for test in INSTRUMENTATION_TESTS.itervalues(): |
| 308 | RunInstrumentationSuite(options, test) |
| 309 | |
| 310 | |
| 311 | def RunWebkitTests(options): |
[email protected] | 9e68925 | 2013-07-30 20:14:36 | [diff] [blame] | 312 | RunTestSuites(options, ['webkit_unit_tests']) |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 313 | RunWebkitLint(options.target) |
| 314 | |
| 315 | |
[email protected] | 02bfada | 2013-08-12 05:00:52 | [diff] [blame] | 316 | def RunWebRTCTests(options): |
| 317 | RunTestSuites(options, gtest_config.WEBRTC_TEST_SUITES) |
| 318 | |
| 319 | |
[email protected] | a4b1ec97 | 2013-09-14 05:36:25 | [diff] [blame] | 320 | def RunGPUTests(options): |
| 321 | InstallApk(options, INSTRUMENTATION_TESTS['ContentShell'], False) |
[email protected] | bb508f8 | 2013-09-06 06:42:24 | [diff] [blame] | 322 | bb_annotations.PrintNamedStep('gpu_tests') |
| 323 | RunCmd(['content/test/gpu/run_gpu_test', |
| 324 | '--browser=android-content-shell', 'pixel']) |
| 325 | |
| 326 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 327 | def GetTestStepCmds(): |
| 328 | return [ |
| 329 | ('chromedriver', RunChromeDriverTests), |
[email protected] | bb508f8 | 2013-09-06 06:42:24 | [diff] [blame] | 330 | ('gpu', RunGPUTests), |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 331 | ('unit', RunUnitTests), |
| 332 | ('ui', RunInstrumentationTests), |
| 333 | ('webkit', RunWebkitTests), |
[email protected] | 02bfada | 2013-08-12 05:00:52 | [diff] [blame] | 334 | ('webkit_layout', RunWebkitLayoutTests), |
| 335 | ('webrtc', RunWebRTCTests), |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 336 | ] |
| 337 | |
| 338 | |
[email protected] | 4e622cee | 2013-09-17 18:32:12 | [diff] [blame^] | 339 | def 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] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 342 | |
| 343 | Args: |
| 344 | options: Command line options. |
[email protected] | 4e622cee | 2013-09-17 18:32:12 | [diff] [blame^] | 345 | 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] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 351 | """ |
[email protected] | e6a5eee | 2013-08-23 05:27:08 | [diff] [blame] | 352 | revision = options.build_properties.get('got_revision') |
| 353 | if not revision: |
| 354 | revision = options.build_properties.get('revision', 'testing') |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 355 | bot_id = options.build_properties.get('buildername', 'testing') |
| 356 | randhash = hashlib.sha1(str(random.random())).hexdigest() |
[email protected] | 4e622cee | 2013-09-17 18:32:12 | [diff] [blame^] | 357 | 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] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 361 | |
| 362 | |
| 363 | def 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] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 370 | '--metadata-dir', os.path.join(CHROME_OUT_DIR, options.target), |
[email protected] | a1f1abfe | 2013-08-27 22:02:43 | [diff] [blame] | 371 | '--cleanup', |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 372 | '--output', os.path.join(coverage_html, 'index.html')]) |
[email protected] | 4e622cee | 2013-09-17 18:32:12 | [diff] [blame^] | 373 | return coverage_html |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 374 | |
| 375 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 376 | def LogcatDump(options): |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 377 | # Print logcat, kill logcat monitor |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 378 | bb_annotations.PrintNamedStep('logcat_dump') |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 379 | logcat_file = os.path.join(CHROME_OUT_DIR, options.target, 'full_log') |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 380 | with open(logcat_file, 'w') as f: |
| 381 | RunCmd([ |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 382 | os.path.join(CHROME_SRC_DIR, 'build', 'android', |
| 383 | 'adb_logcat_printer.py'), |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 384 | LOGCAT_DIR], stdout=f) |
| 385 | RunCmd(['cat', logcat_file]) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 386 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 387 | |
| 388 | def GenerateTestReport(options): |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 389 | bb_annotations.PrintNamedStep('test_report') |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 390 | for report in glob.glob( |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 391 | os.path.join(CHROME_OUT_DIR, options.target, 'test_logs', '*.log')): |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 392 | RunCmd(['cat', report]) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 393 | os.remove(report) |
| 394 | |
| 395 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 396 | def MainTestWrapper(options): |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 397 | try: |
| 398 | # Spawn logcat monitor |
| 399 | SpawnLogcatMonitor() |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 400 | |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 401 | # Run all device setup steps |
| 402 | for _, cmd in GetDeviceSetupStepCmds(): |
| 403 | cmd(options) |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 404 | |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 405 | if options.install: |
| 406 | test_obj = INSTRUMENTATION_TESTS[options.install] |
| 407 | InstallApk(options, test_obj, print_step=True) |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 408 | |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 409 | if options.test_filter: |
| 410 | bb_utils.RunSteps(options.test_filter, GetTestStepCmds(), options) |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 411 | |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 412 | if options.coverage_bucket: |
[email protected] | 4e622cee | 2013-09-17 18:32:12 | [diff] [blame^] | 413 | coverage_html = GenerateJavaCoverageReport(options) |
| 414 | UploadHTML(options, '%s/java' % options.coverage_bucket, coverage_html, |
| 415 | 'Coverage Report') |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 416 | |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 417 | if options.experimental: |
| 418 | RunTestSuites(options, gtest_config.EXPERIMENTAL_TEST_SUITES) |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 419 | |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 420 | 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] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 427 | |
| 428 | |
| 429 | def GetDeviceStepsOptParser(): |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 430 | parser = bb_utils.GetParser() |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 431 | 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] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 440 | parser.add_option('--reboot', action='store_true', |
| 441 | help='Reboot devices before running tests') |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 442 | parser.add_option('--coverage-bucket', |
| 443 | help=('Bucket name to store coverage results. Coverage is ' |
| 444 | 'only run if this is set.')) |
[email protected] | 14f139f4 | 2013-07-24 18:41:58 | [diff] [blame] | 445 | parser.add_option( |
| 446 | '--flakiness-server', |
| 447 | help='The flakiness dashboard server to which the results should be ' |
| 448 | 'uploaded.') |
[email protected] | 12f36c8 | 2013-03-29 06:21:13 | [diff] [blame] | 449 | parser.add_option( |
| 450 | '--auto-reconnect', action='store_true', |
| 451 | help='Push script to device which restarts adbd on disconnections.') |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 452 | 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 | |
| 459 | def main(argv): |
| 460 | parser = GetDeviceStepsOptParser() |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 461 | options, args = parser.parse_args(argv[1:]) |
| 462 | |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 463 | if args: |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 464 | return sys.exit('Unused args %s' % args) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 465 | |
| 466 | unknown_tests = set(options.test_filter) - VALID_TESTS |
| 467 | if unknown_tests: |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 468 | return sys.exit('Unknown tests %s' % list(unknown_tests)) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 469 | |
| 470 | setattr(options, 'target', options.factory_properties.get('target', 'Debug')) |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 471 | if options.coverage_bucket: |
| 472 | setattr(options, 'coverage_dir', |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 473 | os.path.join(CHROME_OUT_DIR, options.target, 'coverage')) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 474 | |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 475 | MainTestWrapper(options) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 476 | |
| 477 | |
| 478 | if __name__ == '__main__': |
| 479 | sys.exit(main(sys.argv)) |