Home | History | Annotate | Download | only in constants
      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 # TODO(jbudorick): Split these constants into coherent modules.
      8 
      9 # pylint: disable=W0212
     10 
     11 import collections
     12 import glob
     13 import logging
     14 import os
     15 import subprocess
     16 
     17 import devil.android.sdk.keyevent
     18 from devil.android.constants import chrome
     19 from devil.android.sdk import version_codes
     20 from devil.constants import exit_codes
     21 
     22 
     23 keyevent = devil.android.sdk.keyevent
     24 
     25 
     26 DIR_SOURCE_ROOT = os.environ.get('CHECKOUT_SOURCE_ROOT',
     27     os.path.abspath(os.path.join(os.path.dirname(__file__),
     28                                  os.pardir, os.pardir, os.pardir, os.pardir)))
     29 
     30 PACKAGE_INFO = dict(chrome.PACKAGE_INFO)
     31 PACKAGE_INFO.update({
     32     'legacy_browser': chrome.PackageInfo(
     33         'com.google.android.browser',
     34         'com.android.browser.BrowserActivity',
     35         None,
     36         None),
     37     'chromecast_shell': chrome.PackageInfo(
     38         'com.google.android.apps.mediashell',
     39         'com.google.android.apps.mediashell.MediaShellActivity',
     40         '/data/local/tmp/castshell-command-line',
     41         None),
     42     'android_webview_shell': chrome.PackageInfo(
     43         'org.chromium.android_webview.shell',
     44         'org.chromium.android_webview.shell.AwShellActivity',
     45         '/data/local/tmp/android-webview-command-line',
     46         None),
     47     'gtest': chrome.PackageInfo(
     48         'org.chromium.native_test',
     49         'org.chromium.native_test.NativeUnitTestActivity',
     50         '/data/local/tmp/chrome-native-tests-command-line',
     51         None),
     52     'components_browsertests': chrome.PackageInfo(
     53         'org.chromium.components_browsertests_apk',
     54         ('org.chromium.components_browsertests_apk' +
     55          '.ComponentsBrowserTestsActivity'),
     56         '/data/local/tmp/chrome-native-tests-command-line',
     57         None),
     58     'content_browsertests': chrome.PackageInfo(
     59         'org.chromium.content_browsertests_apk',
     60         'org.chromium.content_browsertests_apk.ContentBrowserTestsActivity',
     61         '/data/local/tmp/chrome-native-tests-command-line',
     62         None),
     63     'chromedriver_webview_shell': chrome.PackageInfo(
     64         'org.chromium.chromedriver_webview_shell',
     65         'org.chromium.chromedriver_webview_shell.Main',
     66         None,
     67         None),
     68 })
     69 
     70 
     71 # Ports arrangement for various test servers used in Chrome for Android.
     72 # Lighttpd server will attempt to use 9000 as default port, if unavailable it
     73 # will find a free port from 8001 - 8999.
     74 LIGHTTPD_DEFAULT_PORT = 9000
     75 LIGHTTPD_RANDOM_PORT_FIRST = 8001
     76 LIGHTTPD_RANDOM_PORT_LAST = 8999
     77 TEST_SYNC_SERVER_PORT = 9031
     78 TEST_SEARCH_BY_IMAGE_SERVER_PORT = 9041
     79 TEST_POLICY_SERVER_PORT = 9051
     80 
     81 
     82 TEST_EXECUTABLE_DIR = '/data/local/tmp'
     83 # Directories for common java libraries for SDK build.
     84 # These constants are defined in build/android/ant/common.xml
     85 SDK_BUILD_JAVALIB_DIR = 'lib.java'
     86 SDK_BUILD_TEST_JAVALIB_DIR = 'test.lib.java'
     87 SDK_BUILD_APKS_DIR = 'apks'
     88 
     89 ADB_KEYS_FILE = '/data/misc/adb/adb_keys'
     90 
     91 PERF_OUTPUT_DIR = os.path.join(DIR_SOURCE_ROOT, 'out', 'step_results')
     92 # The directory on the device where perf test output gets saved to.
     93 DEVICE_PERF_OUTPUT_DIR = (
     94     '/data/data/' + PACKAGE_INFO['chrome'].package + '/files')
     95 
     96 SCREENSHOTS_DIR = os.path.join(DIR_SOURCE_ROOT, 'out_screenshots')
     97 
     98 ANDROID_SDK_VERSION = version_codes.MARSHMALLOW
     99 ANDROID_SDK_BUILD_TOOLS_VERSION = '23.0.1'
    100 ANDROID_SDK_ROOT = os.path.join(DIR_SOURCE_ROOT,
    101                                 'third_party', 'android_tools', 'sdk')
    102 ANDROID_SDK_TOOLS = os.path.join(ANDROID_SDK_ROOT,
    103                                  'build-tools', ANDROID_SDK_BUILD_TOOLS_VERSION)
    104 ANDROID_NDK_ROOT = os.path.join(DIR_SOURCE_ROOT,
    105                                 'third_party', 'android_tools', 'ndk')
    106 
    107 PROGUARD_SCRIPT_PATH = os.path.join(
    108     ANDROID_SDK_ROOT, 'tools', 'proguard', 'bin', 'proguard.sh')
    109 
    110 PROGUARD_ROOT = os.path.join(DIR_SOURCE_ROOT, 'third_party', 'proguard')
    111 
    112 BAD_DEVICES_JSON = os.path.join(DIR_SOURCE_ROOT,
    113                                 os.environ.get('CHROMIUM_OUT_DIR', 'out'),
    114                                 'bad_devices.json')
    115 
    116 UPSTREAM_FLAKINESS_SERVER = 'test-results.appspot.com'
    117 
    118 # TODO(jbudorick): Remove once unused.
    119 DEVICE_LOCAL_PROPERTIES_PATH = '/data/local.prop'
    120 
    121 # TODO(jbudorick): Rework this into testing/buildbot/
    122 PYTHON_UNIT_TEST_SUITES = {
    123   'pylib_py_unittests': {
    124     'path': os.path.join(DIR_SOURCE_ROOT, 'build', 'android'),
    125     'test_modules': [
    126       'devil.android.device_utils_test',
    127       'devil.android.md5sum_test',
    128       'devil.utils.cmd_helper_test',
    129       'pylib.results.json_results_test',
    130       'pylib.utils.proguard_test',
    131     ]
    132   },
    133   'gyp_py_unittests': {
    134     'path': os.path.join(DIR_SOURCE_ROOT, 'build', 'android', 'gyp'),
    135     'test_modules': [
    136       'java_cpp_enum_tests',
    137       'java_google_api_keys_tests',
    138     ]
    139   },
    140 }
    141 
    142 LOCAL_MACHINE_TESTS = ['junit', 'python']
    143 VALID_ENVIRONMENTS = ['local', 'remote_device']
    144 VALID_TEST_TYPES = ['gtest', 'instrumentation', 'junit', 'linker', 'monkey',
    145                     'perf', 'python', 'uirobot']
    146 VALID_DEVICE_TYPES = ['Android', 'iOS']
    147 
    148 
    149 def GetBuildType():
    150   try:
    151     return os.environ['BUILDTYPE']
    152   except KeyError:
    153     raise EnvironmentError(
    154         'The BUILDTYPE environment variable has not been set')
    155 
    156 
    157 def SetBuildType(build_type):
    158   os.environ['BUILDTYPE'] = build_type
    159 
    160 
    161 def SetBuildDirectory(build_directory):
    162   os.environ['CHROMIUM_OUT_DIR'] = build_directory
    163 
    164 
    165 def SetOutputDirectory(output_directory):
    166   os.environ['CHROMIUM_OUTPUT_DIR'] = output_directory
    167 
    168 
    169 def GetOutDirectory(build_type=None):
    170   """Returns the out directory where the output binaries are built.
    171 
    172   Args:
    173     build_type: Build type, generally 'Debug' or 'Release'. Defaults to the
    174       globally set build type environment variable BUILDTYPE.
    175   """
    176   if 'CHROMIUM_OUTPUT_DIR' in os.environ:
    177     return os.path.abspath(os.path.join(
    178         DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUTPUT_DIR')))
    179 
    180   return os.path.abspath(os.path.join(
    181       DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUT_DIR', 'out'),
    182       GetBuildType() if build_type is None else build_type))
    183 
    184 
    185 def CheckOutputDirectory():
    186   """Checks that CHROMIUM_OUT_DIR or CHROMIUM_OUTPUT_DIR is set.
    187 
    188   If neither are set, but the current working directory is a build directory,
    189   then CHROMIUM_OUTPUT_DIR is set to the current working directory.
    190 
    191   Raises:
    192     Exception: If no output directory is detected.
    193   """
    194   output_dir = os.environ.get('CHROMIUM_OUTPUT_DIR')
    195   out_dir = os.environ.get('CHROMIUM_OUT_DIR')
    196   if not output_dir and not out_dir:
    197     # If CWD is an output directory, then assume it's the desired one.
    198     if os.path.exists('build.ninja'):
    199       output_dir = os.getcwd()
    200       SetOutputDirectory(output_dir)
    201     elif os.environ.get('CHROME_HEADLESS'):
    202       # When running on bots, see if the output directory is obvious.
    203       dirs = glob.glob(os.path.join(DIR_SOURCE_ROOT, 'out', '*', 'build.ninja'))
    204       if len(dirs) == 1:
    205         SetOutputDirectory(dirs[0])
    206       else:
    207         raise Exception('Neither CHROMIUM_OUTPUT_DIR nor CHROMIUM_OUT_DIR '
    208                         'has been set. CHROME_HEADLESS detected, but multiple '
    209                         'out dirs exist: %r' % dirs)
    210     else:
    211       raise Exception('Neither CHROMIUM_OUTPUT_DIR nor CHROMIUM_OUT_DIR '
    212                       'has been set')
    213 
    214 
    215 # TODO(jbudorick): Convert existing callers to AdbWrapper.GetAdbPath() and
    216 # remove this.
    217 def GetAdbPath():
    218   from devil.android.sdk import adb_wrapper
    219   return adb_wrapper.AdbWrapper.GetAdbPath()
    220 
    221 
    222 # Exit codes
    223 ERROR_EXIT_CODE = exit_codes.ERROR
    224 INFRA_EXIT_CODE = exit_codes.INFRA
    225 WARNING_EXIT_CODE = exit_codes.WARNING
    226