[android] Adds constants.GetOutDirectory() and converts test scripts to use it.

BUG=260494
TEST=None
NOTRY=True

Review URL: https://chromiumcodereview.appspot.com/22903016

git-svn-id: http://src.chromium.org/svn/trunk/src/build@221736 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
craigdh@chromium.org 2013-09-06 18:11:02 +00:00
Родитель 72bfca13c6
Коммит babb42acc8
15 изменённых файлов: 54 добавлений и 80 удалений

Просмотреть файл

@ -38,9 +38,8 @@ def ValidateInstallAPKOption(option_parser, options):
if not options.apk:
option_parser.error('--apk is mandatory.')
if not os.path.exists(options.apk):
options.apk = os.path.join(constants.DIR_SOURCE_ROOT,
'out', options.build_type,
'apks', options.apk)
options.apk = os.path.join(constants.GetOutDirectory(), 'apks',
options.apk)
def _InstallApk(args):
@ -54,6 +53,7 @@ def main(argv):
parser = optparse.OptionParser()
AddInstallAPKOption(parser)
options, args = parser.parse_args(argv)
constants.SetBuildType(options.build_type)
ValidateInstallAPKOption(parser, options)
if len(args) > 1:
raise Exception('Error: Unknown argument:', args[1:])

Просмотреть файл

@ -15,7 +15,7 @@ import optparse
import sys
import time
from pylib import android_commands, forwarder
from pylib import android_commands, constants, forwarder
from pylib.utils import run_tests_helper
@ -50,8 +50,9 @@ def main(argv):
sys.exit(1)
adb = android_commands.AndroidCommands(options.device)
constants.SetBuildType(options.build_type)
try:
forwarder.Forwarder.Map(port_pairs, adb, options.build_type)
forwarder.Forwarder.Map(port_pairs, adb)
while True:
time.sleep(60)
except KeyboardInterrupt:

Просмотреть файл

