Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / build / android / pylib / constants / __init__.py
blob4d33e4f0859948ed1e4064e74ac7a1a5c2b4d4f9
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.
5 """Defines a set of constants shared by test runners and other scripts."""
7 # TODO(jbudorick): Split these constants into coherent modules.
9 # pylint: disable=W0212
11 import collections
12 import logging
13 import os
14 import subprocess
16 import devil.android.sdk.keyevent
17 from devil.android.sdk import version_codes
19 keyevent = devil.android.sdk.keyevent
22 DIR_SOURCE_ROOT = os.environ.get('CHECKOUT_SOURCE_ROOT',
23 os.path.abspath(os.path.join(os.path.dirname(__file__),
24 os.pardir, os.pardir, os.pardir, os.pardir)))
25 ISOLATE_DEPS_DIR = os.path.join(DIR_SOURCE_ROOT, 'isolate_deps_dir')
27 PackageInfo = collections.namedtuple('PackageInfo',
28 ['package', 'activity', 'cmdline_file', 'devtools_socket',
29 'test_package'])
31 PACKAGE_INFO = {
32 'chrome_document': PackageInfo(
33 'com.google.android.apps.chrome.document',
34 'com.google.android.apps.chrome.document.ChromeLauncherActivity',
35 '/data/local/chrome-command-line',
36 'chrome_devtools_remote',
37 None),
38 'chrome': PackageInfo(
39 'com.google.android.apps.chrome',
40 'com.google.android.apps.chrome.Main',
41 '/data/local/chrome-command-line',
42 'chrome_devtools_remote',
43 'com.google.android.apps.chrome.tests'),
44 'chrome_beta': PackageInfo(
45 'com.chrome.beta',
46 'com.google.android.apps.chrome.Main',
47 '/data/local/chrome-command-line',
48 'chrome_devtools_remote',
49 None),
50 'chrome_stable': PackageInfo(
51 'com.android.chrome',
52 'com.google.android.apps.chrome.Main',
53 '/data/local/chrome-command-line',
54 'chrome_devtools_remote',
55 None),
56 'chrome_dev': PackageInfo(
57 'com.chrome.dev',
58 'com.google.android.apps.chrome.Main',
59 '/data/local/chrome-command-line',
60 'chrome_devtools_remote',
61 None),
62 'chrome_canary': PackageInfo(
63 'com.chrome.canary',
64 'com.google.android.apps.chrome.Main',
65 '/data/local/chrome-command-line',
66 'chrome_devtools_remote',
67 None),
68 'chrome_work': PackageInfo(
69 'com.chrome.work',
70 'com.google.android.apps.chrome.Main',
71 '/data/local/chrome-command-line',
72 'chrome_devtools_remote',
73 None),
74 'chromium': PackageInfo(
75 'org.chromium.chrome',
76 'com.google.android.apps.chrome.Main',
77 '/data/local/chrome-command-line',
78 'chrome_devtools_remote',
79 None),
80 'legacy_browser': PackageInfo(
81 'com.google.android.browser',
82 'com.android.browser.BrowserActivity',
83 None,
84 None,
85 None),
86 'chromecast_shell': PackageInfo(
87 'com.google.android.apps.mediashell',
88 'com.google.android.apps.mediashell.MediaShellActivity',
89 '/data/local/tmp/castshell-command-line',
90 None,
91 None),
92 'content_shell': PackageInfo(
93 'org.chromium.content_shell_apk',
94 'org.chromium.content_shell_apk.ContentShellActivity',
95 '/data/local/tmp/content-shell-command-line',
96 None,
97 'org.chromium.content_shell_apk.tests'),
98 'android_webview_shell': PackageInfo(
99 'org.chromium.android_webview.shell',
100 'org.chromium.android_webview.shell.AwShellActivity',
101 '/data/local/tmp/android-webview-command-line',
102 None,
103 'org.chromium.android_webview.test'),
104 'gtest': PackageInfo(
105 'org.chromium.native_test',
106 'org.chromium.native_test.NativeUnitTestActivity',
107 '/data/local/tmp/chrome-native-tests-command-line',
108 None,
109 None),
110 'components_browsertests': PackageInfo(
111 'org.chromium.components_browsertests_apk',
112 ('org.chromium.components_browsertests_apk' +
113 '.ComponentsBrowserTestsActivity'),
114 '/data/local/tmp/chrome-native-tests-command-line',
115 None,
116 None),
117 'content_browsertests': PackageInfo(
118 'org.chromium.content_browsertests_apk',
119 'org.chromium.content_browsertests_apk.ContentBrowserTestsActivity',
120 '/data/local/tmp/chrome-native-tests-command-line',
121 None,
122 None),
123 'chromedriver_webview_shell': PackageInfo(
124 'org.chromium.chromedriver_webview_shell',
125 'org.chromium.chromedriver_webview_shell.Main',
126 None,
127 None,
128 None),
132 # Ports arrangement for various test servers used in Chrome for Android.
133 # Lighttpd server will attempt to use 9000 as default port, if unavailable it
134 # will find a free port from 8001 - 8999.
135 LIGHTTPD_DEFAULT_PORT = 9000
136 LIGHTTPD_RANDOM_PORT_FIRST = 8001
137 LIGHTTPD_RANDOM_PORT_LAST = 8999
138 TEST_SYNC_SERVER_PORT = 9031
139 TEST_SEARCH_BY_IMAGE_SERVER_PORT = 9041
140 TEST_POLICY_SERVER_PORT = 9051
143 TEST_EXECUTABLE_DIR = '/data/local/tmp'
144 # Directories for common java libraries for SDK build.
145 # These constants are defined in build/android/ant/common.xml
146 SDK_BUILD_JAVALIB_DIR = 'lib.java'
147 SDK_BUILD_TEST_JAVALIB_DIR = 'test.lib.java'
148 SDK_BUILD_APKS_DIR = 'apks'
150 ADB_KEYS_FILE = '/data/misc/adb/adb_keys'
152 PERF_OUTPUT_DIR = os.path.join(DIR_SOURCE_ROOT, 'out', 'step_results')
153 # The directory on the device where perf test output gets saved to.
154 DEVICE_PERF_OUTPUT_DIR = (
155 '/data/data/' + PACKAGE_INFO['chrome'].package + '/files')
157 SCREENSHOTS_DIR = os.path.join(DIR_SOURCE_ROOT, 'out_screenshots')
159 ANDROID_SDK_VERSION = version_codes.MARSHMALLOW
160 ANDROID_SDK_BUILD_TOOLS_VERSION = '23.0.0'
161 ANDROID_SDK_ROOT = os.path.join(DIR_SOURCE_ROOT,
162 'third_party/android_tools/sdk')
163 ANDROID_SDK_TOOLS = os.path.join(ANDROID_SDK_ROOT,
164 'build-tools', ANDROID_SDK_BUILD_TOOLS_VERSION)
165 ANDROID_NDK_ROOT = os.path.join(DIR_SOURCE_ROOT,
166 'third_party/android_tools/ndk')
168 PROGUARD_SCRIPT_PATH = os.path.join(
169 ANDROID_SDK_ROOT, 'tools', 'proguard', 'bin', 'proguard.sh')
171 EMULATOR_SDK_ROOT = os.environ.get('ANDROID_EMULATOR_SDK_ROOT',
172 os.path.join(DIR_SOURCE_ROOT,
173 'android_emulator_sdk'))
175 PROGUARD_ROOT = os.path.join(DIR_SOURCE_ROOT, 'third_party', 'proguard')
177 BAD_DEVICES_JSON = os.path.join(DIR_SOURCE_ROOT,
178 os.environ.get('CHROMIUM_OUT_DIR', 'out'),
179 'bad_devices.json')
181 UPSTREAM_FLAKINESS_SERVER = 'test-results.appspot.com'
183 # TODO(jbudorick): Remove once unused.
184 DEVICE_LOCAL_PROPERTIES_PATH = '/data/local.prop'
186 # TODO(jbudorick): Rework this into testing/buildbot/
187 PYTHON_UNIT_TEST_SUITES = {
188 'pylib_py_unittests': {
189 'path': os.path.join(DIR_SOURCE_ROOT, 'build', 'android'),
190 'test_modules': [
191 'devil.android.device_utils_test',
192 'devil.android.md5sum_test',
193 'devil.utils.cmd_helper_test',
194 'pylib.results.json_results_test',
195 'pylib.utils.proguard_test',
198 'gyp_py_unittests': {
199 'path': os.path.join(DIR_SOURCE_ROOT, 'build', 'android', 'gyp'),
200 'test_modules': [
201 'java_cpp_enum_tests',
206 LOCAL_MACHINE_TESTS = ['junit', 'python']
207 VALID_ENVIRONMENTS = ['local', 'remote_device']
208 VALID_TEST_TYPES = ['gtest', 'instrumentation', 'junit', 'linker', 'monkey',
209 'perf', 'python', 'uiautomator', 'uirobot']
210 VALID_DEVICE_TYPES = ['Android', 'iOS']
213 def GetBuildType():
214 try:
215 return os.environ['BUILDTYPE']
216 except KeyError:
217 raise EnvironmentError(
218 'The BUILDTYPE environment variable has not been set')
221 def SetBuildType(build_type):
222 os.environ['BUILDTYPE'] = build_type
225 def SetBuildDirectory(build_directory):
226 os.environ['CHROMIUM_OUT_DIR'] = build_directory
229 def SetOutputDirectory(output_directory):
230 os.environ['CHROMIUM_OUTPUT_DIR'] = output_directory
233 def GetOutDirectory(build_type=None):
234 """Returns the out directory where the output binaries are built.
236 Args:
237 build_type: Build type, generally 'Debug' or 'Release'. Defaults to the
238 globally set build type environment variable BUILDTYPE.
240 if 'CHROMIUM_OUTPUT_DIR' in os.environ:
241 return os.path.abspath(os.path.join(
242 DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUTPUT_DIR')))
244 return os.path.abspath(os.path.join(
245 DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUT_DIR', 'out'),
246 GetBuildType() if build_type is None else build_type))
249 def _Memoize(func):
250 def Wrapper():
251 try:
252 return func._result
253 except AttributeError:
254 func._result = func()
255 return func._result
256 return Wrapper
259 def SetAdbPath(adb_path):
260 os.environ['ADB_PATH'] = adb_path
263 def GetAdbPath():
264 # Check if a custom adb path as been set. If not, try to find adb
265 # on the system.
266 if os.environ.get('ADB_PATH'):
267 return os.environ.get('ADB_PATH')
268 else:
269 return _FindAdbPath()
272 @_Memoize
273 def _FindAdbPath():
274 if os.environ.get('ANDROID_SDK_ROOT'):
275 return 'adb'
276 # If envsetup.sh hasn't been sourced and there's no adb in the path,
277 # set it here.
278 try:
279 with file(os.devnull, 'w') as devnull:
280 subprocess.call(['adb', 'version'], stdout=devnull, stderr=devnull)
281 return 'adb'
282 except OSError:
283 logging.debug('No adb found in $PATH, fallback to checked in binary.')
284 return os.path.join(ANDROID_SDK_ROOT, 'platform-tools', 'adb')
286 # Exit codes
287 ERROR_EXIT_CODE = 1
288 INFRA_EXIT_CODE = 87
289 WARNING_EXIT_CODE = 88