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