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
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',
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',
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(
42 'com.google.android.apps.chrome.Main',
43 '/data/local/chrome-command-line',
44 'chrome_devtools_remote',
46 'chrome_stable': PackageInfo(
48 'com.google.android.apps.chrome.Main',
49 '/data/local/chrome-command-line',
50 'chrome_devtools_remote',
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',
58 'chrome_canary': PackageInfo(
60 'com.google.android.apps.chrome.Main',
61 '/data/local/chrome-command-line',
62 'chrome_devtools_remote',
64 'chrome_work': PackageInfo(
66 'com.google.android.apps.chrome.Main',
67 '/data/local/chrome-command-line',
68 'chrome_devtools_remote',
70 'legacy_browser': PackageInfo(
71 'com.google.android.browser',
72 'com.android.browser.BrowserActivity',
76 'chromecast_shell': PackageInfo(
77 'com.google.android.apps.mediashell',
78 'com.google.android.apps.mediashell.MediaShellActivity',
79 '/data/local/tmp/castshell-command-line',
82 'content_shell': PackageInfo(
83 'org.chromium.content_shell_apk',
84 'org.chromium.content_shell_apk.ContentShellActivity',
85 '/data/local/tmp/content-shell-command-line',
87 'org.chromium.content_shell_apk.tests'),
88 'chrome_shell': PackageInfo(
89 'org.chromium.chrome.shell',
90 'org.chromium.chrome.shell.ChromeShellActivity',
91 '/data/local/tmp/chrome-shell-command-line',
92 'chrome_shell_devtools_remote',
93 'org.chromium.chrome.shell.tests'),
94 'android_webview_shell': PackageInfo(
95 'org.chromium.android_webview.shell',
96 'org.chromium.android_webview.shell.AwShellActivity',
97 '/data/local/tmp/android-webview-command-line',
99 'org.chromium.android_webview.test'),
100 'gtest': PackageInfo(
101 'org.chromium.native_test',
102 'org.chromium.native_test.ChromeNativeTestActivity',
103 '/data/local/tmp/chrome-native-tests-command-line',
106 'content_browsertests': PackageInfo(
107 'org.chromium.content_browsertests_apk',
108 'org.chromium.content_browsertests_apk.ContentBrowserTestsActivity',
109 '/data/local/tmp/content-browser-tests-command-line',
112 'chromedriver_webview_shell': PackageInfo(
113 'org.chromium.chromedriver_webview_shell',
114 'org.chromium.chromedriver_webview_shell.Main',
121 # Ports arrangement for various test servers used in Chrome for Android.
122 # Lighttpd server will attempt to use 9000 as default port, if unavailable it
123 # will find a free port from 8001 - 8999.
124 LIGHTTPD_DEFAULT_PORT
= 9000
125 LIGHTTPD_RANDOM_PORT_FIRST
= 8001
126 LIGHTTPD_RANDOM_PORT_LAST
= 8999
127 TEST_SYNC_SERVER_PORT
= 9031
128 TEST_SEARCH_BY_IMAGE_SERVER_PORT
= 9041
129 TEST_POLICY_SERVER_PORT
= 9051
131 # The net test server is started from port 10201.
132 # TODO(pliard): http://crbug.com/239014. Remove this dirty workaround once
133 # http://crbug.com/239014 is fixed properly.
134 TEST_SERVER_PORT_FIRST
= 10201
135 TEST_SERVER_PORT_LAST
= 30000
136 # A file to record next valid port of test server.
137 TEST_SERVER_PORT_FILE
= '/tmp/test_server_port'
138 TEST_SERVER_PORT_LOCKFILE
= '/tmp/test_server_port.lock'
140 TEST_EXECUTABLE_DIR
= '/data/local/tmp'
141 # Directories for common java libraries for SDK build.
142 # These constants are defined in build/android/ant/common.xml
143 SDK_BUILD_JAVALIB_DIR
= 'lib.java'
144 SDK_BUILD_TEST_JAVALIB_DIR
= 'test.lib.java'
145 SDK_BUILD_APKS_DIR
= 'apks'
147 ADB_KEYS_FILE
= '/data/misc/adb/adb_keys'
149 PERF_OUTPUT_DIR
= os
.path
.join(DIR_SOURCE_ROOT
, 'out', 'step_results')
150 # The directory on the device where perf test output gets saved to.
151 DEVICE_PERF_OUTPUT_DIR
= (
152 '/data/data/' + PACKAGE_INFO
['chrome'].package
+ '/files')
154 SCREENSHOTS_DIR
= os
.path
.join(DIR_SOURCE_ROOT
, 'out_screenshots')
156 class ANDROID_SDK_VERSION_CODES(object):
157 """Android SDK version codes.
159 http://developer.android.com/reference/android/os/Build.VERSION_CODES.html
162 ICE_CREAM_SANDWICH
= 14
163 ICE_CREAM_SANDWICH_MR1
= 15
172 ANDROID_SDK_VERSION
= ANDROID_SDK_VERSION_CODES
.LOLLIPOP_MR1
173 ANDROID_SDK_BUILD_TOOLS_VERSION
= '22.0.0'
174 ANDROID_SDK_ROOT
= os
.path
.join(DIR_SOURCE_ROOT
,
175 'third_party/android_tools/sdk')
176 ANDROID_SDK_TOOLS
= os
.path
.join(ANDROID_SDK_ROOT
,
177 'build-tools', ANDROID_SDK_BUILD_TOOLS_VERSION
)
178 ANDROID_NDK_ROOT
= os
.path
.join(DIR_SOURCE_ROOT
,
179 'third_party/android_tools/ndk')
181 EMULATOR_SDK_ROOT
= os
.environ
.get('ANDROID_EMULATOR_SDK_ROOT',
182 os
.path
.join(DIR_SOURCE_ROOT
,
183 'android_emulator_sdk'))
185 BAD_DEVICES_JSON
= os
.path
.join(DIR_SOURCE_ROOT
,
186 os
.environ
.get('CHROMIUM_OUT_DIR', 'out'),
189 UPSTREAM_FLAKINESS_SERVER
= 'test-results.appspot.com'
191 DEVICE_LOCAL_PROPERTIES_PATH
= '/data/local.prop'
193 PYTHON_UNIT_TEST_SUITES
= {
194 'pylib_py_unittests': {
195 'path': os
.path
.join(DIR_SOURCE_ROOT
, 'build', 'android'),
197 'pylib.cmd_helper_test',
198 'pylib.device.device_utils_test',
199 'pylib.results.json_results_test',
200 'pylib.utils.md5sum_test',
203 'gyp_py_unittests': {
204 'path': os
.path
.join(DIR_SOURCE_ROOT
, 'build', 'android', 'gyp'),
206 'java_cpp_enum_tests',
211 LOCAL_MACHINE_TESTS
= ['junit', 'python']
212 VALID_ENVIRONMENTS
= ['local', 'remote_device']
213 VALID_TEST_TYPES
= ['gtest', 'instrumentation', 'junit', 'linker', 'monkey',
214 'perf', 'python', 'uiautomator', 'uirobot']
215 VALID_DEVICE_TYPES
= ['Android', 'iOS']
220 return os
.environ
['BUILDTYPE']
222 raise Exception('The BUILDTYPE environment variable has not been set')
225 def SetBuildType(build_type
):
226 os
.environ
['BUILDTYPE'] = build_type
229 def SetBuildDirectory(build_directory
):
230 os
.environ
['CHROMIUM_OUT_DIR'] = build_directory
233 def SetOutputDirectort(output_directory
):
234 os
.environ
['CHROMIUM_OUTPUT_DIR'] = output_directory
237 def GetOutDirectory(build_type
=None):
238 """Returns the out directory where the output binaries are built.
241 build_type: Build type, generally 'Debug' or 'Release'. Defaults to the
242 globally set build type environment variable BUILDTYPE.
244 if 'CHROMIUM_OUTPUT_DIR' in os
.environ
:
245 return os
.path
.abspath(os
.path
.join(
246 DIR_SOURCE_ROOT
, os
.environ
.get('CHROMIUM_OUTPUT_DIR')))
248 return os
.path
.abspath(os
.path
.join(
249 DIR_SOURCE_ROOT
, os
.environ
.get('CHROMIUM_OUT_DIR', 'out'),
250 GetBuildType() if build_type
is None else build_type
))
257 except AttributeError:
258 func
._result
= func()
263 def SetAdbPath(adb_path
):
264 os
.environ
['ADB_PATH'] = adb_path
268 # Check if a custom adb path as been set. If not, try to find adb
270 if os
.environ
.get('ADB_PATH'):
271 return os
.environ
.get('ADB_PATH')
273 return _FindAdbPath()
278 if os
.environ
.get('ANDROID_SDK_ROOT'):
280 # If envsetup.sh hasn't been sourced and there's no adb in the path,
283 with
file(os
.devnull
, 'w') as devnull
:
284 subprocess
.call(['adb', 'version'], stdout
=devnull
, stderr
=devnull
)
287 logging
.debug('No adb found in $PATH, fallback to checked in binary.')
288 return os
.path
.join(ANDROID_SDK_ROOT
, 'platform-tools', 'adb')
293 WARNING_EXIT_CODE
= 88