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