[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] | 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] | e2107bd | 2013-09-18 05:13:10 | [diff] [blame] | 12 | import re |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 13 | import shutil |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 14 | import sys |
| 15 | |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 16 | import bb_utils |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 17 | import bb_annotations |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 18 | |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 19 | sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
jbudorick | d28554a | 2016-01-11 16:22:59 | [diff] [blame] | 20 | import devil_chromium |
[email protected] | 7849a33 | 2013-07-12 01:40:09 | [diff] [blame] | 21 | import provision_devices |
jbudorick | 06162944 | 2015-09-03 18:00:57 | [diff] [blame] | 22 | from devil.android import device_utils |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 23 | from pylib import constants |
jbudorick | 605b893 | 2015-09-18 18:57:39 | [diff] [blame] | 24 | from pylib.gtest import gtest_config |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 25 | |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 26 | CHROME_SRC_DIR = bb_utils.CHROME_SRC |
[email protected] | ae41072 | 2013-10-24 15:57:36 | [diff] [blame] | 27 | DIR_BUILD_ROOT = os.path.dirname(CHROME_SRC_DIR) |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 28 | CHROME_OUT_DIR = bb_utils.CHROME_OUT_DIR |
dpranke | ec3eb0a | 2014-09-26 21:42:56 | [diff] [blame] | 29 | BLINK_SCRIPTS_DIR = 'third_party/WebKit/Tools/Scripts' |
[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] | c79bc8a | 2014-04-24 03:39:52 | [diff] [blame] | 34 | GS_AUTH_URL = 'https://storage.cloud.google.com' |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 35 | |
| 36 | # Describes an instrumation test suite: |
| 37 | # test: Name of test we're running. |
| 38 | # apk: apk to be installed. |
| 39 | # apk_package: package for the apk to be installed. |
| 40 | # test_apk: apk to run tests on. |
| 41 | # test_data: data folder in format destination:source. |
[email protected] | 37ee0c79 | 2013-08-06 19:10:13 | [diff] [blame] | 42 | # host_driven_root: The host-driven test root directory. |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 43 | # annotation: Annotation of the tests to include. |
| 44 | # exclude_annotation: The annotation of the tests to exclude. |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 45 | I_TEST = collections.namedtuple('InstrumentationTest', [ |
jbudorick | e4bb2b8 | 2015-02-09 18:35:00 | [diff] [blame] | 46 | 'name', 'apk', 'apk_package', 'test_apk', 'test_data', 'isolate_file_path', |
| 47 | 'host_driven_root', 'annotation', 'exclude_annotation', 'extra_flags']) |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 48 | |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 49 | |
[email protected] | ae41072 | 2013-10-24 15:57:36 | [diff] [blame] | 50 | def SrcPath(*path): |
| 51 | return os.path.join(CHROME_SRC_DIR, *path) |
| 52 | |
jbudorick | 605b893 | 2015-09-18 18:57:39 | [diff] [blame] | 53 | |
jbudorick | e4bb2b8 | 2015-02-09 18:35:00 | [diff] [blame] | 54 | def I(name, apk, apk_package, test_apk, test_data, isolate_file_path=None, |
| 55 | host_driven_root=None, annotation=None, exclude_annotation=None, |
| 56 | extra_flags=None): |
| 57 | return I_TEST(name, apk, apk_package, test_apk, test_data, isolate_file_path, |
| 58 | host_driven_root, annotation, exclude_annotation, extra_flags) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 59 | |
| 60 | INSTRUMENTATION_TESTS = dict((suite.name, suite) for suite in [ |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 61 | I('ContentShell', |
| 62 | 'ContentShell.apk', |
| 63 | 'org.chromium.content_shell_apk', |
jbudorick | 3490213 | 2014-12-09 14:24:56 | [diff] [blame] | 64 | 'ContentShellTest', |
jbudorick | e4bb2b8 | 2015-02-09 18:35:00 | [diff] [blame] | 65 | 'content:content/test/data/android/device_files', |
stip | 5d2e8c4 | 2016-04-25 23:38:17 | [diff] [blame] | 66 | isolate_file_path='content/content_shell_test_data.isolate'), |
gmanikpure | 84279572 | 2015-09-16 00:07:29 | [diff] [blame] | 67 | I('ChromePublic', |
| 68 | 'ChromePublic.apk', |
| 69 | 'org.chromium.chrome', |
| 70 | 'ChromePublicTest', |
| 71 | 'chrome:chrome/test/data/android/device_files', |
| 72 | isolate_file_path='chrome/chrome_public_test_apk.isolate'), |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 73 | I('AndroidWebView', |
| 74 | 'AndroidWebView.apk', |
| 75 | 'org.chromium.android_webview.shell', |
jbudorick | 3490213 | 2014-12-09 14:24:56 | [diff] [blame] | 76 | 'AndroidWebViewTest', |
jbudorick | e4bb2b8 | 2015-02-09 18:35:00 | [diff] [blame] | 77 | 'webview:android_webview/test/data/device_files', |
stip | 5274ed6 | 2016-04-26 21:14:54 | [diff] [blame] | 78 | isolate_file_path='android_webview/android_webview_test_data.isolate'), |
mikecase | 94c8f1ad3b | 2014-10-27 23:09:36 | [diff] [blame] | 79 | I('ChromeSyncShell', |
| 80 | 'ChromeSyncShell.apk', |
| 81 | 'org.chromium.chrome.browser.sync', |
jbudorick | 3490213 | 2014-12-09 14:24:56 | [diff] [blame] | 82 | 'ChromeSyncShellTest', |
| 83 | None), |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 84 | ]) |
| 85 | |
jbudorick | c574b1b | 2014-12-04 18:21:28 | [diff] [blame] | 86 | InstallablePackage = collections.namedtuple('InstallablePackage', [ |
| 87 | 'name', 'apk', 'apk_package']) |
| 88 | |
| 89 | INSTALLABLE_PACKAGES = dict((package.name, package) for package in ( |
| 90 | [InstallablePackage(i.name, i.apk, i.apk_package) |
| 91 | for i in INSTRUMENTATION_TESTS.itervalues()] + |
| 92 | [InstallablePackage('ChromeDriverWebViewShell', |
| 93 | 'ChromeDriverWebViewShell.apk', |
| 94 | 'org.chromium.chromedriver_webview_shell')])) |
| 95 | |
jbudorick | 71a2498 | 2015-05-11 19:12:56 | [diff] [blame] | 96 | VALID_TESTS = set([ |
| 97 | 'base_junit_tests', |
| 98 | 'chromedriver', |
jbudorick | 71a2498 | 2015-05-11 19:12:56 | [diff] [blame] | 99 | 'components_browsertests', |
| 100 | 'gfx_unittests', |
dyen | 35c791f | 2015-05-12 19:25:13 | [diff] [blame] | 101 | 'gl_unittests', |
jbudorick | 71a2498 | 2015-05-11 19:12:56 | [diff] [blame] | 102 | 'gpu', |
| 103 | 'python_unittests', |
jbudorick | 71a2498 | 2015-05-11 19:12:56 | [diff] [blame] | 104 | 'ui', |
| 105 | 'unit', |
| 106 | 'webkit', |
| 107 | 'webkit_layout' |
| 108 | ]) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 109 | |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 110 | RunCmd = bb_utils.RunCmd |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 111 | |
| 112 | |
[email protected] | e7bd341 | 2013-09-20 17:15:28 | [diff] [blame] | 113 | def _GetRevision(options): |
| 114 | """Get the SVN revision number. |
| 115 | |
| 116 | Args: |
| 117 | options: options object. |
| 118 | |
| 119 | Returns: |
| 120 | The revision number. |
| 121 | """ |
| 122 | revision = options.build_properties.get('got_revision') |
| 123 | if not revision: |
| 124 | revision = options.build_properties.get('revision', 'testing') |
| 125 | return revision |
| 126 | |
| 127 | |
[email protected] | f762c120 | 2014-08-13 09:36:34 | [diff] [blame] | 128 | def _RunTest(options, cmd, suite): |
| 129 | """Run test command with runtest.py. |
| 130 | |
| 131 | Args: |
| 132 | options: options object. |
| 133 | cmd: the command to run. |
| 134 | suite: test name. |
| 135 | """ |
| 136 | property_args = bb_utils.EncodeProperties(options) |
| 137 | args = [os.path.join(SLAVE_SCRIPTS_DIR, 'runtest.py')] + property_args |
| 138 | args += ['--test-platform', 'android'] |
| 139 | if options.factory_properties.get('generate_gtest_json'): |
| 140 | args.append('--generate-json-file') |
| 141 | args += ['-o', 'gtest-results/%s' % suite, |
| 142 | '--annotate', 'gtest', |
| 143 | '--build-number', str(options.build_properties.get('buildnumber', |
| 144 | '')), |
| 145 | '--builder-name', options.build_properties.get('buildername', '')] |
| 146 | if options.target == 'Release': |
| 147 | args += ['--target', 'Release'] |
| 148 | else: |
| 149 | args += ['--target', 'Debug'] |
mikecase | 97d50b6 | 2014-11-14 18:33:52 | [diff] [blame] | 150 | if options.flakiness_server: |
| 151 | args += ['--flakiness-dashboard-server=%s' % |
| 152 | options.flakiness_server] |
[email protected] | f762c120 | 2014-08-13 09:36:34 | [diff] [blame] | 153 | args += cmd |
| 154 | RunCmd(args, cwd=DIR_BUILD_ROOT) |
| 155 | |
| 156 | |
[email protected] | 0ceb1499 | 2014-05-24 00:37:26 | [diff] [blame] | 157 | def RunTestSuites(options, suites, suites_options=None): |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 158 | """Manages an invocation of test_runner.py for gtests. |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 159 | |
| 160 | Args: |
| 161 | options: options object. |
[email protected] | 9e68925 | 2013-07-30 20:14:36 | [diff] [blame] | 162 | suites: List of suite names to run. |
[email protected] | 0ceb1499 | 2014-05-24 00:37:26 | [diff] [blame] | 163 | suites_options: Command line options dictionary for particular suites. |
| 164 | For example, |
| 165 | {'content_browsertests', ['--num_retries=1', '--release']} |
| 166 | will add the options only to content_browsertests. |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 167 | """ |
[email protected] | 0ceb1499 | 2014-05-24 00:37:26 | [diff] [blame] | 168 | |
| 169 | if not suites_options: |
| 170 | suites_options = {} |
| 171 | |
jbudorick | a583ba3 | 2015-09-11 17:23:19 | [diff] [blame] | 172 | args = ['--verbose', '--blacklist-file', 'out/bad_devices.json'] |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 173 | if options.target == 'Release': |
| 174 | args.append('--release') |
| 175 | if options.asan: |
| 176 | args.append('--tool=asan') |
[email protected] | 18d59b8 | 2013-11-12 09:21:41 | [diff] [blame] | 177 | if options.gtest_filter: |
| 178 | args.append('--gtest-filter=%s' % options.gtest_filter) |
[email protected] | 0ceb1499 | 2014-05-24 00:37:26 | [diff] [blame] | 179 | |
[email protected] | a8fea93f | 2013-01-10 04:00:07 | [diff] [blame] | 180 | for suite in suites: |
[email protected] | 9e68925 | 2013-07-30 20:14:36 | [diff] [blame] | 181 | bb_annotations.PrintNamedStep(suite) |
[email protected] | f762c120 | 2014-08-13 09:36:34 | [diff] [blame] | 182 | cmd = [suite] + args |
[email protected] | 0ceb1499 | 2014-05-24 00:37:26 | [diff] [blame] | 183 | cmd += suites_options.get(suite, []) |
jbudorick | c4b6b651 | 2015-04-23 21:30:28 | [diff] [blame] | 184 | if suite == 'content_browsertests' or suite == 'components_browsertests': |
[email protected] | 9e68925 | 2013-07-30 20:14:36 | [diff] [blame] | 185 | cmd.append('--num_retries=1') |
[email protected] | f762c120 | 2014-08-13 09:36:34 | [diff] [blame] | 186 | _RunTest(options, cmd, suite) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 187 | |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 188 | |
jbudorick | 8548f23e | 2015-05-11 14:08:14 | [diff] [blame] | 189 | def RunJunitSuite(suite): |
jbudorick | 08e45a9 | 2015-05-11 21:27:03 | [diff] [blame] | 190 | bb_annotations.PrintNamedStep(suite) |
jbudorick | 8548f23e | 2015-05-11 14:08:14 | [diff] [blame] | 191 | RunCmd(['build/android/test_runner.py', 'junit', '-s', suite]) |
| 192 | |
| 193 | |
[email protected] | e7bd341 | 2013-09-20 17:15:28 | [diff] [blame] | 194 | def RunChromeDriverTests(options): |
[email protected] | d8897f6c | 2013-03-05 00:27:16 | [diff] [blame] | 195 | """Run all the steps for running chromedriver tests.""" |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 196 | bb_annotations.PrintNamedStep('chromedriver_annotation') |
[email protected] | d8897f6c | 2013-03-05 00:27:16 | [diff] [blame] | 197 | RunCmd(['chrome/test/chromedriver/run_buildbot_steps.py', |
gmanikpure | 84279572 | 2015-09-16 00:07:29 | [diff] [blame] | 198 | '--android-packages=%s,%s,%s,%s' % |
| 199 | ('chromium', |
| 200 | 'chrome_stable', |
[email protected] | b1010d26 | 2013-11-27 22:01:28 | [diff] [blame] | 201 | 'chrome_beta', |
| 202 | 'chromedriver_webview_shell'), |
[email protected] | e7bd341 | 2013-09-20 17:15:28 | [diff] [blame] | 203 | '--revision=%s' % _GetRevision(options), |
[email protected] | fde0700 | 2013-09-20 21:02:39 | [diff] [blame] | 204 | '--update-log']) |
[email protected] | d8897f6c | 2013-03-05 00:27:16 | [diff] [blame] | 205 | |
[email protected] | 29f7e7c | 2014-04-24 00:55:22 | [diff] [blame] | 206 | |
[email protected] | a2a72524 | 2013-01-09 21:52:57 | [diff] [blame] | 207 | def InstallApk(options, test, print_step=False): |
| 208 | """Install an apk to all phones. |
| 209 | |
| 210 | Args: |
| 211 | options: options object |
| 212 | test: An I_TEST namedtuple |
| 213 | print_step: Print a buildbot step |
| 214 | """ |
| 215 | if print_step: |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 216 | bb_annotations.PrintNamedStep('install_%s' % test.name.lower()) |
[email protected] | 6ca5751 | 2013-08-23 21:42:04 | [diff] [blame] | 217 | |
jbudorick | a583ba3 | 2015-09-11 17:23:19 | [diff] [blame] | 218 | args = [ |
| 219 | '--apk_package', test.apk_package, |
| 220 | '--blacklist-file', 'out/bad_devices.json', |
| 221 | ] |
[email protected] | a2a72524 | 2013-01-09 21:52:57 | [diff] [blame] | 222 | if options.target == 'Release': |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 223 | args.append('--release') |
[email protected] | 068b9cb4 | 2014-06-08 20:11:16 | [diff] [blame] | 224 | args.append(test.apk) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 225 | |
[email protected] | 800673bf | 2013-05-14 17:15:30 | [diff] [blame] | 226 | RunCmd(['build/android/adb_install_apk.py'] + args, halt_on_failure=True) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 227 | |
| 228 | |
[email protected] | acfaf4c | 2013-07-25 00:23:56 | [diff] [blame] | 229 | def RunInstrumentationSuite(options, test, flunk_on_failure=True, |
[email protected] | 54c2d53 | 2013-08-24 01:36:24 | [diff] [blame] | 230 | python_only=False, official_build=False): |
[email protected] | fbe2932 | 2013-07-09 09:03:26 | [diff] [blame] | 231 | """Manages an invocation of test_runner.py for instrumentation tests. |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 232 | |
| 233 | Args: |
| 234 | options: options object |
| 235 | test: An I_TEST namedtuple |
[email protected] | acfaf4c | 2013-07-25 00:23:56 | [diff] [blame] | 236 | flunk_on_failure: Flunk the step if tests fail. |
| 237 | Python: Run only host driven Python tests. |
[email protected] | 54c2d53 | 2013-08-24 01:36:24 | [diff] [blame] | 238 | official_build: Run official-build tests. |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 239 | """ |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 240 | bb_annotations.PrintNamedStep('%s_instrumentation_tests' % test.name.lower()) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 241 | |
[email protected] | 10955d3 | 2014-04-30 11:22:41 | [diff] [blame] | 242 | if test.apk: |
| 243 | InstallApk(options, test) |
jbudorick | a583ba3 | 2015-09-11 17:23:19 | [diff] [blame] | 244 | args = [ |
| 245 | '--test-apk', test.test_apk, '--verbose', |
| 246 | '--blacklist-file', 'out/bad_devices.json' |
| 247 | ] |
[email protected] | 10955d3 | 2014-04-30 11:22:41 | [diff] [blame] | 248 | if test.test_data: |
| 249 | args.extend(['--test_data', test.test_data]) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 250 | if options.target == 'Release': |
| 251 | args.append('--release') |
| 252 | if options.asan: |
| 253 | args.append('--tool=asan') |
[email protected] | 14f139f4 | 2013-07-24 18:41:58 | [diff] [blame] | 254 | if options.flakiness_server: |
[email protected] | b796a77 | 2013-01-19 03:55:22 | [diff] [blame] | 255 | args.append('--flakiness-dashboard-server=%s' % |
[email protected] | 14f139f4 | 2013-07-24 18:41:58 | [diff] [blame] | 256 | options.flakiness_server) |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 257 | if options.coverage_bucket: |
| 258 | args.append('--coverage-dir=%s' % options.coverage_dir) |
jbudorick | e4bb2b8 | 2015-02-09 18:35:00 | [diff] [blame] | 259 | if test.isolate_file_path: |
| 260 | args.append('--isolate-file-path=%s' % test.isolate_file_path) |
[email protected] | 8d8ca04 | 2013-02-14 19:29:17 | [diff] [blame] | 261 | if test.host_driven_root: |
[email protected] | 67954f82 | 2013-08-14 18:09:08 | [diff] [blame] | 262 | args.append('--host-driven-root=%s' % test.host_driven_root) |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 263 | if test.annotation: |
| 264 | args.extend(['-A', test.annotation]) |
| 265 | if test.exclude_annotation: |
| 266 | args.extend(['-E', test.exclude_annotation]) |
| 267 | if test.extra_flags: |
| 268 | args.extend(test.extra_flags) |
[email protected] | acfaf4c | 2013-07-25 00:23:56 | [diff] [blame] | 269 | if python_only: |
| 270 | args.append('-p') |
[email protected] | 54c2d53 | 2013-08-24 01:36:24 | [diff] [blame] | 271 | if official_build: |
| 272 | # The option needs to be assigned 'True' as it does not have an action |
| 273 | # associated with it. |
| 274 | args.append('--official-build') |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 275 | |
[email protected] | bdd22ff | 2013-07-17 17:21:12 | [diff] [blame] | 276 | RunCmd(['build/android/test_runner.py', 'instrumentation'] + args, |
| 277 | flunk_on_failure=flunk_on_failure) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 278 | |
| 279 | |
fdegans | 7b06b61 | 2014-09-26 09:50:53 | [diff] [blame] | 280 | def RunWebkitLint(): |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 281 | """Lint WebKit's TestExpectation files.""" |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 282 | bb_annotations.PrintNamedStep('webkit_lint') |
dpranke | ec3eb0a | 2014-09-26 21:42:56 | [diff] [blame] | 283 | RunCmd([SrcPath(os.path.join(BLINK_SCRIPTS_DIR, 'lint-test-expectations'))]) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 284 | |
| 285 | |
| 286 | def RunWebkitLayoutTests(options): |
| 287 | """Run layout tests on an actual device.""" |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 288 | bb_annotations.PrintNamedStep('webkit_tests') |
[email protected] | 22ee700 | 2013-01-23 20:58:04 | [diff] [blame] | 289 | cmd_args = [ |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 290 | '--no-show-results', |
| 291 | '--no-new-test-results', |
| 292 | '--full-results-html', |
| 293 | '--clobber-old-results', |
| 294 | '--exit-after-n-failures', '5000', |
| 295 | '--exit-after-n-crashes-or-timeouts', '100', |
| 296 | '--debug-rwt-logging', |
| 297 | '--results-directory', '../layout-test-results', |
| 298 | '--target', options.target, |
| 299 | '--builder-name', options.build_properties.get('buildername', ''), |
| 300 | '--build-number', str(options.build_properties.get('buildnumber', '')), |
| 301 | '--master-name', 'ChromiumWebkit', # TODO: Get this from the cfg. |
| 302 | '--build-name', options.build_properties.get('buildername', ''), |
| 303 | '--platform=android'] |
[email protected] | 22ee700 | 2013-01-23 20:58:04 | [diff] [blame] | 304 | |
hendrikw | 1904804a | 2015-04-17 18:44:51 | [diff] [blame] | 305 | for flag in 'test_results_server', 'driver_name', 'additional_driver_flag': |
[email protected] | 22ee700 | 2013-01-23 20:58:04 | [diff] [blame] | 306 | if flag in options.factory_properties: |
| 307 | cmd_args.extend(['--%s' % flag.replace('_', '-'), |
| 308 | options.factory_properties.get(flag)]) |
| 309 | |
[email protected] | 2c39b29 | 2013-03-20 09:34:10 | [diff] [blame] | 310 | for f in options.factory_properties.get('additional_expectations', []): |
| 311 | cmd_args.extend( |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 312 | ['--additional-expectations=%s' % os.path.join(CHROME_SRC_DIR, *f)]) |
[email protected] | 2c39b29 | 2013-03-20 09:34:10 | [diff] [blame] | 313 | |
| 314 | # TODO(dpranke): Remove this block after |
| 315 | # https://codereview.chromium.org/12927002/ lands. |
[email protected] | 22ee700 | 2013-01-23 20:58:04 | [diff] [blame] | 316 | for f in options.factory_properties.get('additional_expectations_files', []): |
[email protected] | 62c5b98 | 2013-01-26 08:23:16 | [diff] [blame] | 317 | cmd_args.extend( |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 318 | ['--additional-expectations=%s' % os.path.join(CHROME_SRC_DIR, *f)]) |
[email protected] | 22ee700 | 2013-01-23 20:58:04 | [diff] [blame] | 319 | |
ager | 158f284 | 2014-09-26 06:07:24 | [diff] [blame] | 320 | exit_code = RunCmd( |
dpranke | ec3eb0a | 2014-09-26 21:42:56 | [diff] [blame] | 321 | [SrcPath(os.path.join(BLINK_SCRIPTS_DIR, 'run-webkit-tests'))] + cmd_args) |
[email protected] | 1782ef4 | 2013-10-18 21:07:33 | [diff] [blame] | 322 | if exit_code == 255: # test_run_results.UNEXPECTED_ERROR_EXIT_STATUS |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 323 | bb_annotations.PrintMsg('?? (crashed or hung)') |
[email protected] | 1782ef4 | 2013-10-18 21:07:33 | [diff] [blame] | 324 | elif exit_code == 254: # test_run_results.NO_DEVICES_EXIT_STATUS |
[email protected] | 361229ac | 2013-10-17 18:57:15 | [diff] [blame] | 325 | bb_annotations.PrintMsg('?? (no devices found)') |
[email protected] | 1782ef4 | 2013-10-18 21:07:33 | [diff] [blame] | 326 | elif exit_code == 253: # test_run_results.NO_TESTS_EXIT_STATUS |
[email protected] | 361229ac | 2013-10-17 18:57:15 | [diff] [blame] | 327 | bb_annotations.PrintMsg('?? (no tests found)') |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 328 | else: |
| 329 | full_results_path = os.path.join('..', 'layout-test-results', |
| 330 | 'full_results.json') |
| 331 | if os.path.exists(full_results_path): |
| 332 | full_results = json.load(open(full_results_path)) |
[email protected] | e2782b8 | 2013-10-14 19:43:45 | [diff] [blame] | 333 | unexpected_passes, unexpected_failures, unexpected_flakes = ( |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 334 | _ParseLayoutTestResults(full_results)) |
| 335 | if unexpected_failures: |
dpranke | d7cae31 | 2015-02-08 02:40:54 | [diff] [blame] | 336 | _PrintDashboardLink('failed', unexpected_failures.keys(), |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 337 | max_tests=25) |
| 338 | elif unexpected_passes: |
dpranke | d7cae31 | 2015-02-08 02:40:54 | [diff] [blame] | 339 | _PrintDashboardLink('unexpected passes', unexpected_passes.keys(), |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 340 | max_tests=10) |
| 341 | if unexpected_flakes: |
dpranke | d7cae31 | 2015-02-08 02:40:54 | [diff] [blame] | 342 | _PrintDashboardLink('unexpected flakes', unexpected_flakes.keys(), |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 343 | max_tests=10) |
[email protected] | bc14cb1 | 2013-10-10 18:47:14 | [diff] [blame] | 344 | |
| 345 | if exit_code == 0 and (unexpected_passes or unexpected_flakes): |
| 346 | # If exit_code != 0, RunCmd() will have already printed an error. |
| 347 | bb_annotations.PrintWarning() |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 348 | else: |
[email protected] | bc14cb1 | 2013-10-10 18:47:14 | [diff] [blame] | 349 | bb_annotations.PrintError() |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 350 | bb_annotations.PrintMsg('?? (results missing)') |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 351 | |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 352 | if options.factory_properties.get('archive_webkit_results', False): |
| 353 | bb_annotations.PrintNamedStep('archive_webkit_results') |
[email protected] | 613e5a3 | 2013-09-18 01:46:32 | [diff] [blame] | 354 | base = 'https://storage.googleapis.com/chromium-layout-test-archives' |
| 355 | builder_name = options.build_properties.get('buildername', '') |
| 356 | build_number = str(options.build_properties.get('buildnumber', '')) |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 357 | results_link = '%s/%s/%s/layout-test-results/results.html' % ( |
| 358 | base, EscapeBuilderName(builder_name), build_number) |
| 359 | bb_annotations.PrintLink('results', results_link) |
[email protected] | e2107bd | 2013-09-18 05:13:10 | [diff] [blame] | 360 | bb_annotations.PrintLink('(zip)', '%s/%s/%s/layout-test-results.zip' % ( |
| 361 | base, EscapeBuilderName(builder_name), build_number)) |
[email protected] | 85db7daf3 | 2013-09-09 21:21:25 | [diff] [blame] | 362 | gs_bucket = 'gs://chromium-layout-test-archives' |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 363 | RunCmd([os.path.join(SLAVE_SCRIPTS_DIR, 'chromium', |
| 364 | 'archive_layout_test_results.py'), |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 365 | '--results-dir', '../../layout-test-results', |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 366 | '--build-number', build_number, |
| 367 | '--builder-name', builder_name, |
[email protected] | ae41072 | 2013-10-24 15:57:36 | [diff] [blame] | 368 | '--gs-bucket', gs_bucket], |
| 369 | cwd=DIR_BUILD_ROOT) |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 370 | |
| 371 | |
| 372 | def _ParseLayoutTestResults(results): |
| 373 | """Extract the failures from the test run.""" |
| 374 | # Cloned from third_party/WebKit/Tools/Scripts/print-json-test-results |
| 375 | tests = _ConvertTrieToFlatPaths(results['tests']) |
| 376 | failures = {} |
| 377 | flakes = {} |
| 378 | passes = {} |
| 379 | for (test, result) in tests.iteritems(): |
| 380 | if result.get('is_unexpected'): |
[email protected] | ff81fe11 | 2013-10-22 21:13:16 | [diff] [blame] | 381 | actual_results = result['actual'].split() |
| 382 | expected_results = result['expected'].split() |
| 383 | if len(actual_results) > 1: |
| 384 | # We report the first failure type back, even if the second |
| 385 | # was more severe. |
| 386 | if actual_results[1] in expected_results: |
| 387 | flakes[test] = actual_results[0] |
| 388 | else: |
| 389 | failures[test] = actual_results[0] |
| 390 | elif actual_results[0] == 'PASS': |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 391 | passes[test] = result |
| 392 | else: |
[email protected] | ff81fe11 | 2013-10-22 21:13:16 | [diff] [blame] | 393 | failures[test] = actual_results[0] |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 394 | |
| 395 | return (passes, failures, flakes) |
| 396 | |
| 397 | |
| 398 | def _ConvertTrieToFlatPaths(trie, prefix=None): |
| 399 | """Flatten the trie of failures into a list.""" |
| 400 | # Cloned from third_party/WebKit/Tools/Scripts/print-json-test-results |
| 401 | result = {} |
| 402 | for name, data in trie.iteritems(): |
| 403 | if prefix: |
| 404 | name = prefix + '/' + name |
| 405 | |
| 406 | if len(data) and 'actual' not in data and 'expected' not in data: |
| 407 | result.update(_ConvertTrieToFlatPaths(data, name)) |
| 408 | else: |
| 409 | result[name] = data |
| 410 | |
| 411 | return result |
| 412 | |
| 413 | |
| 414 | def _PrintDashboardLink(link_text, tests, max_tests): |
| 415 | """Add a link to the flakiness dashboard in the step annotations.""" |
| 416 | if len(tests) > max_tests: |
| 417 | test_list_text = ' '.join(tests[:max_tests]) + ' and more' |
| 418 | else: |
| 419 | test_list_text = ' '.join(tests) |
| 420 | |
| 421 | dashboard_base = ('http://test-results.appspot.com' |
| 422 | '/dashboards/flakiness_dashboard.html#' |
| 423 | 'master=ChromiumWebkit&tests=') |
| 424 | |
| 425 | bb_annotations.PrintLink('%d %s: %s' % |
| 426 | (len(tests), link_text, test_list_text), |
| 427 | dashboard_base + ','.join(tests)) |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 428 | |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 429 | |
[email protected] | e2107bd | 2013-09-18 05:13:10 | [diff] [blame] | 430 | def EscapeBuilderName(builder_name): |
| 431 | return re.sub('[ ()]', '_', builder_name) |
| 432 | |
| 433 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 434 | def SpawnLogcatMonitor(): |
| 435 | shutil.rmtree(LOGCAT_DIR, ignore_errors=True) |
[email protected] | 97d1032 | 2013-10-04 20:53:04 | [diff] [blame] | 436 | bb_utils.SpawnCmd([ |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 437 | os.path.join(CHROME_SRC_DIR, 'build', 'android', 'adb_logcat_monitor.py'), |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 438 | LOGCAT_DIR]) |
| 439 | |
| 440 | # Wait for logcat_monitor to pull existing logcat |
| 441 | RunCmd(['sleep', '5']) |
| 442 | |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 443 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 444 | def ProvisionDevices(options): |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 445 | bb_annotations.PrintNamedStep('provision_devices') |
[email protected] | abfec37 | 2013-08-16 07:22:16 | [diff] [blame] | 446 | |
| 447 | if not bb_utils.TESTING: |
| 448 | # Restart adb to work around bugs, sleep to wait for usb discovery. |
[email protected] | 781c58a | 2014-05-14 05:32:16 | [diff] [blame] | 449 | device_utils.RestartServer() |
[email protected] | abfec37 | 2013-08-16 07:22:16 | [diff] [blame] | 450 | RunCmd(['sleep', '1']) |
jbudorick | a583ba3 | 2015-09-11 17:23:19 | [diff] [blame] | 451 | provision_cmd = [ |
| 452 | 'build/android/provision_devices.py', '-t', options.target, |
| 453 | '--blacklist-file', 'out/bad_devices.json' |
| 454 | ] |
[email protected] | 7849a33 | 2013-07-12 01:40:09 | [diff] [blame] | 455 | if options.auto_reconnect: |
| 456 | provision_cmd.append('--auto-reconnect') |
[email protected] | 3356038b | 2014-06-17 02:40:13 | [diff] [blame] | 457 | if options.skip_wipe: |
| 458 | provision_cmd.append('--skip-wipe') |
jbudorick | 9669e5b | 2015-03-09 16:29:07 | [diff] [blame] | 459 | if options.disable_location: |
| 460 | provision_cmd.append('--disable-location') |
[email protected] | 7b54a872 | 2014-07-17 21:51:21 | [diff] [blame] | 461 | RunCmd(provision_cmd, halt_on_failure=True) |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 462 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 463 | |
[email protected] | e5d85a7 | 2013-10-19 13:44:02 | [diff] [blame] | 464 | def DeviceStatusCheck(options): |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 465 | bb_annotations.PrintNamedStep('device_status_check') |
jbudorick | a583ba3 | 2015-09-11 17:23:19 | [diff] [blame] | 466 | cmd = [ |
| 467 | 'build/android/buildbot/bb_device_status_check.py', |
| 468 | '--blacklist-file', 'out/bad_devices.json', |
| 469 | ] |
[email protected] | e5d85a7 | 2013-10-19 13:44:02 | [diff] [blame] | 470 | if options.restart_usb: |
| 471 | cmd.append('--restart-usb') |
| 472 | RunCmd(cmd, halt_on_failure=True) |
[email protected] | 693c54d | 2013-01-09 19:41:25 | [diff] [blame] | 473 | |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 474 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 475 | def GetDeviceSetupStepCmds(): |
| 476 | return [ |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 477 | ('device_status_check', DeviceStatusCheck), |
[email protected] | 917cd320b | 2013-12-03 16:13:35 | [diff] [blame] | 478 | ('provision_devices', ProvisionDevices), |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 479 | ] |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 480 | |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 481 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 482 | def RunUnitTests(options): |
jbudorick | 605b893 | 2015-09-18 18:57:39 | [diff] [blame] | 483 | suites = gtest_config.STABLE_TEST_SUITES |
[email protected] | 502362c7 | 2014-02-26 07:06:44 | [diff] [blame] | 484 | if options.asan: |
| 485 | suites = [s for s in suites |
jbudorick | 605b893 | 2015-09-18 18:57:39 | [diff] [blame] | 486 | if s not in gtest_config.ASAN_EXCLUDED_TEST_SUITES] |
[email protected] | 502362c7 | 2014-02-26 07:06:44 | [diff] [blame] | 487 | RunTestSuites(options, suites) |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 488 | |
| 489 | |
| 490 | def RunInstrumentationTests(options): |
| 491 | for test in INSTRUMENTATION_TESTS.itervalues(): |
| 492 | RunInstrumentationSuite(options, test) |
| 493 | |
| 494 | |
| 495 | def RunWebkitTests(options): |
[email protected] | 130d0b57 | 2014-02-03 18:09:01 | [diff] [blame] | 496 | RunTestSuites(options, ['webkit_unit_tests', 'blink_heap_unittests']) |
fdegans | 7b06b61 | 2014-09-26 09:50:53 | [diff] [blame] | 497 | RunWebkitLint() |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 498 | |
| 499 | |
[email protected] | a4b1ec97 | 2013-09-14 05:36:25 | [diff] [blame] | 500 | def RunGPUTests(options): |
bpastene | d20f477 | 2016-04-20 15:37:58 | [diff] [blame] | 501 | exit_code = 0 |
[email protected] | 9047cd18 | 2014-05-29 01:04:06 | [diff] [blame] | 502 | revision = _GetRevision(options) |
[email protected] | 5117f5d | 2014-05-29 16:59:16 | [diff] [blame] | 503 | builder_name = options.build_properties.get('buildername', 'noname') |
| 504 | |
| 505 | bb_annotations.PrintNamedStep('pixel_tests') |
bpastene | d20f477 | 2016-04-20 15:37:58 | [diff] [blame] | 506 | exit_code = RunCmd(['content/test/gpu/run_gpu_test.py', |
| 507 | 'pixel', '-v', |
| 508 | '--browser', |
| 509 | 'android-content-shell', |
| 510 | '--build-revision', |
| 511 | str(revision), |
| 512 | '--upload-refimg-to-cloud-storage', |
| 513 | '--refimg-cloud-storage-bucket', |
| 514 | 'chromium-gpu-archive/reference-images', |
| 515 | '--os-type', |
| 516 | 'android', |
| 517 | '--test-machine-name', |
| 518 | EscapeBuilderName(builder_name), |
| 519 | '--android-blacklist-file', |
| 520 | 'out/bad_devices.json']) or exit_code |
[email protected] | fb9cd4bb | 2013-10-16 21:59:53 | [diff] [blame] | 521 | |
[email protected] | cce70f0 | 2013-10-15 12:53:19 | [diff] [blame] | 522 | bb_annotations.PrintNamedStep('webgl_conformance_tests') |
bpastene | d20f477 | 2016-04-20 15:37:58 | [diff] [blame] | 523 | exit_code = RunCmd(['content/test/gpu/run_gpu_test.py', '-v', |
| 524 | '--browser=android-content-shell', 'webgl_conformance', |
| 525 | '--webgl-conformance-version=1.0.1', |
| 526 | '--android-blacklist-file', |
| 527 | 'out/bad_devices.json']) or exit_code |
[email protected] | bb508f8 | 2013-09-06 06:42:24 | [diff] [blame] | 528 | |
sievers | b44610f | 2015-05-05 23:06:17 | [diff] [blame] | 529 | bb_annotations.PrintNamedStep('android_webview_webgl_conformance_tests') |
bpastene | d20f477 | 2016-04-20 15:37:58 | [diff] [blame] | 530 | exit_code = RunCmd(['content/test/gpu/run_gpu_test.py', '-v', |
| 531 | '--browser=android-webview-shell', 'webgl_conformance', |
| 532 | '--webgl-conformance-version=1.0.1', |
| 533 | '--android-blacklist-file', |
| 534 | 'out/bad_devices.json']) or exit_code |
sievers | b44610f | 2015-05-05 23:06:17 | [diff] [blame] | 535 | |
[email protected] | 876cb60 | 2014-05-31 04:49:15 | [diff] [blame] | 536 | bb_annotations.PrintNamedStep('gpu_rasterization_tests') |
bpastene | d20f477 | 2016-04-20 15:37:58 | [diff] [blame] | 537 | exit_code = RunCmd(['content/test/gpu/run_gpu_test.py', |
| 538 | 'gpu_rasterization', '-v', |
| 539 | '--browser', |
| 540 | 'android-content-shell', |
| 541 | '--build-revision', |
| 542 | str(revision), |
| 543 | '--test-machine-name', |
| 544 | EscapeBuilderName(builder_name), |
| 545 | '--android-blacklist-file', |
| 546 | 'out/bad_devices.json']) or exit_code |
| 547 | |
| 548 | return exit_code |
[email protected] | 876cb60 | 2014-05-31 04:49:15 | [diff] [blame] | 549 | |
[email protected] | bb508f8 | 2013-09-06 06:42:24 | [diff] [blame] | 550 | |
jbudorick | 256fd53 | 2014-10-24 01:50:13 | [diff] [blame] | 551 | def RunPythonUnitTests(_options): |
| 552 | for suite in constants.PYTHON_UNIT_TEST_SUITES: |
| 553 | bb_annotations.PrintNamedStep(suite) |
| 554 | RunCmd(['build/android/test_runner.py', 'python', '-s', suite]) |
| 555 | |
| 556 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 557 | def GetTestStepCmds(): |
| 558 | return [ |
jbudorick | 8548f23e | 2015-05-11 14:08:14 | [diff] [blame] | 559 | ('base_junit_tests', |
| 560 | lambda _options: RunJunitSuite('base_junit_tests')), |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 561 | ('chromedriver', RunChromeDriverTests), |
jbudorick | c4b6b651 | 2015-04-23 21:30:28 | [diff] [blame] | 562 | ('components_browsertests', |
| 563 | lambda options: RunTestSuites(options, ['components_browsertests'])), |
tfarina | 43d9353 | 2015-05-11 18:04:07 | [diff] [blame] | 564 | ('gfx_unittests', |
| 565 | lambda options: RunTestSuites(options, ['gfx_unittests'])), |
dyen | 35c791f | 2015-05-12 19:25:13 | [diff] [blame] | 566 | ('gl_unittests', |
| 567 | lambda options: RunTestSuites(options, ['gl_unittests'])), |
[email protected] | bb508f8 | 2013-09-06 06:42:24 | [diff] [blame] | 568 | ('gpu', RunGPUTests), |
jbudorick | 256fd53 | 2014-10-24 01:50:13 | [diff] [blame] | 569 | ('python_unittests', RunPythonUnitTests), |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 570 | ('ui', RunInstrumentationTests), |
mikecase | 0178d48 | 2014-08-27 21:58:18 | [diff] [blame] | 571 | ('unit', RunUnitTests), |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 572 | ('webkit', RunWebkitTests), |
[email protected] | 02bfada | 2013-08-12 05:00:52 | [diff] [blame] | 573 | ('webkit_layout', RunWebkitLayoutTests), |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 574 | ] |
| 575 | |
| 576 | |
[email protected] | c11a468 | 2014-04-22 23:04:13 | [diff] [blame] | 577 | def MakeGSPath(options, gs_base_dir): |
| 578 | revision = _GetRevision(options) |
| 579 | bot_id = options.build_properties.get('buildername', 'testing') |
| 580 | randhash = hashlib.sha1(str(random.random())).hexdigest() |
| 581 | gs_path = '%s/%s/%s/%s' % (gs_base_dir, bot_id, revision, randhash) |
[email protected] | c79bc8a | 2014-04-24 03:39:52 | [diff] [blame] | 582 | # remove double slashes, happens with blank revisions and confuses gsutil |
| 583 | gs_path = re.sub('/+', '/', gs_path) |
[email protected] | c11a468 | 2014-04-22 23:04:13 | [diff] [blame] | 584 | return gs_path |
| 585 | |
[email protected] | 4e622cee | 2013-09-17 18:32:12 | [diff] [blame] | 586 | def UploadHTML(options, gs_base_dir, dir_to_upload, link_text, |
| 587 | link_rel_path='index.html', gs_url=GS_URL): |
| 588 | """Uploads directory at |dir_to_upload| to Google Storage and output a link. |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 589 | |
| 590 | Args: |
| 591 | options: Command line options. |
[email protected] | 4e622cee | 2013-09-17 18:32:12 | [diff] [blame] | 592 | gs_base_dir: The Google Storage base directory (e.g. |
| 593 | 'chromium-code-coverage/java') |
| 594 | dir_to_upload: Absolute path to the directory to be uploaded. |
| 595 | link_text: Link text to be displayed on the step. |
| 596 | link_rel_path: Link path relative to |dir_to_upload|. |
| 597 | gs_url: Google storage URL. |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 598 | """ |
[email protected] | c11a468 | 2014-04-22 23:04:13 | [diff] [blame] | 599 | gs_path = MakeGSPath(options, gs_base_dir) |
[email protected] | 4e622cee | 2013-09-17 18:32:12 | [diff] [blame] | 600 | RunCmd([bb_utils.GSUTIL_PATH, 'cp', '-R', dir_to_upload, 'gs://%s' % gs_path]) |
| 601 | bb_annotations.PrintLink(link_text, |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 602 | '%s/%s/%s' % (gs_url, gs_path, link_rel_path)) |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 603 | |
| 604 | |
| 605 | def GenerateJavaCoverageReport(options): |
| 606 | """Generates an HTML coverage report using EMMA and uploads it.""" |
| 607 | bb_annotations.PrintNamedStep('java_coverage_report') |
| 608 | |
| 609 | coverage_html = os.path.join(options.coverage_dir, 'coverage_html') |
| 610 | RunCmd(['build/android/generate_emma_html.py', |
| 611 | '--coverage-dir', options.coverage_dir, |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 612 | '--metadata-dir', os.path.join(CHROME_OUT_DIR, options.target), |
[email protected] | a1f1abfe | 2013-08-27 22:02:43 | [diff] [blame] | 613 | '--cleanup', |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 614 | '--output', os.path.join(coverage_html, 'index.html')]) |
[email protected] | 4e622cee | 2013-09-17 18:32:12 | [diff] [blame] | 615 | return coverage_html |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 616 | |
| 617 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 618 | def LogcatDump(options): |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 619 | # Print logcat, kill logcat monitor |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 620 | bb_annotations.PrintNamedStep('logcat_dump') |
[email protected] | 6fe4d06 | 2014-05-03 00:07:30 | [diff] [blame] | 621 | logcat_file = os.path.join(CHROME_OUT_DIR, options.target, 'full_log.txt') |
jbudorick | 0f77e96 | 2014-11-19 15:41:29 | [diff] [blame] | 622 | RunCmd([SrcPath('build', 'android', 'adb_logcat_printer.py'), |
[email protected] | 46e095c | 2013-11-21 13:48:58 | [diff] [blame] | 623 | '--output-path', logcat_file, LOGCAT_DIR]) |
[email protected] | c11a468 | 2014-04-22 23:04:13 | [diff] [blame] | 624 | gs_path = MakeGSPath(options, 'chromium-android/logcat_dumps') |
[email protected] | 6fe4d06 | 2014-05-03 00:07:30 | [diff] [blame] | 625 | RunCmd([bb_utils.GSUTIL_PATH, 'cp', '-z', 'txt', logcat_file, |
| 626 | 'gs://%s' % gs_path]) |
[email protected] | c79bc8a | 2014-04-24 03:39:52 | [diff] [blame] | 627 | bb_annotations.PrintLink('logcat dump', '%s/%s' % (GS_AUTH_URL, gs_path)) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 628 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 629 | |
[email protected] | 79d3d8d8 | 2014-02-05 13:47:04 | [diff] [blame] | 630 | def RunStackToolSteps(options): |
| 631 | """Run stack tool steps. |
| 632 | |
| 633 | Stack tool is run for logcat dump, optionally for ASAN. |
| 634 | """ |
| 635 | bb_annotations.PrintNamedStep('Run stack tool with logcat dump') |
agrieve | a952a11 | 2016-02-09 18:29:44 | [diff] [blame] | 636 | build_dir = os.path.join(CHROME_OUT_DIR, options.target) |
| 637 | logcat_file = os.path.join(build_dir, 'full_log.txt') |
[email protected] | 79d3d8d8 | 2014-02-05 13:47:04 | [diff] [blame] | 638 | RunCmd([os.path.join(CHROME_SRC_DIR, 'third_party', 'android_platform', |
| 639 | 'development', 'scripts', 'stack'), |
agrieve | a952a11 | 2016-02-09 18:29:44 | [diff] [blame] | 640 | '--output-directory', build_dir, |
flackr | a4899418 | 2016-02-08 19:42:24 | [diff] [blame] | 641 | '--more-info', logcat_file]) |
[email protected] | 79d3d8d8 | 2014-02-05 13:47:04 | [diff] [blame] | 642 | if options.asan_symbolize: |
| 643 | bb_annotations.PrintNamedStep('Run stack tool for ASAN') |
| 644 | RunCmd([ |
| 645 | os.path.join(CHROME_SRC_DIR, 'build', 'android', 'asan_symbolize.py'), |
agrieve | a952a11 | 2016-02-09 18:29:44 | [diff] [blame] | 646 | '--output-directory', build_dir, |
flackr | a4899418 | 2016-02-08 19:42:24 | [diff] [blame] | 647 | '-l', logcat_file]) |
[email protected] | 79d3d8d8 | 2014-02-05 13:47:04 | [diff] [blame] | 648 | |
| 649 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 650 | def GenerateTestReport(options): |
[email protected] | b387389 | 2013-07-10 04:57:10 | [diff] [blame] | 651 | bb_annotations.PrintNamedStep('test_report') |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 652 | for report in glob.glob( |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 653 | os.path.join(CHROME_OUT_DIR, options.target, 'test_logs', '*.log')): |
[email protected] | 78af871 | 2013-01-14 10:37:12 | [diff] [blame] | 654 | RunCmd(['cat', report]) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 655 | os.remove(report) |
| 656 | |
| 657 | |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 658 | def MainTestWrapper(options): |
bpastene | d20f477 | 2016-04-20 15:37:58 | [diff] [blame] | 659 | exit_code = 0 |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 660 | try: |
| 661 | # Spawn logcat monitor |
| 662 | SpawnLogcatMonitor() |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 663 | |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 664 | # Run all device setup steps |
| 665 | for _, cmd in GetDeviceSetupStepCmds(): |
| 666 | cmd(options) |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 667 | |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 668 | if options.install: |
jbudorick | 7da88de6 | 2014-12-03 21:46:03 | [diff] [blame] | 669 | for i in options.install: |
jbudorick | c574b1b | 2014-12-04 18:21:28 | [diff] [blame] | 670 | install_obj = INSTALLABLE_PACKAGES[i] |
| 671 | InstallApk(options, install_obj, print_step=True) |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 672 | |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 673 | if options.test_filter: |
bpastene | d20f477 | 2016-04-20 15:37:58 | [diff] [blame] | 674 | exit_code = bb_utils.RunSteps( |
| 675 | options.test_filter, GetTestStepCmds(), options) or exit_code |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 676 | |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 677 | if options.coverage_bucket: |
[email protected] | 4e622cee | 2013-09-17 18:32:12 | [diff] [blame] | 678 | coverage_html = GenerateJavaCoverageReport(options) |
| 679 | UploadHTML(options, '%s/java' % options.coverage_bucket, coverage_html, |
| 680 | 'Coverage Report') |
[email protected] | ec7b222 | 2014-01-16 02:49:15 | [diff] [blame] | 681 | shutil.rmtree(coverage_html, ignore_errors=True) |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 682 | |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 683 | if options.experimental: |
bpastene | d20f477 | 2016-04-20 15:37:58 | [diff] [blame] | 684 | exit_code = RunTestSuites( |
| 685 | options, gtest_config.EXPERIMENTAL_TEST_SUITES) or exit_code |
| 686 | |
| 687 | return exit_code |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 688 | |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 689 | finally: |
| 690 | # Run all post test steps |
| 691 | LogcatDump(options) |
[email protected] | 79d3d8d8 | 2014-02-05 13:47:04 | [diff] [blame] | 692 | if not options.disable_stack_tool: |
| 693 | RunStackToolSteps(options) |
[email protected] | 4cf098c | 2013-08-02 21:08:06 | [diff] [blame] | 694 | GenerateTestReport(options) |
| 695 | # KillHostHeartbeat() has logic to check if heartbeat process is running, |
| 696 | # and kills only if it finds the process is running on the host. |
| 697 | provision_devices.KillHostHeartbeat() |
[email protected] | 773c4f0 | 2014-08-12 19:05:22 | [diff] [blame] | 698 | if options.cleanup: |
| 699 | shutil.rmtree(os.path.join(CHROME_OUT_DIR, options.target), |
| 700 | ignore_errors=True) |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 701 | |
| 702 | |
| 703 | def GetDeviceStepsOptParser(): |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 704 | parser = bb_utils.GetParser() |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 705 | parser.add_option('--experimental', action='store_true', |
| 706 | help='Run experiemental tests') |
| 707 | parser.add_option('-f', '--test-filter', metavar='<filter>', default=[], |
| 708 | action='append', |
| 709 | help=('Run a test suite. Test suites: "%s"' % |
| 710 | '", "'.join(VALID_TESTS))) |
[email protected] | 18d59b8 | 2013-11-12 09:21:41 | [diff] [blame] | 711 | parser.add_option('--gtest-filter', |
| 712 | help='Filter for running a subset of tests of a gtest test') |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 713 | parser.add_option('--asan', action='store_true', help='Run tests with asan.') |
jbudorick | 7da88de6 | 2014-12-03 21:46:03 | [diff] [blame] | 714 | parser.add_option('--install', metavar='<apk name>', action="append", |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 715 | help='Install an apk by name') |
[email protected] | 4a3375d | 2014-01-08 12:56:50 | [diff] [blame] | 716 | parser.add_option('--no-reboot', action='store_true', |
| 717 | help='Do not reboot devices during provisioning.') |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 718 | parser.add_option('--coverage-bucket', |
| 719 | help=('Bucket name to store coverage results. Coverage is ' |
| 720 | 'only run if this is set.')) |
[email protected] | e5d85a7 | 2013-10-19 13:44:02 | [diff] [blame] | 721 | parser.add_option('--restart-usb', action='store_true', |
| 722 | help='Restart usb ports before device status check.') |
[email protected] | 14f139f4 | 2013-07-24 18:41:58 | [diff] [blame] | 723 | parser.add_option( |
| 724 | '--flakiness-server', |
[email protected] | f049a19 | 2013-10-10 01:11:26 | [diff] [blame] | 725 | help=('The flakiness dashboard server to which the results should be ' |
| 726 | 'uploaded.')) |
[email protected] | 12f36c8 | 2013-03-29 06:21:13 | [diff] [blame] | 727 | parser.add_option( |
| 728 | '--auto-reconnect', action='store_true', |
| 729 | help='Push script to device which restarts adbd on disconnections.') |
[email protected] | 3356038b | 2014-06-17 02:40:13 | [diff] [blame] | 730 | parser.add_option('--skip-wipe', action='store_true', |
| 731 | help='Do not wipe devices during provisioning.') |
jbudorick | 9669e5b | 2015-03-09 16:29:07 | [diff] [blame] | 732 | parser.add_option('--disable-location', action='store_true', |
| 733 | help='Disable location settings.') |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 734 | parser.add_option( |
| 735 | '--logcat-dump-output', |
| 736 | help='The logcat dump output will be "tee"-ed into this file') |
[email protected] | 2982604 | 2014-06-06 19:00:05 | [diff] [blame] | 737 | # During processing perf bisects, a seperate working directory created under |
| 738 | # which builds are produced. Therefore we should look for relevent output |
| 739 | # file under this directory.(/b/build/slave/<slave_name>/build/bisect/src/out) |
| 740 | parser.add_option( |
| 741 | '--chrome-output-dir', |
| 742 | help='Chrome output directory to be used while bisecting.') |
| 743 | |
jbudorick | 0f77e96 | 2014-11-19 15:41:29 | [diff] [blame] | 744 | parser.add_option('--disable-stack-tool', action='store_true', |
[email protected] | 79d3d8d8 | 2014-02-05 13:47:04 | [diff] [blame] | 745 | help='Do not run stack tool.') |
jbudorick | 0f77e96 | 2014-11-19 15:41:29 | [diff] [blame] | 746 | parser.add_option('--asan-symbolize', action='store_true', |
[email protected] | 79d3d8d8 | 2014-02-05 13:47:04 | [diff] [blame] | 747 | help='Run stack tool for ASAN') |
[email protected] | 773c4f0 | 2014-08-12 19:05:22 | [diff] [blame] | 748 | parser.add_option('--cleanup', action='store_true', |
| 749 | help='Delete out/<target> directory at the end of the run.') |
[email protected] | 7405027 | 2013-07-02 14:02:15 | [diff] [blame] | 750 | return parser |
| 751 | |
| 752 | |
| 753 | def main(argv): |
| 754 | parser = GetDeviceStepsOptParser() |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 755 | options, args = parser.parse_args(argv[1:]) |
| 756 | |
jbudorick | d28554a | 2016-01-11 16:22:59 | [diff] [blame] | 757 | devil_chromium.Initialize() |
| 758 | |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 759 | if args: |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 760 | return sys.exit('Unused args %s' % args) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 761 | |
| 762 | unknown_tests = set(options.test_filter) - VALID_TESTS |
| 763 | if unknown_tests: |
[email protected] | c528275 | 2013-06-07 23:14:39 | [diff] [blame] | 764 | return sys.exit('Unknown tests %s' % list(unknown_tests)) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 765 | |
| 766 | setattr(options, 'target', options.factory_properties.get('target', 'Debug')) |
[email protected] | 2982604 | 2014-06-06 19:00:05 | [diff] [blame] | 767 | |
jbudorick | 58b4d36 | 2015-09-08 16:44:59 | [diff] [blame] | 768 | # pylint: disable=global-statement |
[email protected] | 2982604 | 2014-06-06 19:00:05 | [diff] [blame] | 769 | if options.chrome_output_dir: |
| 770 | global CHROME_OUT_DIR |
| 771 | global LOGCAT_DIR |
| 772 | CHROME_OUT_DIR = options.chrome_output_dir |
| 773 | LOGCAT_DIR = os.path.join(CHROME_OUT_DIR, 'logcat') |
| 774 | |
[email protected] | 485fb23 | 2013-08-22 19:56:33 | [diff] [blame] | 775 | if options.coverage_bucket: |
| 776 | setattr(options, 'coverage_dir', |
[email protected] | dc8ec3f | 2013-09-07 07:18:14 | [diff] [blame] | 777 | os.path.join(CHROME_OUT_DIR, options.target, 'coverage')) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 778 | |
bpastene | d20f477 | 2016-04-20 15:37:58 | [diff] [blame] | 779 | return MainTestWrapper(options) |
[email protected] | e185b7e8 | 2013-01-09 03:49:57 | [diff] [blame] | 780 | |
| 781 | |
| 782 | if __name__ == '__main__': |
| 783 | sys.exit(main(sys.argv)) |