diff options
author | craigdh@chromium.org <craigdh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-06 18:11:02 +0000 |
---|---|---|
committer | craigdh@chromium.org <craigdh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-06 18:11:02 +0000 |
commit | 8b0e097bff94843b6b30f92ceebb540480216fe1 (patch) | |
tree | 2401d39a7581c145e988e66f4e6c6af749b062d1 | |
parent | af4932055f794a081494fada7637b2f4fe3cde60 (diff) | |
download | chromium_src-8b0e097bff94843b6b30f92ceebb540480216fe1.zip chromium_src-8b0e097bff94843b6b30f92ceebb540480216fe1.tar.gz chromium_src-8b0e097bff94843b6b30f92ceebb540480216fe1.tar.bz2 |
[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: svn://svn.chromium.org/chrome/trunk/src@221736 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-x | build/android/adb_install_apk.py | 6 | ||||
-rwxr-xr-x | build/android/adb_reverse_forwarder.py | 5 | ||||
-rw-r--r-- | build/android/pylib/android_commands.py | 21 | ||||
-rw-r--r-- | build/android/pylib/base/base_test_runner.py | 2 | ||||
-rw-r--r-- | build/android/pylib/chrome_test_server_spawner.py | 3 | ||||
-rw-r--r-- | build/android/pylib/cmd_helper.py | 11 | ||||
-rw-r--r-- | build/android/pylib/constants.py | 12 | ||||
-rw-r--r-- | build/android/pylib/device_stats_monitor.py | 5 | ||||
-rw-r--r-- | build/android/pylib/fake_dns.py | 3 | ||||
-rw-r--r-- | build/android/pylib/forwarder.py | 36 | ||||
-rw-r--r-- | build/android/pylib/gtest/setup.py | 8 | ||||
-rw-r--r-- | build/android/pylib/gtest/test_package_apk.py | 7 | ||||
-rw-r--r-- | build/android/pylib/gtest/test_package_exe.py | 7 | ||||
-rw-r--r-- | build/android/pylib/host_driven/test_case.py | 5 | ||||
-rw-r--r-- | build/android/pylib/utils/report_results.py | 3 | ||||
-rw-r--r-- | chrome/test/functional/ispy/ispy_core/tools/reverse_port_forwarder.py | 2 | ||||
-rw-r--r-- | tools/telemetry/telemetry/core/backends/adb_commands.py | 21 |
17 files changed, 67 insertions, 90 deletions
diff --git a/build/android/adb_install_apk.py b/build/android/adb_install_apk.py index 36adb79..adad48b 100755 --- a/build/android/adb_install_apk.py +++ b/build/android/adb_install_apk.py @@ -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:]) diff --git a/build/android/adb_reverse_forwarder.py b/build/android/adb_reverse_forwarder.py index ee38332..de8e6e5 100755 --- a/build/android/adb_reverse_forwarder.py +++ b/build/android/adb_reverse_forwarder.py @@ -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: diff --git a/build/android/pylib/android_commands.py b/build/android/pylib/android_commands.py index 4228b03..66f7bcf 100644 --- a/build/android/pylib/android_commands.py +++ b/build/android/pylib/android_commands.py @@ -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) diff --git a/build/android/pylib/base/base_test_runner.py b/build/android/pylib/base/base_test_runner.py index 154ea66..2688a6f 100644 --- a/build/android/pylib/base/base_test_runner.py +++ b/build/android/pylib/base/base_test_runner.py @@ -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.""" diff --git a/build/android/pylib/chrome_test_server_spawner.py b/build/android/pylib/chrome_test_server_spawner.py index b15f291..642e522 100644 --- a/build/android/pylib/chrome_test_server_spawner.py +++ b/build/android/pylib/chrome_test_server_spawner.py @@ -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) diff --git a/build/android/pylib/cmd_helper.py b/build/android/pylib/cmd_helper.py index 96a30bb..bce3f97 100644 --- a/build/android/pylib/cmd_helper.py +++ b/build/android/pylib/cmd_helper.py @@ -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 diff --git a/build/android/pylib/constants.py b/build/android/pylib/constants.py index 15aebab..46f9e18 100644 --- a/build/android/pylib/constants.py +++ b/build/android/pylib/constants.py @@ -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' diff --git a/build/android/pylib/device_stats_monitor.py b/build/android/pylib/device_stats_monitor.py index 482965f..2a7adc8 100644 --- a/build/android/pylib/device_stats_monitor.py +++ b/build/android/pylib/device_stats_monitor.py @@ -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 diff --git a/build/android/pylib/fake_dns.py b/build/android/pylib/fake_dns.py index ed99d20..c0e12e1 100644 --- a/build/android/pylib/fake_dns.py +++ b/build/android/pylib/fake_dns.py @@ -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(), diff --git a/build/android/pylib/forwarder.py b/build/android/pylib/forwarder.py index 0f4b1bc..807634a 100644 --- a/build/android/pylib/forwarder.py +++ b/build/android/pylib/forwarder.py @@ -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: diff --git a/build/android/pylib/gtest/setup.py b/build/android/pylib/gtest/setup.py index 3be6b81..a4b0eef 100644 --- a/build/android/pylib/gtest/setup.py +++ b/build/android/pylib/gtest/setup.py @@ -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, ] diff --git a/build/android/pylib/gtest/test_package_apk.py b/build/android/pylib/gtest/test_package_apk.py index 81c4cfe..5aa473e 100644 --- a/build/android/pylib/gtest/test_package_apk.py +++ b/build/android/pylib/gtest/test_package_apk.py @@ -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): diff --git a/build/android/pylib/gtest/test_package_exe.py b/build/android/pylib/gtest/test_package_exe.py index 7aa39d8..5da86ba 100644 --- a/build/android/pylib/gtest/test_package_exe.py +++ b/build/android/pylib/gtest/test_package_exe.py @@ -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): diff --git a/build/android/pylib/host_driven/test_case.py b/build/android/pylib/host_driven/test_case.py index 7ce1c30..2fbcae8 100644 --- a/build/android/pylib/host_driven/test_case.py +++ b/build/android/pylib/host_driven/test_case.py @@ -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) diff --git a/build/android/pylib/utils/report_results.py b/build/android/pylib/utils/report_results.py index 75ef322..2668145 100644 --- a/build/android/pylib/utils/report_results.py +++ b/build/android/pylib/utils/report_results.py @@ -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( diff --git a/chrome/test/functional/ispy/ispy_core/tools/reverse_port_forwarder.py b/chrome/test/functional/ispy/ispy_core/tools/reverse_port_forwarder.py index 0c45152..90aec16 100644 --- a/chrome/test/functional/ispy/ispy_core/tools/reverse_port_forwarder.py +++ b/chrome/test/functional/ispy/ispy_core/tools/reverse_port_forwarder.py @@ -55,7 +55,7 @@ class ReversePortForwarder(object): # Begin forwarding the device_ports to the host_ports. forwarder.Forwarder.Map([(self._device_http, self._host_http), (self._device_https, self._host_https)], - self._adb, build_type='Release', tool=None) + self._adb, tool=None) def Stop(self): """Cleans up after the start call by closing the forwarder.""" diff --git a/tools/telemetry/telemetry/core/backends/adb_commands.py b/tools/telemetry/telemetry/core/backends/adb_commands.py index bd749e9..e02a3fa 100644 --- a/tools/telemetry/telemetry/core/backends/adb_commands.py +++ b/tools/telemetry/telemetry/core/backends/adb_commands.py @@ -14,7 +14,7 @@ from telemetry.core import util util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android') try: from pylib import android_commands # pylint: disable=F0401 - from pylib import cmd_helper # pylint: disable=F0401 + from pylib import constants # pylint: disable=F0401 from pylib import forwarder # pylint: disable=F0401 from pylib import ports # pylint: disable=F0401 except Exception: @@ -41,10 +41,6 @@ def ResetTestServerPortAllocation(): return ports.ResetTestServerPortAllocation() -def GetOutDirectory(): - return cmd_helper.OutDirectory.get() - - class AdbCommands(object): """A thin wrapper around ADB""" @@ -151,10 +147,11 @@ def HasForwarder(buildtype=None): if not buildtype: return (HasForwarder(buildtype='Release') or HasForwarder(buildtype='Debug')) - return (os.path.exists(os.path.join(GetOutDirectory(), buildtype, - 'device_forwarder')) and - os.path.exists(os.path.join(GetOutDirectory(), buildtype, - 'host_forwarder'))) + device_forwarder = os.path.join( + constants.GetOutDirectory(build_type=buildtype), 'device_forwarder') + host_forwarder = os.path.join( + constants.GetOutDirectory(build_type=buildtype), 'host_forwarder') + return os.path.exists(device_forwarder) and os.path.exists(host_forwarder) class Forwarder(object): def __init__(self, adb, *port_pairs): @@ -165,6 +162,12 @@ class Forwarder(object): for port_pair in port_pairs] self._port_pairs = new_port_pairs + if HasForwarder('Release'): + constants.SetBuildType('Release') + elif HasForwarder('Debug'): + constants.SetBuildType('Debug') + else: + raise Exception('Build forwarder2') forwarder.Forwarder.Map(new_port_pairs, self._adb) @property |