@ -247,7 +247,6 @@ class AndroidCommands(object):
self._device_utc_offset = None
self._potential_push_size = 0
self._actual_push_size = 0
self._md5sum_build_dir = ''
self._external_storage = ''
self._util_wrapper = ''
@ -783,18 +782,11 @@ class AndroidCommands(object):
A tuple containing lists of the host and device md5sum results as
created by _ParseMd5SumOutput().
"""
if not self._md5sum_build_dir:
default_build_type = os.environ.get('BUILD_TYPE', 'Debug')
build_dir = '%s/%s/' % (
cmd_helper.OutDirectory().get(), default_build_type)
md5sum_dist_path = '%s/md5sum_dist' % build_dir
if not os.path.exists(md5sum_dist_path):
build_dir = '%s/Release/' % cmd_helper.OutDirectory().get()
md5sum_dist_path = '%s/md5sum_dist' % build_dir
assert os.path.exists(md5sum_dist_path), 'Please build md5sum.'
command = 'push %s %s' % (md5sum_dist_path, MD5SUM_DEVICE_FOLDER)
assert _HasAdbPushSucceeded(self._adb.SendCommand(command))
self._md5sum_build_dir = build_dir
md5sum_dist_path = os.path.join(constants.GetOutDirectory(),
'md5sum_dist')
assert os.path.exists(md5sum_dist_path), 'Please build md5sum.'
command = 'push %s %s' % (md5sum_dist_path, MD5SUM_DEVICE_FOLDER)
assert _HasAdbPushSucceeded(self._adb.SendCommand(command))
cmd = (MD5SUM_LD_LIBRARY_PATH + ' ' + self._util_wrapper + ' ' +
MD5SUM_DEVICE_PATH + ' ' + device_path)
@ -802,7 +794,8 @@ class AndroidCommands(object):
self.RunShellCommand(cmd, timeout_time=2 * 60))
assert os.path.exists(host_path), 'Local path not found %s' % host_path
md5sum_output = cmd_helper.GetCmdOutput(
['%s/md5sum_bin_host' % self._md5sum_build_dir, host_path])
[os.path.join(constants.GetOutDirectory(), 'md5sum_bin_host'),
host_path])
host_hash_tuples = _ParseMd5SumOutput(md5sum_output.splitlines())
return (host_hash_tuples, device_hash_tuples)

Просмотреть файл

@ -124,7 +124,7 @@ class BaseTestRunner(object):
def _ForwardPorts(self, port_pairs):
"""Forwards a port."""
Forwarder.Map(port_pairs, self.adb, constants.GetBuildType(), self.tool)
Forwarder.Map(port_pairs, self.adb, self.tool)
def _UnmapPorts(self, port_pairs):
"""Unmap previously forwarded ports."""

Просмотреть файл

@ -249,8 +249,7 @@ class TestServerThread(threading.Thread):
else:
self.is_ready = _CheckPortStatus(self.host_port, True)
if self.is_ready:
Forwarder.Map([(0, self.host_port)], self.adb, constants.GetBuildType(),
self.tool)
Forwarder.Map([(0, self.host_port)], self.adb, self.tool)
# Check whether the forwarder is ready on the device.
self.is_ready = False
device_port = Forwarder.DevicePortForHostPort(self.host_port)

Просмотреть файл

@ -97,14 +97,3 @@ def GetCmdStatusAndOutput(args, cwd=None, shell=False):
logging.debug('Truncated output:')
logging.debug(stdout[:4096])
return (exit_code, stdout)
class OutDirectory(object):
_out_directory = os.path.join(constants.DIR_SOURCE_ROOT,
os.environ.get('CHROMIUM_OUT_DIR','out'))
@staticmethod
def set(out_directory):
OutDirectory._out_directory = out_directory
@staticmethod
def get():
return OutDirectory._out_directory

Просмотреть файл

@ -132,6 +132,18 @@ def SetBuildType(build_type):
os.environ['BUILDTYPE'] = build_type
def GetOutDirectory(build_type=None):
"""Returns the out directory where the output binaries are built.
Args:
build_type: Build type, generally 'Debug' or 'Release'. Defaults to the
globally set build type environment variable BUILDTYPE.
"""
return os.path.abspath(os.path.join(
DIR_SOURCE_ROOT, os.environ.get('CHROMIUM_OUT_DIR', 'out'),
GetBuildType() if build_type is None else build_type))
def _GetADBPath():
if os.environ.get('ANDROID_SDK_ROOT'):
return 'adb'

Просмотреть файл

@ -31,9 +31,8 @@ class DeviceStatsMonitor(object):
def __init__(self, adb, hz):
self._adb = adb
host_path = os.path.abspath(os.path.join(
constants.DIR_SOURCE_ROOT, 'out', constants.GetBuildType(),
'device_stats_monitor'))
host_path = os.path.join(
constants.GetOutDirectory(), 'device_stats_monitor')
self._adb.PushIfNeeded(host_path, DeviceStatsMonitor.DEVICE_PATH)
self._hz = hz

Просмотреть файл

@ -30,8 +30,7 @@ class FakeDns(object):
subprocess instance connected to the fake_dns process on the device.
"""
self._adb.PushIfNeeded(
os.path.join(constants.DIR_SOURCE_ROOT, 'out', constants.GetBuildType(),
'fake_dns'),
os.path.join(constants.GetOutDirectory(), 'fake_dns'),
FakeDns._FAKE_DNS_PATH)
return subprocess.Popen(
['adb', '-s', self._adb._adb.GetSerialNumber(),

Просмотреть файл

@ -17,10 +17,6 @@ import constants
from pylib import valgrind_tools
def _MakeBinaryPath(build_type, binary_name):
return os.path.join(cmd_helper.OutDirectory.get(), build_type, binary_name)
def _GetProcessStartTime(pid):
return psutil.Process(pid).create_time
@ -64,7 +60,7 @@ class Forwarder(object):
os.environ[Forwarder._MULTIPROCESSING_ENV_VAR] = '1'
@staticmethod
def Map(port_pairs, adb, build_type='Debug', tool=None):
def Map(port_pairs, adb, tool=None):
"""Runs the forwarder.
Args:
@ -83,7 +79,7 @@ class Forwarder(object):
if not tool:
tool = valgrind_tools.CreateTool(None, adb)
with _FileLock(Forwarder._LOCK_PATH):
instance = Forwarder._GetInstanceLocked(build_type, tool)
instance = Forwarder._GetInstanceLocked(tool)
instance._InitDeviceLocked(adb, tool)
device_serial = adb.Adb().GetSerialNumber()
@ -137,7 +133,7 @@ class Forwarder(object):
"""
with _FileLock(Forwarder._LOCK_PATH):
port_map = Forwarder._GetInstanceLocked(
None, None)._device_to_host_port_map
None)._device_to_host_port_map
adb_serial = adb.Adb().GetSerialNumber()
for (device_serial, device_port) in port_map.keys():
if adb_serial == device_serial:
@ -148,51 +144,43 @@ class Forwarder(object):
"""Returns the device port that corresponds to a given host port."""
with _FileLock(Forwarder._LOCK_PATH):
(device_serial, device_port) = Forwarder._GetInstanceLocked(
None, None)._host_to_device_port_map.get(host_port)
None)._host_to_device_port_map.get(host_port)
return device_port
@staticmethod
def _GetInstanceLocked(build_type, tool):
def _GetInstanceLocked(tool):
"""Returns the singleton instance.
Note that the global lock must be acquired before calling this method.
Args:
build_type: 'Release' or 'Debug'
tool: Tool class to use to get wrapper, if necessary, for executing the
forwarder (see valgrind_tools.py).
"""
if not Forwarder._instance:
Forwarder._instance = Forwarder(build_type, tool)
Forwarder._instance = Forwarder(tool)
return Forwarder._instance
def __init__(self, build_type, tool):
def __init__(self, tool):
"""Constructs a new instance of Forwarder.
Note that Forwarder is a singleton therefore this constructor should be
called only once.
Args:
build_type: 'Release' or 'Debug'
tool: Tool class to use to get wrapper, if necessary, for executing the
forwarder (see valgrind_tools.py).
"""
assert not Forwarder._instance
self._build_type = build_type
self._tool = tool
self._initialized_devices = set()
self._device_to_host_port_map = dict()
self._host_to_device_port_map = dict()
self._host_forwarder_path = _MakeBinaryPath(
self._build_type, 'host_forwarder')
if not os.path.exists(self._host_forwarder_path):
self._build_type = 'Release' if self._build_type == 'Debug' else 'Debug'
self._host_forwarder_path = _MakeBinaryPath(
self._build_type, 'host_forwarder')
assert os.path.exists(
self._host_forwarder_path), 'Please build forwarder2'
self._host_forwarder_path = os.path.join(
constants.GetOutDirectory(), 'host_forwarder')
assert os.path.exists(self._host_forwarder_path), 'Please build forwarder2'
self._device_forwarder_path_on_host = os.path.join(
cmd_helper.OutDirectory.get(), self._build_type, 'forwarder_dist')
constants.GetOutDirectory(), 'forwarder_dist')
self._InitHostLocked()
@staticmethod
@ -201,7 +189,7 @@ class Forwarder(object):
Note that the global lock must be acquired before calling this method.
"""
instance = Forwarder._GetInstanceLocked(None, None)
instance = Forwarder._GetInstanceLocked(None)
serial = adb.Adb().GetSerialNumber()
serial_with_port = (serial, device_port)
if not serial_with_port in instance._device_to_host_port_map:

Просмотреть файл

@ -96,10 +96,6 @@ def _GenerateDepsDirUsingIsolate(suite_name):
Args:
suite_name: Name of the test suite (e.g. base_unittests).
"""
product_dir = os.path.join(cmd_helper.OutDirectory.get(),
constants.GetBuildType())
assert os.path.isabs(product_dir)
if os.path.isdir(constants.ISOLATE_DEPS_DIR):
shutil.rmtree(constants.ISOLATE_DEPS_DIR)
@ -110,14 +106,14 @@ def _GenerateDepsDirUsingIsolate(suite_name):
isolate_abs_path = os.path.join(constants.DIR_SOURCE_ROOT, isolate_rel_path)
isolated_abs_path = os.path.join(
product_dir, '%s.isolated' % suite_name)
constants.GetOutDirectory(), '%s.isolated' % suite_name)
assert os.path.exists(isolate_abs_path)
isolate_cmd = [
'python', _ISOLATE_SCRIPT,
'remap',
'--isolate', isolate_abs_path,
'--isolated', isolated_abs_path,
'-V', 'PRODUCT_DIR=%s' % product_dir,
'-V', 'PRODUCT_DIR=%s' % constants.GetOutDirectory(),
'-V', 'OS=android',
'--outdir', constants.ISOLATE_DEPS_DIR,
]

