From babb42acc80f4c0412c824256b70cafc850010bd Mon Sep 17 00:00:00 2001 From: "craigdh@chromium.org" Date: Fri, 6 Sep 2013 18:11:02 +0000 Subject: [PATCH] [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 --- android/adb_install_apk.py | 6 ++-- android/adb_reverse_forwarder.py | 5 +-- android/pylib/android_commands.py | 21 ++++-------- android/pylib/base/base_test_runner.py | 2 +- android/pylib/chrome_test_server_spawner.py | 3 +- android/pylib/cmd_helper.py | 11 ------- android/pylib/constants.py | 12 +++++++ android/pylib/device_stats_monitor.py | 5 ++- android/pylib/fake_dns.py | 3 +- android/pylib/forwarder.py | 36 +++++++-------------- android/pylib/gtest/setup.py | 8 ++--- android/pylib/gtest/test_package_apk.py | 7 ++-- android/pylib/gtest/test_package_exe.py | 7 ++-- android/pylib/host_driven/test_case.py | 5 +-- android/pylib/utils/report_results.py | 3 +- 15 files changed, 54 insertions(+), 80 deletions(-) diff --git a/android/adb_install_apk.py b/android/adb_install_apk.py index 36adb79d5..adad48bde 100755 --- a/android/adb_install_apk.py +++ b/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/android/adb_reverse_forwarder.py b/android/adb_reverse_forwarder.py index ee38332b3..de8e6e5f4 100755 --- a/android/adb_reverse_forwarder.py +++ b/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/android/pylib/android_commands.py b/android/pylib/android_commands.py index 4228b035f..66f7bcf63 100644 --- a/android/pylib/android_commands.py +++ b/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/android/pylib/base/base_test_runner.py b/android/pylib/base/base_test_runner.py index 154ea6684..2688a6fbf 100644 --- a/android/pylib/base/base_test_runner.py +++ b/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/android/pylib/chrome_test_server_spawner.py b/android/pylib/chrome_test_server_spawner.py index b15f2917b..642e5223e 100644 --- a/android/pylib/chrome_test_server_spawner.py +++ b/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/android/pylib/cmd_helper.py b/android/pylib/cmd_helper.py index 96a30bb03..bce3f97e6 100644 --- a/android/pylib/cmd_helper.py +++ b/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/android/pylib/constants.py b/android/pylib/constants.py index 15aebaba5..46f9e1835 100644 --- a/android/pylib/constants.py +++ b/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/android/pylib/device_stats_monitor.py b/android/pylib/device_stats_monitor.py index 482965f72..2a7adc830 100644 --- a/android/pylib/device_stats_monitor.py +++ b/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/android/pylib/fake_dns.py b/android/pylib/fake_dns.py index ed99d20fb..c0e12e1dd 100644 --- a/android/pylib/fake_dns.py +++ b/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/android/pylib/forwarder.py b/android/pylib/forwarder.py index 0f4b1bc71..807634a85 100644 --- a/android/pylib/forwarder.py +++ b/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/android/pylib/gtest/setup.py b/android/pylib/gtest/setup.py index 3be6b8112..a4b0eef23 100644 --- a/android/pylib/gtest/setup.py +++ b/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/android/pylib/gtest/test_package_apk.py b/android/pylib/gtest/test_package_apk.py index 81c4cfed9..5aa473eca 100644 --- a/android/pylib/gtest/test_package_apk.py +++ b/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/android/pylib/gtest/test_package_exe.py b/android/pylib/gtest/test_package_exe.py index 7aa39d832..5da86ba4c 100644 --- a/android/pylib/gtest/test_package_exe.py +++ b/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/android/pylib/host_driven/test_case.py b/android/pylib/host_driven/test_case.py index 7ce1c3078..2fbcae8b5 100644 --- a/android/pylib/host_driven/test_case.py +++ b/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/android/pylib/utils/report_results.py b/android/pylib/utils/report_results.py index 75ef3222d..2668145e3 100644 --- a/android/pylib/utils/report_results.py +++ b/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(