X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Ftools%2Ftelemetry%2Ftelemetry%2Fcore%2Fbackends%2Fadb_commands.py;h=737da375ff9b4cd974ebfc066bd503fb865b9569;hb=ff3e2503a20db9193d323c1d19c38c68004dec4a;hp=eca8b83a85e8e0ccfe22abee481c536191298e04;hpb=4b53d56b8a1db20d4089f6d4f37126d43f907125;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/tools/telemetry/telemetry/core/backends/adb_commands.py b/src/tools/telemetry/telemetry/core/backends/adb_commands.py index eca8b83..737da37 100644 --- a/src/tools/telemetry/telemetry/core/backends/adb_commands.py +++ b/src/tools/telemetry/telemetry/core/backends/adb_commands.py @@ -1,6 +1,7 @@ # Copyright 2013 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. + """Brings in Chrome Android's android_commands module, which itself is a thin(ish) wrapper around adb.""" @@ -21,9 +22,9 @@ util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android') try: from pylib import android_commands # pylint: disable=F0401 from pylib import constants # pylint: disable=F0401 - from pylib import forwarder # pylint: disable=F0401 from pylib import ports # pylint: disable=F0401 - from pylib.utils import apk_helper # #pylint: disable=F0401 + from pylib.utils import apk_helper # pylint: disable=F0401 + from pylib.utils import test_environment # pylint: disable=F0401 except Exception: android_commands = None @@ -40,6 +41,10 @@ def GetAttachedDevices(): return android_commands.GetAttachedDevices() +def CleanupLeftoverProcesses(): + test_environment.CleanupLeftoverProcesses() + + def AllocateTestServerPort(): return ports.AllocateTestServerPort() @@ -52,12 +57,16 @@ class AdbCommands(object): """A thin wrapper around ADB""" def __init__(self, device): - self._adb = android_commands.AndroidCommands(device) + self._adb = android_commands.AndroidCommands(device, api_strict_mode=True) self._device = device def device(self): return self._device + @property + def system_properties(self): + return self._adb.system_properties + def Adb(self): return self._adb @@ -81,6 +90,9 @@ class AdbCommands(object): """ return self._adb.RunShellCommand(command, timeout_time, log_result) + def RunShellCommandWithSU(self, command, timeout_time=20, log_result=False): + return self._adb.RunShellCommandWithSU(command, timeout_time, log_result) + def CloseApplication(self, package): """Attempt to close down the application, using increasing violence. @@ -170,70 +182,63 @@ class AdbCommands(object): def GoHome(self): return self._adb.GoHome() + def RestartAdbdOnDevice(self): + return self._adb.RestartAdbdOnDevice() + + def IsUserBuild(self): + return self._adb.GetBuildType() == 'user' + + +def GetBuildTypeOfPath(path): + if not path: + return None + for build_dir, build_type in util.GetBuildDirectories(): + if os.path.join(build_dir, build_type) in path: + return build_type + return None + -def SetupPrebuiltTools(device): +def SetupPrebuiltTools(adb): # TODO(bulach): build the host tools for mac, and the targets for x86/mips. # Prebuilt tools from r226197. has_prebuilt = sys.platform.startswith('linux') if has_prebuilt: - adb = AdbCommands(device) - abi = adb.RunShellCommand('getprop ro.product.cpu.abi') - has_prebuilt = abi and abi[0].startswith('armeabi') + abi = adb.system_properties['ro.product.cpu.abi'] + has_prebuilt = abi.startswith('armeabi') if not has_prebuilt: - logging.error('Prebuilt tools only available for ARM.') + logging.error( + 'Prebuilt android tools only available for Linux host and ARM device.') return False prebuilt_tools = [ + 'bitmaptools', + 'file_poller', 'forwarder_dist/device_forwarder', 'host_forwarder', 'md5sum_dist/md5sum_bin', 'md5sum_bin_host', + 'purge_ashmem', ] + build_type = None for t in prebuilt_tools: src = os.path.basename(t) android_prebuilt_profiler_helper.GetIfChanged(src) + bin_path = util.FindSupportBinary(t) + if not build_type: + build_type = GetBuildTypeOfPath(bin_path) or 'Release' + constants.SetBuildType(build_type) dest = os.path.join(constants.GetOutDirectory(), t) - if not os.path.exists(dest): + if not bin_path: logging.warning('Setting up prebuilt %s', dest) if not os.path.exists(os.path.dirname(dest)): os.makedirs(os.path.dirname(dest)) - shutil.copyfile(android_prebuilt_profiler_helper.GetHostPath(src), dest) + prebuilt_path = android_prebuilt_profiler_helper.GetHostPath(src) + if not os.path.exists(prebuilt_path): + raise NotImplementedError(""" +%s must be checked into cloud storage. +Instructions: +http://www.chromium.org/developers/telemetry/upload_to_cloud_storage +""" % t) + shutil.copyfile(prebuilt_path, dest) os.chmod(dest, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) return True - -def HasForwarder(buildtype=None): - if not buildtype: - return (HasForwarder(buildtype='Release') or - HasForwarder(buildtype='Debug')) - device_forwarder = os.path.join( - constants.GetOutDirectory(build_type=buildtype), - 'forwarder_dist', '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): - self._adb = adb.Adb() - self._host_port = port_pairs[0].local_port - - new_port_pairs = [(port_pair.local_port, port_pair.remote_port) - 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 - def url(self): - return 'http://127.0.0.1:%i' % self._host_port - - def Close(self): - for (device_port, _) in self._port_pairs: - forwarder.Forwarder.UnmapDevicePort(device_port, self._adb)