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
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')
22 CHROME_SHELL_HOST_DRIVEN_DIR
= os
.path
.join(
23 DIR_SOURCE_ROOT
, 'chrome', 'android')
26 PackageInfo
= collections
.namedtuple('PackageInfo',
27 ['package', 'activity', 'cmdline_file', 'devtools_socket',
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',
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(
45 'com.google.android.apps.chrome.Main',
46 '/data/local/chrome-command-line',
47 'chrome_devtools_remote',
49 'chrome_stable': PackageInfo(
51 'com.google.android.apps.chrome.Main',
52 '/data/local/chrome-command-line',
53 'chrome_devtools_remote',
55 'chrome_dev': PackageInfo(
57 'com.google.android.apps.chrome.Main',
58 '/data/local/chrome-command-line',
59 'chrome_devtools_remote',
61 'chrome_canary': PackageInfo(
63 'com.google.android.apps.chrome.Main',
64 '/data/local/chrome-command-line',
65 'chrome_devtools_remote',
67 'chrome_work': PackageInfo(
69 'com.google.android.apps.chrome.Main',
70 '/data/local/chrome-command-line',
71 'chrome_devtools_remote',
73 'chromium': PackageInfo(
74 'org.chromium.chrome',
75 'com.google.android.apps.chrome.Main',
76 '/data/local/chrome-command-line',
77 'chrome_devtools_remote',
79 'legacy_browser': PackageInfo(
80 'com.google.android.browser',
81 'com.android.browser.BrowserActivity',
85 'chromecast_shell': PackageInfo(
86 'com.google.android.apps.mediashell',
87 'com.google.android.apps.mediashell.MediaShellActivity',
88 '/data/local/tmp/castshell-command-line',
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',
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',
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',
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',
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',
128 'chromedriver_webview_shell': PackageInfo(
129 'org.chromium.chromedriver_webview_shell',
130 'org.chromium.chromedriver_webview_shell.Main',
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
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'
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'
163 ADB_KEYS_FILE
= '/data/misc/adb/adb_keys'
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')
170 SCREENSHOTS_DIR
= os
.path
.join(DIR_SOURCE_ROOT
, 'out_screenshots')
172 class ANDROID_SDK_VERSION_CODES(object):
173 """Android SDK version codes.
175 http://developer.android.com/reference/android/os/Build.VERSION_CODES.html
186 ANDROID_SDK_VERSION
= ANDROID_SDK_VERSION_CODES
.LOLLIPOP_MR1
187 ANDROID_SDK_BUILD_TOOLS_VERSION
= '22.0.0'
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')
195 EMULATOR_SDK_ROOT
= os
.environ
.get('ANDROID_EMULATOR_SDK_ROOT',
196 os
.path
.join(DIR_SOURCE_ROOT
,
197 'android_emulator_sdk'))
199 BAD_DEVICES_JSON
= os
.path
.join(DIR_SOURCE_ROOT
,
200 os
.environ
.get('CHROMIUM_OUT_DIR', 'out'),
203 UPSTREAM_FLAKINESS_SERVER
= 'test-results.appspot.com'
205 DEVICE_LOCAL_PROPERTIES_PATH
= '/data/local.prop'
207 PYTHON_UNIT_TEST_SUITES
= {
208 'pylib_py_unittests': {
209 'path': os
.path
.join(DIR_SOURCE_ROOT
, 'build', 'android'),
211 'pylib.cmd_helper_test',
212 'pylib.device.device_utils_test',
213 'pylib.results.json_results_test',
214 'pylib.utils.md5sum_test',
217 'gyp_py_unittests': {
218 'path': os
.path
.join(DIR_SOURCE_ROOT
, 'build', 'android', 'gyp'),
220 'java_cpp_enum_tests',
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']
234 return os
.environ
['BUILDTYPE']
236 raise EnvironmentError(
237 'The BUILDTYPE environment variable has not been set')
240 def SetBuildType(build_type
):
241 os
.environ
['BUILDTYPE'] = build_type
244 def SetBuildDirectory(build_directory
):
245 os
.environ
['CHROMIUM_OUT_DIR'] = build_directory
248 def SetOutputDirectory(output_directory
):
249 os
.environ
['CHROMIUM_OUTPUT_DIR'] = output_directory
252 def GetOutDirectory(build_type
=None):
253 """Returns the out directory where the output binaries are built.
256 build_type: Build type, generally 'Debug' or 'Release'. Defaults to the
257 globally set build type environment variable BUILDTYPE.
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')))
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
))
272 except AttributeError:
273 func
._result
= func()
278 def SetAdbPath(adb_path
):
279 os
.environ
['ADB_PATH'] = adb_path
283 # Check if a custom adb path as been set. If not, try to find adb
285 if os
.environ
.get('ADB_PATH'):
286 return os
.environ
.get('ADB_PATH')
288 return _FindAdbPath()
293 if os
.environ
.get('ANDROID_SDK_ROOT'):
295 # If envsetup.sh hasn't been sourced and there's no adb in the path,
298 with
file(os
.devnull
, 'w') as devnull
:
299 subprocess
.call(['adb', 'version'], stdout
=devnull
, stderr
=devnull
)
302 logging
.debug('No adb found in $PATH, fallback to checked in binary.')
303 return os
.path
.join(ANDROID_SDK_ROOT
, 'platform-tools', 'adb')
308 WARNING_EXIT_CODE
= 88