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