[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] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 9 | import json |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 10 | import multiprocessing |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 11 | import os |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 12 | import random |
[email protected] | e2107bd | 2013-09-18 05:13:10 | [diff] [blame] | 13 | import re |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 14 | import shutil |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 15 | import sys |
| 16 | |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 17 | import bb_utils |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 18 | import bb_annotations |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 19 | |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 20 | sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
[email protected] | 7849a33 | 2013-07-12 01:40:09 | [diff] [blame] | 21 | import provision_devices |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 22 | from pylib import android_commands |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 23 | from pylib import constants |
[email protected] | 044d79b | 2014-04-10 19:37:30 | [diff] [blame] | 24 | from pylib.device import device_utils |
[email protected] | a8fea93f | 2013-01-10 04:00:07 | [diff] [blame] | 25 | from pylib.gtest import gtest_config |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 26 | |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 27 | CHROME_SRC_DIR = bb_utils.CHROME_SRC |
[email protected] | ae41072 | 2013-10-24 15:57:36 | [diff] [blame] | 28 | DIR_BUILD_ROOT = os.path.dirname(CHROME_SRC_DIR) |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 29 | CHROME_OUT_DIR = bb_utils.CHROME_OUT_DIR |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 30 | sys.path.append(os.path.join( |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 31 | CHROME_SRC_DIR, 'third_party', 'android_testrunner')) |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 32 | import errors |
| 33 | |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 34 | |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 35 | SLAVE_SCRIPTS_DIR = os.path.join(bb_utils.BB_BUILD_DIR, 'scripts', 'slave') |
| 36 | LOGCAT_DIR = os.path.join(bb_utils.CHROME_OUT_DIR, 'logcat') |
[email protected] | 4e622cee | 2013-09-17 18:32:12 | [diff] [blame] | 37 | GS_URL = 'https://storage.googleapis.com' |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 38 | |
| 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] | 37ee0c79 | 2013-08-06 19:10:13 | [diff] [blame] | 45 | # host_driven_root: The host-driven test root directory. |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 46 | # annotation: Annotation of the tests to include. |
| 47 | # exclude_annotation: The annotation of the tests to exclude. |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 48 | I_TEST = collections.namedtuple('InstrumentationTest', [ |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 49 | 'name', 'apk', 'apk_package', 'test_apk', 'test_data', 'host_driven_root', |
| 50 | 'annotation', 'exclude_annotation', 'extra_flags']) |
| 51 | |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 52 | |
[email protected] | ae41072 | 2013-10-24 15:57:36 | [diff] [blame] | 53 | def SrcPath(*path): |
| 54 | return os.path.join(CHROME_SRC_DIR, *path) |
| 55 | |
| 56 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 57 | def 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] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 61 | |
| 62 | INSTRUMENTATION_TESTS = dict((suite.name, suite) for suite in [ |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 63 | I('ContentShell', |
| 64 | 'ContentShell.apk', |
| 65 | 'org.chromium.content_shell_apk', |
| 66 | 'ContentShellTest', |
| 67 | 'content:content/test/data/android/device_files'), |
[email protected] | efeb59e | 2014-03-12 01:31:26 | [diff] [blame] | 68 | I('ChromeShell', |
| 69 | 'ChromeShell.apk', |
[email protected] | 34460fc | 2014-03-04 07:18:00 | [diff] [blame] | 70 | 'org.chromium.chrome.shell', |
[email protected] | efeb59e | 2014-03-12 01:31:26 | [diff] [blame] | 71 | 'ChromeShellTest', |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 72 | 'chrome:chrome/test/data/android/device_files', |
[email protected] | efeb59e | 2014-03-12 01:31:26 | [diff] [blame] | 73 | constants.CHROME_SHELL_HOST_DRIVEN_DIR), |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 74 | I('AndroidWebView', |
| 75 | 'AndroidWebView.apk', |
| 76 | 'org.chromium.android_webview.shell', |
| 77 | 'AndroidWebViewTest', |
| 78 | 'webview:android_webview/test/data/device_files'), |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 79 | ]) |
| 80 | |
[email protected] | 29f7e7c | 2014-04-24 00:55:22 | [diff] [blame^] | 81 | VALID_TESTS = set(['chromedriver', 'gpu', 'telemetry_perf_unittests', |
| 82 | 'ui', 'unit', 'webkit', 'webkit_layout', 'webrtc_chromium', |
| 83 | 'webrtc_native']) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 84 | |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 85 | RunCmd = bb_utils.RunCmd |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 86 | |
| 87 | |
[email protected] | e7bd341 | 2013-09-20 17:15:28 | [diff] [blame] | 88 | def _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] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 103 | # multiprocessing map_async requires a top-level function for pickle library. |
| 104 | def RebootDeviceSafe(device): |
| 105 | """Reboot a device, wait for it to start, and squelch timeout exceptions.""" |
| 106 | try: |
[email protected] | 044d79b | 2014-04-10 19:37:30 | [diff] [blame] | 107 | device_utils.DeviceUtils(device).old_interface.Reboot(True) |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 108 | except errors.DeviceUnresponsiveError as e: |
| 109 | return e |
| 110 | |
| 111 | |
| 112 | def RebootDevices(): |
| 113 | """Reboot all attached and online devices.""" |
[email protected] | c94ae6b | 2013-01-14 21:38:34 | [diff] [blame] | 114 | # Early return here to avoid presubmit dependence on adb, |
| 115 | # which might not exist in this checkout. |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 116 | if bb_utils.TESTING: |
[email protected] | c94ae6b | 2013-01-14 21:38:34 | [diff] [blame] | 117 | return |
[email protected] | 044d79b | 2014-04-10 19:37:30 | [diff] [blame] | 118 | devices = android_commands.GetAttachedDevices() |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 119 | print 'Rebooting: %s' % devices |
[email protected] | c94ae6b | 2013-01-14 21:38:34 | [diff] [blame] | 120 | if devices: |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 121 | 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] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 129 | bb_annotations.PrintWarning() |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 130 | else: |
| 131 | print 'Reboots complete.' |
| 132 | |
| 133 | |
[email protected] | a8fea93f | 2013-01-10 04:00:07 | [diff] [blame] | 134 | def RunTestSuites(options, suites): |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 135 | """Manages an invocation of test_runner.py for gtests. |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 136 | |
| 137 | Args: |
| 138 | options: options object. |
[email protected] | 9e68925 | 2013-07-30 20:14:36 | [diff] [blame] | 139 | suites: List of suite names to run. |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 140 | """ |
| 141 | args = ['--verbose'] |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 142 | if options.target == 'Release': |
| 143 | args.append('--release') |
| 144 | if options.asan: |
| 145 | args.append('--tool=asan') |
[email protected] | 18d59b8 | 2013-11-12 09:21:41 | [diff] [blame] | 146 | if options.gtest_filter: |
| 147 | args.append('--gtest-filter=%s' % options.gtest_filter) |
[email protected] | a8fea93f | 2013-01-10 04:00:07 | [diff] [blame] | 148 | for suite in suites: |
[email protected] | 9e68925 | 2013-07-30 20:14:36 | [diff] [blame] | 149 | 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] | 9324bff | 2013-03-13 04:09:27 | [diff] [blame] | 153 | RunCmd(cmd) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 154 | |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 155 | |
[email protected] | e7bd341 | 2013-09-20 17:15:28 | [diff] [blame] | 156 | def RunChromeDriverTests(options): |
[email protected] | d8897f6c | 2013-03-05 00:27:16 | [diff] [blame] | 157 | """Run all the steps for running chromedriver tests.""" |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 158 | bb_annotations.PrintNamedStep('chromedriver_annotation') |
[email protected] | d8897f6c | 2013-03-05 00:27:16 | [diff] [blame] | 159 | RunCmd(['chrome/test/chromedriver/run_buildbot_steps.py', |
[email protected] | b1010d26 | 2013-11-27 22:01:28 | [diff] [blame] | 160 | '--android-packages=%s,%s,%s,%s' % |
[email protected] | efeb59e | 2014-03-12 01:31:26 | [diff] [blame] | 161 | ('chrome_shell', |
[email protected] | 4418f02 | 2013-11-11 19:21:03 | [diff] [blame] | 162 | 'chrome_stable', |
[email protected] | b1010d26 | 2013-11-27 22:01:28 | [diff] [blame] | 163 | 'chrome_beta', |
| 164 | 'chromedriver_webview_shell'), |
[email protected] | e7bd341 | 2013-09-20 17:15:28 | [diff] [blame] | 165 | '--revision=%s' % _GetRevision(options), |
[email protected] | fde0700 | 2013-09-20 21:02:39 | [diff] [blame] | 166 | '--update-log']) |
[email protected] | d8897f6c | 2013-03-05 00:27:16 | [diff] [blame] | 167 | |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 168 | |
[email protected] | 29f7e7c | 2014-04-24 00:55:22 | [diff] [blame^] | 169 | def 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] | a2a72524 | 2013-01-09 21:52:57 | [diff] [blame] | 184 | def 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] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 193 | bb_annotations.PrintNamedStep('install_%s' % test.name.lower()) |
[email protected] | 6ca5751 | 2013-08-23 21:42:04 | [diff] [blame] | 194 | |
[email protected] | a2a72524 | 2013-01-09 21:52:57 | [diff] [blame] | 195 | args = ['--apk', test.apk, '--apk_package', test.apk_package] |
| 196 | if options.target == 'Release': |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 197 | args.append('--release') |
| 198 | |
[email protected] | 800673bf | 2013-05-14 17:15:30 | [diff] [blame] | 199 | RunCmd(['build/android/adb_install_apk.py'] + args, halt_on_failure=True) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 200 | |
| 201 | |
[email protected] | acfaf4c | 2013-07-25 00:23:56 | [diff] [blame] | 202 | def RunInstrumentationSuite(options, test, flunk_on_failure=True, |
[email protected] | 54c2d53 | 2013-08-24 01:36:24 | [diff] [blame] | 203 | python_only=False, official_build=False): |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 204 | """Manages an invocation of test_runner.py for instrumentation tests. |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 205 | |
| 206 | Args: |
| 207 | options: options object |
| 208 | test: An I_TEST namedtuple |
[email protected] | acfaf4c | 2013-07-25 00:23:56 | [diff] [blame] | 209 | flunk_on_failure: Flunk the step if tests fail. |
| 210 | Python: Run only host driven Python tests. |
[email protected] | 54c2d53 | 2013-08-24 01:36:24 | [diff] [blame] | 211 | official_build: Run official-build tests. |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 212 | """ |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 213 | bb_annotations.PrintNamedStep('%s_instrumentation_tests' % test.name.lower()) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 214 | |
[email protected] | a2a72524 | 2013-01-09 21:52:57 | [diff] [blame] | 215 | InstallApk(options, test) |
[email protected] | d1a0657c | 2013-04-10 22:38:59 | [diff] [blame] | 216 | args = ['--test-apk', test.test_apk, '--test_data', test.test_data, |
[email protected] | fb7ab5e8 | 2013-07-26 18:31:20 | [diff] [blame] | 217 | '--verbose'] |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 218 | if options.target == 'Release': |
| 219 | args.append('--release') |
| 220 | if options.asan: |
| 221 | args.append('--tool=asan') |
[email protected] | 14f139f4 | 2013-07-24 18:41:58 | [diff] [blame] | 222 | if options.flakiness_server: |
[email protected] | b796a77 | 2013-01-19 03:55:22 | [diff] [blame] | 223 | args.append('--flakiness-dashboard-server=%s' % |
[email protected] | 14f139f4 | 2013-07-24 18:41:58 | [diff] [blame] | 224 | options.flakiness_server) |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 225 | if options.coverage_bucket: |
| 226 | args.append('--coverage-dir=%s' % options.coverage_dir) |
[email protected] | 8d8ca04 | 2013-02-14 19:29:17 | [diff] [blame] | 227 | if test.host_driven_root: |
[email protected] | 67954f82 | 2013-08-14 18:09:08 | [diff] [blame] | 228 | args.append('--host-driven-root=%s' % test.host_driven_root) |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 229 | 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] | acfaf4c | 2013-07-25 00:23:56 | [diff] [blame] | 235 | if python_only: |
| 236 | args.append('-p') |
[email protected] | 54c2d53 | 2013-08-24 01:36:24 | [diff] [blame] | 237 | 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] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 241 | |
[email protected] | bdd22ff | 2013-07-17 17:21:12 | [diff] [blame] | 242 | RunCmd(['build/android/test_runner.py', 'instrumentation'] + args, |
| 243 | flunk_on_failure=flunk_on_failure) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 244 | |
| 245 | |
| 246 | def RunWebkitLint(target): |
| 247 | """Lint WebKit's TestExpectation files.""" |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 248 | bb_annotations.PrintNamedStep('webkit_lint') |
[email protected] | ae41072 | 2013-10-24 15:57:36 | [diff] [blame] | 249 | RunCmd([SrcPath('webkit/tools/layout_tests/run_webkit_tests.py'), |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 250 | '--lint-test-files', |
| 251 | '--chromium', |
| 252 | '--target', target]) |
| 253 | |
| 254 | |
| 255 | def RunWebkitLayoutTests(options): |
| 256 | """Run layout tests on an actual device.""" |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 257 | bb_annotations.PrintNamedStep('webkit_tests') |
[email protected] | 22ee700 | 2013-01-23 20:58:04 | [diff] [blame] | 258 | cmd_args = [ |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 259 | '--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] | 22ee700 | 2013-01-23 20:58:04 | [diff] [blame] | 273 | |
| 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] | 2c39b29 | 2013-03-20 09:34:10 | [diff] [blame] | 279 | for f in options.factory_properties.get('additional_expectations', []): |
| 280 | cmd_args.extend( |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 281 | ['--additional-expectations=%s' % os.path.join(CHROME_SRC_DIR, *f)]) |
[email protected] | 2c39b29 | 2013-03-20 09:34:10 | [diff] [blame] | 282 | |
| 283 | # TODO(dpranke): Remove this block after |
| 284 | # https://codereview.chromium.org/12927002/ lands. |
[email protected] | 22ee700 | 2013-01-23 20:58:04 | [diff] [blame] | 285 | for f in options.factory_properties.get('additional_expectations_files', []): |
[email protected] | 62c5b98 | 2013-01-26 08:23:16 | [diff] [blame] | 286 | cmd_args.extend( |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 287 | ['--additional-expectations=%s' % os.path.join(CHROME_SRC_DIR, *f)]) |
[email protected] | 22ee700 | 2013-01-23 20:58:04 | [diff] [blame] | 288 | |
[email protected] | ae41072 | 2013-10-24 15:57:36 | [diff] [blame] | 289 | exit_code = RunCmd([SrcPath('webkit/tools/layout_tests/run_webkit_tests.py')] |
| 290 | + cmd_args) |
[email protected] | 1782ef4 | 2013-10-18 21:07:33 | [diff] [blame] | 291 | if exit_code == 255: # test_run_results.UNEXPECTED_ERROR_EXIT_STATUS |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 292 | bb_annotations.PrintMsg('?? (crashed or hung)') |
[email protected] | 1782ef4 | 2013-10-18 21:07:33 | [diff] [blame] | 293 | elif exit_code == 254: # test_run_results.NO_DEVICES_EXIT_STATUS |
[email protected] | 361229ac | 2013-10-17 18:57:15 | [diff] [blame] | 294 | bb_annotations.PrintMsg('?? (no devices found)') |
[email protected] | 1782ef4 | 2013-10-18 21:07:33 | [diff] [blame] | 295 | elif exit_code == 253: # test_run_results.NO_TESTS_EXIT_STATUS |
[email protected] | 361229ac | 2013-10-17 18:57:15 | [diff] [blame] | 296 | bb_annotations.PrintMsg('?? (no tests found)') |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 297 | 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] | e2782b8 | 2013-10-14 19:43:45 | [diff] [blame] | 302 | unexpected_passes, unexpected_failures, unexpected_flakes = ( |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 303 | _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] | bc14cb1 | 2013-10-10 18:47:14 | [diff] [blame] | 313 | |
| 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] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 317 | else: |
[email protected] | bc14cb1 | 2013-10-10 18:47:14 | [diff] [blame] | 318 | bb_annotations.PrintError() |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 319 | bb_annotations.PrintMsg('?? (results missing)') |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 320 | |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 321 | if options.factory_properties.get('archive_webkit_results', False): |
| 322 | bb_annotations.PrintNamedStep('archive_webkit_results') |
[email protected] | 613e5a3 | 2013-09-18 01:46:32 | [diff] [blame] | 323 | 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] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 326 | 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] | e2107bd | 2013-09-18 05:13:10 | [diff] [blame] | 329 | bb_annotations.PrintLink('(zip)', '%s/%s/%s/layout-test-results.zip' % ( |
| 330 | base, EscapeBuilderName(builder_name), build_number)) |
[email protected] | 85db7daf3 | 2013-09-09 21:21:25 | [diff] [blame] | 331 | gs_bucket = 'gs://chromium-layout-test-archives' |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 332 | RunCmd([os.path.join(SLAVE_SCRIPTS_DIR, 'chromium', |
| 333 | 'archive_layout_test_results.py'), |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 334 | '--results-dir', '../../layout-test-results', |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 335 | '--build-number', build_number, |
| 336 | '--builder-name', builder_name, |
[email protected] | ae41072 | 2013-10-24 15:57:36 | [diff] [blame] | 337 | '--gs-bucket', gs_bucket], |
| 338 | cwd=DIR_BUILD_ROOT) |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 339 | |
| 340 | |
| 341 | def _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] | ff81fe11 | 2013-10-22 21:13:16 | [diff] [blame] | 350 | 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] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 360 | passes[test] = result |
| 361 | else: |
[email protected] | ff81fe11 | 2013-10-22 21:13:16 | [diff] [blame] | 362 | failures[test] = actual_results[0] |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 363 | |
| 364 | return (passes, failures, flakes) |
| 365 | |
| 366 | |
| 367 | def _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 | |
| 383 | def _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] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 397 | |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 398 | |
[email protected] | e2107bd | 2013-09-18 05:13:10 | [diff] [blame] | 399 | def EscapeBuilderName(builder_name): |
| 400 | return re.sub('[ ()]', '_', builder_name) |
| 401 | |
| 402 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 403 | def SpawnLogcatMonitor(): |
| 404 | shutil.rmtree(LOGCAT_DIR, ignore_errors=True) |
[email protected] | 97d1032 | 2013-10-04 20:53:04 | [diff] [blame] | 405 | bb_utils.SpawnCmd([ |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 406 | os.path.join(CHROME_SRC_DIR, 'build', 'android', 'adb_logcat_monitor.py'), |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 407 | LOGCAT_DIR]) |
| 408 | |
| 409 | # Wait for logcat_monitor to pull existing logcat |
| 410 | RunCmd(['sleep', '5']) |
| 411 | |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 412 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 413 | def ProvisionDevices(options): |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 414 | bb_annotations.PrintNamedStep('provision_devices') |
[email protected] | abfec37 | 2013-08-16 07:22:16 | [diff] [blame] | 415 | |
| 416 | if not bb_utils.TESTING: |
| 417 | # Restart adb to work around bugs, sleep to wait for usb discovery. |
[email protected] | 044d79b | 2014-04-10 19:37:30 | [diff] [blame] | 418 | device_utils.DeviceUtils(None).old_interface.RestartAdbServer() |
[email protected] | abfec37 | 2013-08-16 07:22:16 | [diff] [blame] | 419 | RunCmd(['sleep', '1']) |
| 420 | |
[email protected] | 4a3375d | 2014-01-08 12:56:50 | [diff] [blame] | 421 | if not options.no_reboot: |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 422 | RebootDevices() |
[email protected] | 7849a33 | 2013-07-12 01:40:09 | [diff] [blame] | 423 | 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] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 427 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 428 | |
[email protected] | e5d85a7 | 2013-10-19 13:44:02 | [diff] [blame] | 429 | def DeviceStatusCheck(options): |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 430 | bb_annotations.PrintNamedStep('device_status_check') |
[email protected] | e5d85a7 | 2013-10-19 13:44:02 | [diff] [blame] | 431 | 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] | 693c54d | 2013-01-09 19:41:25 | [diff] [blame] | 435 | |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 436 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 437 | def GetDeviceSetupStepCmds(): |
| 438 | return [ |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 439 | ('device_status_check', DeviceStatusCheck), |
[email protected] | 917cd320b | 2013-12-03 16:13:35 | [diff] [blame] | 440 | ('provision_devices', ProvisionDevices), |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 441 | ] |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 442 | |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 443 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 444 | def RunUnitTests(options): |
[email protected] | 502362c7 | 2014-02-26 07:06:44 | [diff] [blame] | 445 | 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] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 450 | |
| 451 | |
| 452 | def RunInstrumentationTests(options): |
| 453 | for test in INSTRUMENTATION_TESTS.itervalues(): |
| 454 | RunInstrumentationSuite(options, test) |
| 455 | |
| 456 | |
| 457 | def RunWebkitTests(options): |
[email protected] | 130d0b57 | 2014-02-03 18:09:01 | [diff] [blame] | 458 | RunTestSuites(options, ['webkit_unit_tests', 'blink_heap_unittests']) |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 459 | RunWebkitLint(options.target) |
| 460 | |
| 461 | |
[email protected] | 640afed | 2013-10-21 08:18:29 | [diff] [blame] | 462 | def RunWebRTCChromiumTests(options): |
| 463 | RunTestSuites(options, gtest_config.WEBRTC_CHROMIUM_TEST_SUITES) |
| 464 | |
| 465 | |
| 466 | def RunWebRTCNativeTests(options): |
| 467 | RunTestSuites(options, gtest_config.WEBRTC_NATIVE_TEST_SUITES) |
[email protected] | 02bfada | 2013-08-12 05:00:52 | [diff] [blame] | 468 | |
| 469 | |
[email protected] | a4b1ec97 | 2013-09-14 05:36:25 | [diff] [blame] | 470 | def RunGPUTests(options): |
| 471 | InstallApk(options, INSTRUMENTATION_TESTS['ContentShell'], False) |
[email protected] | fb9cd4bb | 2013-10-16 21:59:53 | [diff] [blame] | 472 | |
[email protected] | 7444882 | 2013-10-22 16:40:53 | [diff] [blame] | 473 | bb_annotations.PrintNamedStep('gpu_tests') |
[email protected] | 7391b31 | 2013-12-12 17:06:01 | [diff] [blame] | 474 | revision = _GetRevision(options) |
[email protected] | 389234f | 2014-02-25 03:31:12 | [diff] [blame] | 475 | RunCmd(['content/test/gpu/run_gpu_test.py', |
[email protected] | e66b592 | 2014-01-07 20:10:04 | [diff] [blame] | 476 | '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] | fb9cd4bb | 2013-10-16 21:59:53 | [diff] [blame] | 489 | |
[email protected] | cce70f0 | 2013-10-15 12:53:19 | [diff] [blame] | 490 | bb_annotations.PrintNamedStep('webgl_conformance_tests') |
[email protected] | 389234f | 2014-02-25 03:31:12 | [diff] [blame] | 491 | RunCmd(['content/test/gpu/run_gpu_test.py', |
[email protected] | cce70f0 | 2013-10-15 12:53:19 | [diff] [blame] | 492 | '--browser=android-content-shell', 'webgl_conformance', |
| 493 | '--webgl-conformance-version=1.0.1']) |
[email protected] | bb508f8 | 2013-09-06 06:42:24 | [diff] [blame] | 494 | |
| 495 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 496 | def GetTestStepCmds(): |
| 497 | return [ |
| 498 | ('chromedriver', RunChromeDriverTests), |
[email protected] | bb508f8 | 2013-09-06 06:42:24 | [diff] [blame] | 499 | ('gpu', RunGPUTests), |
[email protected] | 29f7e7c | 2014-04-24 00:55:22 | [diff] [blame^] | 500 | ('telemetry_perf_unittests', RunTelemetryPerfUnitTests), |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 501 | ('unit', RunUnitTests), |
| 502 | ('ui', RunInstrumentationTests), |
| 503 | ('webkit', RunWebkitTests), |
[email protected] | 02bfada | 2013-08-12 05:00:52 | [diff] [blame] | 504 | ('webkit_layout', RunWebkitLayoutTests), |
[email protected] | 640afed | 2013-10-21 08:18:29 | [diff] [blame] | 505 | ('webrtc_chromium', RunWebRTCChromiumTests), |
| 506 | ('webrtc_native', RunWebRTCNativeTests), |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 507 | ] |
| 508 | |
| 509 | |
[email protected] | c11a468 | 2014-04-22 23:04:13 | [diff] [blame] | 510 | def 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] | 4e622cee | 2013-09-17 18:32:12 | [diff] [blame] | 517 | def 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] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 520 | |
| 521 | Args: |
| 522 | options: Command line options. |
[email protected] | 4e622cee | 2013-09-17 18:32:12 | [diff] [blame] | 523 | 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] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 529 | """ |
[email protected] | c11a468 | 2014-04-22 23:04:13 | [diff] [blame] | 530 | gs_path = MakeGSPath(options, gs_base_dir) |
[email protected] | 4e622cee | 2013-09-17 18:32:12 | [diff] [blame] | 531 | RunCmd([bb_utils.GSUTIL_PATH, 'cp', '-R', dir_to_upload, 'gs://%s' % gs_path]) |
| 532 | bb_annotations.PrintLink(link_text, |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 533 | '%s/%s/%s' % (gs_url, gs_path, link_rel_path)) |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 534 | |
| 535 | |
| 536 | def 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] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 543 | '--metadata-dir', os.path.join(CHROME_OUT_DIR, options.target), |
[email protected] | a1f1abfe | 2013-08-27 22:02:43 | [diff] [blame] | 544 | '--cleanup', |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 545 | '--output', os.path.join(coverage_html, 'index.html')]) |
[email protected] | 4e622cee | 2013-09-17 18:32:12 | [diff] [blame] | 546 | return coverage_html |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 547 | |
| 548 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 549 | def LogcatDump(options): |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 550 | # Print logcat, kill logcat monitor |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 551 | bb_annotations.PrintNamedStep('logcat_dump') |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 552 | logcat_file = os.path.join(CHROME_OUT_DIR, options.target, 'full_log') |
[email protected] | 46e095c | 2013-11-21 13:48:58 | [diff] [blame] | 553 | RunCmd([SrcPath('build' , 'android', 'adb_logcat_printer.py'), |
| 554 | '--output-path', logcat_file, LOGCAT_DIR]) |
[email protected] | c11a468 | 2014-04-22 23:04:13 | [diff] [blame] | 555 | 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] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 558 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 559 | |
[email protected] | 79d3d8d8 | 2014-02-05 13:47:04 | [diff] [blame] | 560 | def 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] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 577 | def GenerateTestReport(options): |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 578 | bb_annotations.PrintNamedStep('test_report') |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 579 | for report in glob.glob( |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 580 | os.path.join(CHROME_OUT_DIR, options.target, 'test_logs', '*.log')): |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 581 | RunCmd(['cat', report]) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 582 | os.remove(report) |
| 583 | |
| 584 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 585 | def MainTestWrapper(options): |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 586 | try: |
| 587 | # Spawn logcat monitor |
| 588 | SpawnLogcatMonitor() |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 589 | |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 590 | # Run all device setup steps |
| 591 | for _, cmd in GetDeviceSetupStepCmds(): |
| 592 | cmd(options) |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 593 | |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 594 | if options.install: |
| 595 | test_obj = INSTRUMENTATION_TESTS[options.install] |
| 596 | InstallApk(options, test_obj, print_step=True) |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 597 | |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 598 | if options.test_filter: |
| 599 | bb_utils.RunSteps(options.test_filter, GetTestStepCmds(), options) |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 600 | |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 601 | if options.coverage_bucket: |
[email protected] | 4e622cee | 2013-09-17 18:32:12 | [diff] [blame] | 602 | coverage_html = GenerateJavaCoverageReport(options) |
| 603 | UploadHTML(options, '%s/java' % options.coverage_bucket, coverage_html, |
| 604 | 'Coverage Report') |
[email protected] | ec7b222 | 2014-01-16 02:49:15 | [diff] [blame] | 605 | shutil.rmtree(coverage_html, ignore_errors=True) |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 606 | |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 607 | if options.experimental: |
| 608 | RunTestSuites(options, gtest_config.EXPERIMENTAL_TEST_SUITES) |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 609 | |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 610 | finally: |
| 611 | # Run all post test steps |
| 612 | LogcatDump(options) |
[email protected] | 79d3d8d8 | 2014-02-05 13:47:04 | [diff] [blame] | 613 | if not options.disable_stack_tool: |
| 614 | RunStackToolSteps(options) |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 615 | 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] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 619 | |
| 620 | |
| 621 | def GetDeviceStepsOptParser(): |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 622 | parser = bb_utils.GetParser() |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 623 | 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] | 18d59b8 | 2013-11-12 09:21:41 | [diff] [blame] | 629 | parser.add_option('--gtest-filter', |
| 630 | help='Filter for running a subset of tests of a gtest test') |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 631 | 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] | 4a3375d | 2014-01-08 12:56:50 | [diff] [blame] | 634 | parser.add_option('--no-reboot', action='store_true', |
| 635 | help='Do not reboot devices during provisioning.') |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 636 | parser.add_option('--coverage-bucket', |
| 637 | help=('Bucket name to store coverage results. Coverage is ' |
| 638 | 'only run if this is set.')) |
[email protected] | e5d85a7 | 2013-10-19 13:44:02 | [diff] [blame] | 639 | parser.add_option('--restart-usb', action='store_true', |
| 640 | help='Restart usb ports before device status check.') |
[email protected] | 14f139f4 | 2013-07-24 18:41:58 | [diff] [blame] | 641 | parser.add_option( |
| 642 | '--flakiness-server', |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 643 | help=('The flakiness dashboard server to which the results should be ' |
| 644 | 'uploaded.')) |
[email protected] | 12f36c8 | 2013-03-29 06:21:13 | [diff] [blame] | 645 | parser.add_option( |
| 646 | '--auto-reconnect', action='store_true', |
| 647 | help='Push script to device which restarts adbd on disconnections.') |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 648 | parser.add_option( |
| 649 | '--logcat-dump-output', |
| 650 | help='The logcat dump output will be "tee"-ed into this file') |
[email protected] | 79d3d8d8 | 2014-02-05 13:47:04 | [diff] [blame] | 651 | 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] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 655 | return parser |
| 656 | |
| 657 | |
| 658 | def main(argv): |
| 659 | parser = GetDeviceStepsOptParser() |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 660 | options, args = parser.parse_args(argv[1:]) |
| 661 | |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 662 | if args: |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 663 | return sys.exit('Unused args %s' % args) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 664 | |
| 665 | unknown_tests = set(options.test_filter) - VALID_TESTS |
| 666 | if unknown_tests: |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 667 | return sys.exit('Unknown tests %s' % list(unknown_tests)) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 668 | |
| 669 | setattr(options, 'target', options.factory_properties.get('target', 'Debug')) |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 670 | if options.coverage_bucket: |
| 671 | setattr(options, 'coverage_dir', |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 672 | os.path.join(CHROME_OUT_DIR, options.target, 'coverage')) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 673 | |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 674 | MainTestWrapper(options) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 675 | |
| 676 | |
| 677 | if __name__ == '__main__': |
| 678 | sys.exit(main(sys.argv)) |