constants.py revision 68043e1e95eeb07d5cae7aca370b26518b0867d6
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.
4
5"""Defines a set of constants shared by test runners and other scripts."""
6
7import collections
8import os
9import subprocess
10import sys
11
12
13DIR_SOURCE_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__),
14                                               os.pardir, os.pardir, os.pardir))
15ISOLATE_DEPS_DIR = os.path.join(DIR_SOURCE_ROOT, 'isolate_deps_dir')
16EMULATOR_SDK_ROOT = os.path.abspath(os.path.join(DIR_SOURCE_ROOT, os.pardir,
17                                                 os.pardir))
18
19CHROMIUM_TEST_SHELL_HOST_DRIVEN_DIR = os.path.join(
20    DIR_SOURCE_ROOT, 'chrome', 'android')
21
22
23PackageInfo = collections.namedtuple('PackageInfo',
24    ['package', 'activity', 'cmdline_file', 'devtools_socket',
25     'test_package'])
26
27PACKAGE_INFO = {
28    'chrome': PackageInfo(
29        'com.google.android.apps.chrome',
30        'com.google.android.apps.chrome.Main',
31        '/data/local/chrome-command-line',
32        'chrome_devtools_remote',
33        'com.google.android.apps.chrome.tests'),
34    'chrome_beta': PackageInfo(
35        'com.chrome.beta',
36        'com.google.android.apps.chrome.Main',
37        '/data/local/chrome-command-line',
38        'chrome_devtools_remote',
39        None),
40    'chrome_stable': PackageInfo(
41        'com.android.chrome',
42        'com.google.android.apps.chrome.Main',
43        '/data/local/chrome-command-line',
44        'chrome_devtools_remote',
45        None),
46    'legacy_browser': PackageInfo(
47        'com.google.android.browser',
48        'com.android.browser.BrowserActivity',
49        None,
50        None,
51        None),
52    'content_shell': PackageInfo(
53        'org.chromium.content_shell_apk',
54        'org.chromium.content_shell_apk.ContentShellActivity',
55        '/data/local/tmp/content-shell-command-line',
56        None,
57        None),
58    'chromium_test_shell': PackageInfo(
59        'org.chromium.chrome.testshell',
60        'org.chromium.chrome.testshell.ChromiumTestShellActivity',
61        '/data/local/tmp/chromium-testshell-command-line',
62        'chromium_testshell_devtools_remote',
63        'org.chromium.chrome.testshell.tests'),
64    'gtest': PackageInfo(
65        'org.chromium.native_test',
66        'org.chromium.native_test.ChromeNativeTestActivity',
67        '/data/local/tmp/chrome-native-tests-command-line',
68        None,
69        None),
70    'content_browsertests': PackageInfo(
71        'org.chromium.content_browsertests_apk',
72        'org.chromium.content_browsertests_apk.ContentBrowserTestsActivity',
73        '/data/local/tmp/content-browser-tests-command-line',
74        None,
75        None),
76}
77
78
79# Ports arrangement for various test servers used in Chrome for Android.
80# Lighttpd server will attempt to use 9000 as default port, if unavailable it
81# will find a free port from 8001 - 8999.
82LIGHTTPD_DEFAULT_PORT = 9000
83LIGHTTPD_RANDOM_PORT_FIRST = 8001
84LIGHTTPD_RANDOM_PORT_LAST = 8999
85TEST_SYNC_SERVER_PORT = 9031
86TEST_SEARCH_BY_IMAGE_SERVER_PORT = 9041
87
88# The net test server is started from port 10201.
89# TODO(pliard): http://crbug.com/239014. Remove this dirty workaround once
90# http://crbug.com/239014 is fixed properly.
91TEST_SERVER_PORT_FIRST = 10201
92TEST_SERVER_PORT_LAST = 30000
93# A file to record next valid port of test server.
94TEST_SERVER_PORT_FILE = '/tmp/test_server_port'
95TEST_SERVER_PORT_LOCKFILE = '/tmp/test_server_port.lock'
96
97TEST_EXECUTABLE_DIR = '/data/local/tmp'
98# Directories for common java libraries for SDK build.
99# These constants are defined in build/android/ant/common.xml
100SDK_BUILD_JAVALIB_DIR = 'lib.java'
101SDK_BUILD_TEST_JAVALIB_DIR = 'test.lib.java'
102SDK_BUILD_APKS_DIR = 'apks'
103
104PERF_OUTPUT_DIR = os.path.join(DIR_SOURCE_ROOT, 'out', 'step_results')
105# The directory on the device where perf test output gets saved to.
106DEVICE_PERF_OUTPUT_DIR = (
107    '/data/data/' + PACKAGE_INFO['chrome'].package + '/files')
108
109SCREENSHOTS_DIR = os.path.join(DIR_SOURCE_ROOT, 'out_screenshots')
110
111ANDROID_SDK_VERSION = 18
112ANDROID_SDK_ROOT = os.path.join(DIR_SOURCE_ROOT,
113                                'third_party/android_tools/sdk')
114ANDROID_NDK_ROOT = os.path.join(DIR_SOURCE_ROOT,
115                                'third_party/android_tools/ndk')
116
117UPSTREAM_FLAKINESS_SERVER = 'test-results.appspot.com'
118
119
120def GetBuildType():
121  try:
122    return os.environ['BUILDTYPE']
123  except KeyError:
124    raise Exception('The BUILDTYPE environment variable has not been set')
125
126
127def SetBuildType(build_type):
128  os.environ['BUILDTYPE'] = build_type
129
130
131def GetOutDirectory(build_type=None):
132  """Returns the out directory where the output binaries are built.
133
134  Args:
135    build_type: Build type, generally 'Debug' or 'Release'. Defaults to the
136      globally set build type environment variable BUILDTYPE.
137  """
138  return os.path.abspath(os.path.join(
139      DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUT_DIR', 'out'),
140      GetBuildType() if build_type is None else build_type))
141
142
143def _GetADBPath():
144  if os.environ.get('ANDROID_SDK_ROOT'):
145    return 'adb'
146  # If envsetup.sh hasn't been sourced and there's no adb in the path,
147  # set it here.
148  try:
149    with file(os.devnull, 'w') as devnull:
150      subprocess.call(['adb', 'version'], stdout=devnull, stderr=devnull)
151    return 'adb'
152  except OSError:
153    print >> sys.stderr, 'No adb found in $PATH, fallback to checked in binary.'
154    return os.path.join(ANDROID_SDK_ROOT, 'platform-tools', 'adb')
155
156
157ADB_PATH = _GetADBPath()
158
159# Exit codes
160ERROR_EXIT_CODE = 1
161WARNING_EXIT_CODE = 88
162