Re-land: content: Refactor GPU memory buffer framework.
[chromium-blink-merge.git] / build / android / pylib / constants.py
blobe89a29869f9cd426a8a30f396b15b831cef3e84f
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."""
6 # pylint: disable=W0212
8 import collections
9 import logging
10 import os
11 import subprocess
14 DIR_SOURCE_ROOT = os.environ.get('CHECKOUT_SOURCE_ROOT',
15 os.path.abspath(os.path.join(os.path.dirname(__file__),
16 os.pardir, os.pardir, os.pardir)))
17 ISOLATE_DEPS_DIR = os.path.join(DIR_SOURCE_ROOT, 'isolate_deps_dir')
19 CHROME_SHELL_HOST_DRIVEN_DIR = os.path.join(
20 DIR_SOURCE_ROOT, 'chrome', 'android')
23 PackageInfo = collections.namedtuple('PackageInfo',
24 ['package', 'activity', 'cmdline_file', 'devtools_socket',
25 'test_package'])
27 PACKAGE_INFO = {
28 'chrome_document': PackageInfo(
29 'com.google.android.apps.chrome.document',
30 'com.google.android.apps.chrome.document.ChromeLauncherActivity',
31 '/data/local/chrome-command-line',
32 'chrome_devtools_remote',
33 None),
34 'chrome': PackageInfo(
35 'com.google.android.apps.chrome',
36 'com.google.android.apps.chrome.Main',
37 '/data/local/chrome-command-line',
38 'chrome_devtools_remote',
39 'com.google.android.apps.chrome.tests'),
40 'chrome_beta': PackageInfo(
41 'com.chrome.beta',
42 'com.google.android.apps.chrome.Main',
43 '/data/local/chrome-command-line',
44 'chrome_devtools_remote',
45 None),
46 'chrome_stable': PackageInfo(
47 'com.android.chrome',
48 'com.google.android.apps.chrome.Main',
49 '/data/local/chrome-command-line',
50 'chrome_devtools_remote',
51 None),
52 'chrome_dev': PackageInfo(
53 'com.google.android.apps.chrome_dev',
54 'com.google.android.apps.chrome.Main',
55 '/data/local/chrome-command-line',
56 'chrome_devtools_remote',
57 None),
58 'chrome_canary': PackageInfo(
59 'com.chrome.canary',
60 'com.google.android.apps.chrome.Main',
61 '/data/local/chrome-command-line',
62 'chrome_devtools_remote',
63 None),
64 'legacy_browser': PackageInfo(
65 'com.google.android.browser',
66 'com.android.browser.BrowserActivity',
67 None,
68 None,
69 None),
70 'chromecast_shell': PackageInfo(
71 'com.google.android.apps.mediashell',
72 'com.google.android.apps.mediashell.MediaShellActivity',
73 '/data/local/tmp/castshell-command-line',
74 None,
75 None),
76 'content_shell': PackageInfo(
77 'org.chromium.content_shell_apk',
78 'org.chromium.content_shell_apk.ContentShellActivity',
79 '/data/local/tmp/content-shell-command-line',
80 None,
81 'org.chromium.content_shell_apk.tests'),
82 'chrome_shell': PackageInfo(
83 'org.chromium.chrome.shell',
84 'org.chromium.chrome.shell.ChromeShellActivity',
85 '/data/local/tmp/chrome-shell-command-line',
86 'chrome_shell_devtools_remote',
87 'org.chromium.chrome.shell.tests'),
88 'android_webview_shell': PackageInfo(
89 'org.chromium.android_webview.shell',
90 'org.chromium.android_webview.shell.AwShellActivity',
91 None,
92 None,
93 'org.chromium.android_webview.test'),
94 'gtest': PackageInfo(
95 'org.chromium.native_test',
96 'org.chromium.native_test.ChromeNativeTestActivity',
97 '/data/local/tmp/chrome-native-tests-command-line',
98 None,
99 None),
100 'content_browsertests': PackageInfo(
101 'org.chromium.content_browsertests_apk',
102 'org.chromium.content_browsertests_apk.ContentBrowserTestsActivity',
103 '/data/local/tmp/content-browser-tests-command-line',
104 None,
105 None),
106 'chromedriver_webview_shell': PackageInfo(
107 'org.chromium.chromedriver_webview_shell',
108 'org.chromium.chromedriver_webview_shell.Main',
109 None,
110 None,
111 None),
115 # Ports arrangement for various test servers used in Chrome for Android.
116 # Lighttpd server will attempt to use 9000 as default port, if unavailable it
117 # will find a free port from 8001 - 8999.
118 LIGHTTPD_DEFAULT_PORT = 9000
119 LIGHTTPD_RANDOM_PORT_FIRST = 8001
120 LIGHTTPD_RANDOM_PORT_LAST = 8999
121 TEST_SYNC_SERVER_PORT = 9031
122 TEST_SEARCH_BY_IMAGE_SERVER_PORT = 9041
124 # The net test server is started from port 10201.
125 # TODO(pliard): http://crbug.com/239014. Remove this dirty workaround once
126 # http://crbug.com/239014 is fixed properly.
127 TEST_SERVER_PORT_FIRST = 10201
128 TEST_SERVER_PORT_LAST = 30000
129 # A file to record next valid port of test server.
130 TEST_SERVER_PORT_FILE = '/tmp/test_server_port'
131 TEST_SERVER_PORT_LOCKFILE = '/tmp/test_server_port.lock'
133 TEST_EXECUTABLE_DIR = '/data/local/tmp'
134 # Directories for common java libraries for SDK build.
135 # These constants are defined in build/android/ant/common.xml
136 SDK_BUILD_JAVALIB_DIR = 'lib.java'
137 SDK_BUILD_TEST_JAVALIB_DIR = 'test.lib.java'
138 SDK_BUILD_APKS_DIR = 'apks'
140 ADB_KEYS_FILE = '/data/misc/adb/adb_keys'
142 PERF_OUTPUT_DIR = os.path.join(DIR_SOURCE_ROOT, 'out', 'step_results')
143 # The directory on the device where perf test output gets saved to.
144 DEVICE_PERF_OUTPUT_DIR = (
145 '/data/data/' + PACKAGE_INFO['chrome'].package + '/files')
147 SCREENSHOTS_DIR = os.path.join(DIR_SOURCE_ROOT, 'out_screenshots')
149 class ANDROID_SDK_VERSION_CODES(object):
150 """Android SDK version codes.
152 http://developer.android.com/reference/android/os/Build.VERSION_CODES.html
155 ICE_CREAM_SANDWICH = 14
156 ICE_CREAM_SANDWICH_MR1 = 15
157 JELLY_BEAN = 16
158 JELLY_BEAN_MR1 = 17
159 JELLY_BEAN_MR2 = 18
160 KITKAT = 19
161 KITKAT_WATCH = 20
162 LOLLIPOP = 21
164 ANDROID_SDK_VERSION = ANDROID_SDK_VERSION_CODES.LOLLIPOP
165 ANDROID_SDK_BUILD_TOOLS_VERSION = '21.0.1'
166 ANDROID_SDK_ROOT = os.path.join(DIR_SOURCE_ROOT,
167 'third_party/android_tools/sdk')
168 ANDROID_SDK_TOOLS = os.path.join(ANDROID_SDK_ROOT,
169 'build-tools', ANDROID_SDK_BUILD_TOOLS_VERSION)
170 ANDROID_NDK_ROOT = os.path.join(DIR_SOURCE_ROOT,
171 'third_party/android_tools/ndk')
173 EMULATOR_SDK_ROOT = os.environ.get('ANDROID_EMULATOR_SDK_ROOT',
174 os.path.join(DIR_SOURCE_ROOT,
175 'android_emulator_sdk'))
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 DEVICE_LOCAL_PROPERTIES_PATH = '/data/local.prop'
185 PYTHON_UNIT_TEST_SUITES = {
186 'pylib_py_unittests': {
187 'path': os.path.join(DIR_SOURCE_ROOT, 'build', 'android'),
188 'test_modules': [
189 'pylib.device.device_utils_test',
190 'pylib.utils.md5sum_test',
193 'gyp_py_unittests': {
194 'path': os.path.join(DIR_SOURCE_ROOT, 'build', 'android', 'gyp'),
195 'test_modules': [
196 'java_cpp_enum_tests',
201 LOCAL_MACHINE_TESTS = ['junit', 'python']
202 VALID_ENVIRONMENTS = ['local']
205 def GetBuildType():
206 try:
207 return os.environ['BUILDTYPE']
208 except KeyError:
209 raise Exception('The BUILDTYPE environment variable has not been set')
212 def SetBuildType(build_type):
213 os.environ['BUILDTYPE'] = build_type
216 def SetBuildDirectory(build_directory):
217 os.environ['CHROMIUM_OUT_DIR'] = build_directory
220 def SetOutputDirectort(output_directory):
221 os.environ['CHROMIUM_OUTPUT_DIR'] = output_directory
224 def GetOutDirectory(build_type=None):
225 """Returns the out directory where the output binaries are built.
227 Args:
228 build_type: Build type, generally 'Debug' or 'Release'. Defaults to the
229 globally set build type environment variable BUILDTYPE.
231 if 'CHROMIUM_OUTPUT_DIR' in os.environ:
232 return os.path.abspath(os.path.join(
233 DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUTPUT_DIR')))
235 return os.path.abspath(os.path.join(
236 DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUT_DIR', 'out'),
237 GetBuildType() if build_type is None else build_type))
240 def _Memoize(func):
241 def Wrapper():
242 try:
243 return func._result
244 except AttributeError:
245 func._result = func()
246 return func._result
247 return Wrapper
250 def SetAdbPath(adb_path):
251 os.environ['ADB_PATH'] = adb_path
254 def GetAdbPath():
255 # Check if a custom adb path as been set. If not, try to find adb
256 # on the system.
257 if os.environ.get('ADB_PATH'):
258 return os.environ.get('ADB_PATH')
259 else:
260 return _FindAdbPath()
263 @_Memoize
264 def _FindAdbPath():
265 if os.environ.get('ANDROID_SDK_ROOT'):
266 return 'adb'
267 # If envsetup.sh hasn't been sourced and there's no adb in the path,
268 # set it here.
269 try:
270 with file(os.devnull, 'w') as devnull:
271 subprocess.call(['adb', 'version'], stdout=devnull, stderr=devnull)
272 return 'adb'
273 except OSError:
274 logging.debug('No adb found in $PATH, fallback to checked in binary.')
275 return os.path.join(ANDROID_SDK_ROOT, 'platform-tools', 'adb')
277 # Exit codes
278 ERROR_EXIT_CODE = 1
279 WARNING_EXIT_CODE = 88