Просмотреть файл

@ -29,15 +29,14 @@ class TestPackageApk(TestPackage):
suite_name: Name of the test suite (e.g. base_unittests).
"""
TestPackage.__init__(self, suite_name)
product_dir = os.path.join(cmd_helper.OutDirectory.get(),
constants.GetBuildType())
if suite_name == 'content_browsertests':
self.suite_path = os.path.join(
product_dir, 'apks', '%s.apk' % suite_name)
constants.GetOutDirectory(), 'apks', '%s.apk' % suite_name)
self._package_info = constants.PACKAGE_INFO['content_browsertests']
else:
self.suite_path = os.path.join(
product_dir, '%s_apk' % suite_name, '%s-debug.apk' % suite_name)
constants.GetOutDirectory(), '%s_apk' % suite_name,
'%s-debug.apk' % suite_name)
self._package_info = constants.PACKAGE_INFO['gtest']
def _CreateCommandLineFileOnDevice(self, adb, options):

Просмотреть файл

@ -28,10 +28,9 @@ class TestPackageExecutable(TestPackage):
suite_name: Name of the test suite (e.g. base_unittests).
"""
TestPackage.__init__(self, suite_name)
product_dir = os.path.join(cmd_helper.OutDirectory.get(),
constants.GetBuildType())
self.suite_path = os.path.join(product_dir, suite_name)
self._symbols_dir = os.path.join(product_dir, 'lib.target')
self.suite_path = os.path.join(constants.GetOutDirectory(), suite_name)
self._symbols_dir = os.path.join(constants.GetOutDirectory(),
'lib.target')
#override
def GetGTestReturnCode(self, adb):

Просмотреть файл

@ -68,9 +68,10 @@ class HostDrivenTestCase(object):
def TearDown(self):
pass
# TODO(craigdh): Remove GetOutDir once references have been removed
# downstream.
def GetOutDir(self):
return os.path.join(os.environ['CHROME_SRC'], 'out',
constants.GetBuildType())
return constants.GetOutDirectory()
def Run(self):
logging.info('Running host-driven test: %s', self.tagged_name)

Просмотреть файл

@ -15,8 +15,7 @@ import flakiness_dashboard_results_uploader
def _LogToFile(results, test_type, suite_name):
"""Log results to local files which can be used for aggregation later."""
log_file_path = os.path.join(constants.DIR_SOURCE_ROOT, 'out',
constants.GetBuildType(), 'test_logs')
log_file_path = os.path.join(constants.GetOutDirectory(), 'test_logs')
if not os.path.exists(log_file_path):
os.mkdir(log_file_path)
full_file_name = os.path.join(