OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """Defines a set of constants shared by test runners and other scripts.""" |
| 6 |
| 7 # TODO(jbudorick): Split these constants into coherent modules. |
| 8 |
| 9 # pylint: disable=W0212 |
| 10 |
| 11 import collections |
| 12 import logging |
| 13 import os |
| 14 import subprocess |
| 15 |
| 16 |
| 17 DIR_SOURCE_ROOT = os.environ.get('CHECKOUT_SOURCE_ROOT', |
| 18 os.path.abspath(os.path.join(os.path.dirname(__file__), |
| 19 os.pardir, os.pardir, os.pardir, os.pardir))) |
| 20 ISOLATE_DEPS_DIR = os.path.join(DIR_SOURCE_ROOT, 'isolate_deps_dir') |
| 21 |
| 22 CHROME_SHELL_HOST_DRIVEN_DIR = os.path.join( |
| 23 DIR_SOURCE_ROOT, 'chrome', 'android') |
| 24 |
| 25 |
| 26 PackageInfo = collections.namedtuple('PackageInfo', |
| 27 ['package', 'activity', 'cmdline_file', 'devtools_socket', |
| 28 'test_package']) |
| 29 |
| 30 PACKAGE_INFO = { |
| 31 'chrome_document': PackageInfo( |
| 32 'com.google.android.apps.chrome.document', |
| 33 'com.google.android.apps.chrome.document.ChromeLauncherActivity', |
| 34 '/data/local/chrome-command-line', |
| 35 'chrome_devtools_remote', |
| 36 None), |
| 37 'chrome': PackageInfo( |
| 38 'com.google.android.apps.chrome', |
| 39 'com.google.android.apps.chrome.Main', |
| 40 '/data/local/chrome-command-line', |
| 41 'chrome_devtools_remote', |
| 42 'com.google.android.apps.chrome.tests'), |
| 43 'chrome_beta': PackageInfo( |
| 44 'com.chrome.beta', |
| 45 'com.google.android.apps.chrome.Main', |
| 46 '/data/local/chrome-command-line', |
| 47 'chrome_devtools_remote', |
| 48 None), |
| 49 'chrome_stable': PackageInfo( |
| 50 'com.android.chrome', |
| 51 'com.google.android.apps.chrome.Main', |
| 52 '/data/local/chrome-command-line', |
| 53 'chrome_devtools_remote', |
| 54 None), |
| 55 'chrome_dev': PackageInfo( |
| 56 'com.chrome.dev', |
| 57 'com.google.android.apps.chrome.Main', |
| 58 '/data/local/chrome-command-line', |
| 59 'chrome_devtools_remote', |
| 60 None), |
| 61 'chrome_canary': PackageInfo( |
| 62 'com.chrome.canary', |
| 63 'com.google.android.apps.chrome.Main', |
| 64 '/data/local/chrome-command-line', |
| 65 'chrome_devtools_remote', |
| 66 None), |
| 67 'chrome_work': PackageInfo( |
| 68 'com.chrome.work', |
| 69 'com.google.android.apps.chrome.Main', |
| 70 '/data/local/chrome-command-line', |
| 71 'chrome_devtools_remote', |
| 72 None), |
| 73 'chromium': PackageInfo( |
| 74 'org.chromium.chrome', |
| 75 'com.google.android.apps.chrome.Main', |
| 76 '/data/local/chrome-command-line', |
| 77 'chrome_devtools_remote', |
| 78 None), |
| 79 'legacy_browser': PackageInfo( |
| 80 'com.google.android.browser', |
| 81 'com.android.browser.BrowserActivity', |
| 82 None, |
| 83 None, |
| 84 None), |
| 85 'chromecast_shell': PackageInfo( |
| 86 'com.google.android.apps.mediashell', |
| 87 'com.google.android.apps.mediashell.MediaShellActivity', |
| 88 '/data/local/tmp/castshell-command-line', |
| 89 None, |
| 90 None), |
| 91 'content_shell': PackageInfo( |
| 92 'org.chromium.content_shell_apk', |
| 93 'org.chromium.content_shell_apk.ContentShellActivity', |
| 94 '/data/local/tmp/content-shell-command-line', |
| 95 None, |
| 96 'org.chromium.content_shell_apk.tests'), |
| 97 'chrome_shell': PackageInfo( |
| 98 'org.chromium.chrome.shell', |
| 99 'org.chromium.chrome.shell.ChromeShellActivity', |
| 100 '/data/local/tmp/chrome-shell-command-line', |
| 101 'chrome_shell_devtools_remote', |
| 102 'org.chromium.chrome.shell.tests'), |
| 103 'android_webview_shell': PackageInfo( |
| 104 'org.chromium.android_webview.shell', |
| 105 'org.chromium.android_webview.shell.AwShellActivity', |
| 106 '/data/local/tmp/android-webview-command-line', |
| 107 None, |
| 108 'org.chromium.android_webview.test'), |
| 109 'gtest': PackageInfo( |
| 110 'org.chromium.native_test', |
| 111 'org.chromium.native_test.NativeUnitTestActivity', |
| 112 '/data/local/tmp/chrome-native-tests-command-line', |
| 113 None, |
| 114 None), |
| 115 'components_browsertests': PackageInfo( |
| 116 'org.chromium.components_browsertests_apk', |
| 117 ('org.chromium.components_browsertests_apk' + |
| 118 '.ComponentsBrowserTestsActivity'), |
| 119 '/data/local/tmp/chrome-native-tests-command-line', |
| 120 None, |
| 121 None), |
| 122 'content_browsertests': PackageInfo( |
| 123 'org.chromium.content_browsertests_apk', |
| 124 'org.chromium.content_browsertests_apk.ContentBrowserTestsActivity', |
| 125 '/data/local/tmp/chrome-native-tests-command-line', |
| 126 None, |
| 127 None), |
| 128 'chromedriver_webview_shell': PackageInfo( |
| 129 'org.chromium.chromedriver_webview_shell', |
| 130 'org.chromium.chromedriver_webview_shell.Main', |
| 131 None, |
| 132 None, |
| 133 None), |
| 134 } |
| 135 |
| 136 |
| 137 # Ports arrangement for various test servers used in Chrome for Android. |
| 138 # Lighttpd server will attempt to use 9000 as default port, if unavailable it |
| 139 # will find a free port from 8001 - 8999. |
| 140 LIGHTTPD_DEFAULT_PORT = 9000 |
| 141 LIGHTTPD_RANDOM_PORT_FIRST = 8001 |
| 142 LIGHTTPD_RANDOM_PORT_LAST = 8999 |
| 143 TEST_SYNC_SERVER_PORT = 9031 |
| 144 TEST_SEARCH_BY_IMAGE_SERVER_PORT = 9041 |
| 145 TEST_POLICY_SERVER_PORT = 9051 |
| 146 |
| 147 # The net test server is started from port 10201. |
| 148 # TODO(pliard): http://crbug.com/239014. Remove this dirty workaround once |
| 149 # http://crbug.com/239014 is fixed properly. |
| 150 TEST_SERVER_PORT_FIRST = 10201 |
| 151 TEST_SERVER_PORT_LAST = 30000 |
| 152 # A file to record next valid port of test server. |
| 153 TEST_SERVER_PORT_FILE = '/tmp/test_server_port' |
| 154 TEST_SERVER_PORT_LOCKFILE = '/tmp/test_server_port.lock' |
| 155 |
| 156 TEST_EXECUTABLE_DIR = '/data/local/tmp' |
| 157 # Directories for common java libraries for SDK build. |
| 158 # These constants are defined in build/android/ant/common.xml |
| 159 SDK_BUILD_JAVALIB_DIR = 'lib.java' |
| 160 SDK_BUILD_TEST_JAVALIB_DIR = 'test.lib.java' |
| 161 SDK_BUILD_APKS_DIR = 'apks' |
| 162 |
| 163 ADB_KEYS_FILE = '/data/misc/adb/adb_keys' |
| 164 |
| 165 PERF_OUTPUT_DIR = os.path.join(DIR_SOURCE_ROOT, 'out', 'step_results') |
| 166 # The directory on the device where perf test output gets saved to. |
| 167 DEVICE_PERF_OUTPUT_DIR = ( |
| 168 '/data/data/' + PACKAGE_INFO['chrome'].package + '/files') |
| 169 |
| 170 SCREENSHOTS_DIR = os.path.join(DIR_SOURCE_ROOT, 'out_screenshots') |
| 171 |
| 172 class ANDROID_SDK_VERSION_CODES(object): |
| 173 """Android SDK version codes. |
| 174 |
| 175 http://developer.android.com/reference/android/os/Build.VERSION_CODES.html |
| 176 """ |
| 177 |
| 178 JELLY_BEAN = 16 |
| 179 JELLY_BEAN_MR1 = 17 |
| 180 JELLY_BEAN_MR2 = 18 |
| 181 KITKAT = 19 |
| 182 KITKAT_WATCH = 20 |
| 183 LOLLIPOP = 21 |
| 184 LOLLIPOP_MR1 = 22 |
| 185 |
| 186 ANDROID_SDK_VERSION = ANDROID_SDK_VERSION_CODES.LOLLIPOP_MR1 |
| 187 ANDROID_SDK_BUILD_TOOLS_VERSION = '22.0.1' |
| 188 ANDROID_SDK_ROOT = os.path.join(DIR_SOURCE_ROOT, |
| 189 'third_party/android_tools/sdk') |
| 190 ANDROID_SDK_TOOLS = os.path.join(ANDROID_SDK_ROOT, |
| 191 'build-tools', ANDROID_SDK_BUILD_TOOLS_VERSION) |
| 192 ANDROID_NDK_ROOT = os.path.join(DIR_SOURCE_ROOT, |
| 193 'third_party/android_tools/ndk') |
| 194 |
| 195 EMULATOR_SDK_ROOT = os.environ.get('ANDROID_EMULATOR_SDK_ROOT', |
| 196 os.path.join(DIR_SOURCE_ROOT, |
| 197 'android_emulator_sdk')) |
| 198 |
| 199 BAD_DEVICES_JSON = os.path.join(DIR_SOURCE_ROOT, |
| 200 os.environ.get('CHROMIUM_OUT_DIR', 'out'), |
| 201 'bad_devices.json') |
| 202 |
| 203 UPSTREAM_FLAKINESS_SERVER = 'test-results.appspot.com' |
| 204 |
| 205 DEVICE_LOCAL_PROPERTIES_PATH = '/data/local.prop' |
| 206 |
| 207 PYTHON_UNIT_TEST_SUITES = { |
| 208 'pylib_py_unittests': { |
| 209 'path': os.path.join(DIR_SOURCE_ROOT, 'build', 'android'), |
| 210 'test_modules': [ |
| 211 'pylib.cmd_helper_test', |
| 212 'pylib.device.device_utils_test', |
| 213 'pylib.results.json_results_test', |
| 214 'pylib.utils.md5sum_test', |
| 215 ] |
| 216 }, |
| 217 'gyp_py_unittests': { |
| 218 'path': os.path.join(DIR_SOURCE_ROOT, 'build', 'android', 'gyp'), |
| 219 'test_modules': [ |
| 220 'java_cpp_enum_tests', |
| 221 ] |
| 222 }, |
| 223 } |
| 224 |
| 225 LOCAL_MACHINE_TESTS = ['junit', 'python'] |
| 226 VALID_ENVIRONMENTS = ['local', 'remote_device'] |
| 227 VALID_TEST_TYPES = ['gtest', 'instrumentation', 'junit', 'linker', 'monkey', |
| 228 'perf', 'python', 'uiautomator', 'uirobot'] |
| 229 VALID_DEVICE_TYPES = ['Android', 'iOS'] |
| 230 |
| 231 |
| 232 def GetBuildType(): |
| 233 try: |
| 234 return os.environ['BUILDTYPE'] |
| 235 except KeyError: |
| 236 raise EnvironmentError( |
| 237 'The BUILDTYPE environment variable has not been set') |
| 238 |
| 239 |
| 240 def SetBuildType(build_type): |
| 241 os.environ['BUILDTYPE'] = build_type |
| 242 |
| 243 |
| 244 def SetBuildDirectory(build_directory): |
| 245 os.environ['CHROMIUM_OUT_DIR'] = build_directory |
| 246 |
| 247 |
| 248 def SetOutputDirectory(output_directory): |
| 249 os.environ['CHROMIUM_OUTPUT_DIR'] = output_directory |
| 250 |
| 251 |
| 252 def GetOutDirectory(build_type=None): |
| 253 """Returns the out directory where the output binaries are built. |
| 254 |
| 255 Args: |
| 256 build_type: Build type, generally 'Debug' or 'Release'. Defaults to the |
| 257 globally set build type environment variable BUILDTYPE. |
| 258 """ |
| 259 if 'CHROMIUM_OUTPUT_DIR' in os.environ: |
| 260 return os.path.abspath(os.path.join( |
| 261 DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUTPUT_DIR'))) |
| 262 |
| 263 return os.path.abspath(os.path.join( |
| 264 DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUT_DIR', 'out'), |
| 265 GetBuildType() if build_type is None else build_type)) |
| 266 |
| 267 |
| 268 def _Memoize(func): |
| 269 def Wrapper(): |
| 270 try: |
| 271 return func._result |
| 272 except AttributeError: |
| 273 func._result = func() |
| 274 return func._result |
| 275 return Wrapper |
| 276 |
| 277 |
| 278 def SetAdbPath(adb_path): |
| 279 os.environ['ADB_PATH'] = adb_path |
| 280 |
| 281 |
| 282 def GetAdbPath(): |
| 283 # Check if a custom adb path as been set. If not, try to find adb |
| 284 # on the system. |
| 285 if os.environ.get('ADB_PATH'): |
| 286 return os.environ.get('ADB_PATH') |
| 287 else: |
| 288 return _FindAdbPath() |
| 289 |
| 290 |
| 291 @_Memoize |
| 292 def _FindAdbPath(): |
| 293 if os.environ.get('ANDROID_SDK_ROOT'): |
| 294 return 'adb' |
| 295 # If envsetup.sh hasn't been sourced and there's no adb in the path, |
| 296 # set it here. |
| 297 try: |
| 298 with file(os.devnull, 'w') as devnull: |
| 299 subprocess.call(['adb', 'version'], stdout=devnull, stderr=devnull) |
| 300 return 'adb' |
| 301 except OSError: |
| 302 logging.debug('No adb found in $PATH, fallback to checked in binary.') |
| 303 return os.path.join(ANDROID_SDK_ROOT, 'platform-tools', 'adb') |
| 304 |
| 305 # Exit codes |
| 306 ERROR_EXIT_CODE = 1 |
| 307 INFRA_EXIT_CODE = 87 |
| 308 WARNING_EXIT_CODE = 88 |
OLD | NEW |