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
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',
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',
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(
46 'com.google.android.apps.chrome.Main',
47 '/data/local/chrome-command-line',
48 'chrome_devtools_remote',
50 'chrome_stable': PackageInfo(
52 'com.google.android.apps.chrome.Main',
53 '/data/local/chrome-command-line',
54 'chrome_devtools_remote',
56 'chrome_dev': PackageInfo(
58 'com.google.android.apps.chrome.Main',
59 '/data/local/chrome-command-line',
60 'chrome_devtools_remote',
62 'chrome_canary': PackageInfo(
64 'com.google.android.apps.chrome.Main',
65 '/data/local/chrome-command-line',
66 'chrome_devtools_remote',
68 'chrome_work': PackageInfo(
70 'com.google.android.apps.chrome.Main',
71 '/data/local/chrome-command-line',
72 'chrome_devtools_remote',
74 'chromium': PackageInfo(
75 'org.chromium.chrome',
76 'com.google.android.apps.chrome.Main',
77 '/data/local/chrome-command-line',
78 'chrome_devtools_remote',
80 'legacy_browser': PackageInfo(
81 'com.google.android.browser',
82 'com.android.browser.BrowserActivity',
86 'chromecast_shell': PackageInfo(
87 'com.google.android.apps.mediashell',
88 'com.google.android.apps.mediashell.MediaShellActivity',
89 '/data/local/tmp/castshell-command-line',
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',
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',
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',
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',
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',
123 'chromedriver_webview_shell': PackageInfo(
124 'org.chromium.chromedriver_webview_shell',
125 'org.chromium.chromedriver_webview_shell.Main',
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'),
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'),
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'),
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']
215 return os
.environ
['BUILDTYPE']
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.
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
))
253 except AttributeError:
254 func
._result
= func()
259 def SetAdbPath(adb_path
):
260 os
.environ
['ADB_PATH'] = adb_path
264 # Check if a custom adb path as been set. If not, try to find adb
266 if os
.environ
.get('ADB_PATH'):
267 return os
.environ
.get('ADB_PATH')
269 return _FindAdbPath()
274 if os
.environ
.get('ANDROID_SDK_ROOT'):
276 # If envsetup.sh hasn't been sourced and there's no adb in the path,
279 with
file(os
.devnull
, 'w') as devnull
:
280 subprocess
.call(['adb', 'version'], stdout
=devnull
, stderr
=devnull
)
283 logging
.debug('No adb found in $PATH, fallback to checked in binary.')
284 return os
.path
.join(ANDROID_SDK_ROOT
, 'platform-tools', 'adb')
289 WARNING_EXIT_CODE
= 88