Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """ | 5 """ |
| 6 Provides a variety of device interactions based on adb. | 6 Provides a variety of device interactions based on adb. |
| 7 | 7 |
| 8 Eventually, this will be based on adb_wrapper. | 8 Eventually, this will be based on adb_wrapper. |
| 9 """ | 9 """ |
| 10 # pylint: disable=W0613 | 10 # pylint: disable=W0613 |
| 11 | 11 |
| 12 import multiprocessing | |
| 13 import os | |
| 14 import sys | |
| 15 | |
| 16 import pylib.android_commands | 12 import pylib.android_commands |
| 17 from pylib.device import adb_wrapper | 13 from pylib.device import adb_wrapper |
| 18 from pylib.device import decorators | 14 from pylib.device import decorators |
| 19 from pylib.device import device_errors | 15 from pylib.device import device_errors |
| 20 | 16 from pylib.utils import parallelizer |
| 21 CHROME_SRC_DIR = os.path.abspath( | |
| 22 os.path.join(os.path.dirname(__file__), '..', '..', '..', '..')) | |
| 23 sys.path.append(os.path.join( | |
| 24 CHROME_SRC_DIR, 'third_party', 'android_testrunner')) | |
| 25 import errors | |
| 26 | 17 |
| 27 _DEFAULT_TIMEOUT = 30 | 18 _DEFAULT_TIMEOUT = 30 |
| 28 _DEFAULT_RETRIES = 3 | 19 _DEFAULT_RETRIES = 3 |
| 29 | 20 |
| 30 | 21 |
| 31 # multiprocessing map_async requires a top-level function for pickle library. | |
| 32 def RebootDeviceSafe(device): | |
| 33 """Reboot a device, wait for it to start, and squelch timeout exceptions.""" | |
| 34 try: | |
| 35 DeviceUtils(device).old_interface.Reboot(True) | |
| 36 except errors.DeviceUnresponsiveError as e: | |
| 37 return e | |
| 38 | |
| 39 | |
| 40 def RebootDevices(): | |
| 41 """Reboot all attached and online devices.""" | |
| 42 devices = pylib.android_commands.GetAttachedDevices() | |
| 43 print 'Rebooting: %s' % devices | |
| 44 if devices: | |
| 45 pool = multiprocessing.Pool(len(devices)) | |
| 46 results = pool.map_async(RebootDeviceSafe, devices).get(99999) | |
| 47 | |
| 48 for device, result in zip(devices, results): | |
| 49 if result: | |
| 50 print '%s failed to startup.' % device | |
| 51 | |
| 52 if any(results): | |
| 53 print 'RebootDevices() Warning: %s' % results | |
| 54 else: | |
| 55 print 'Reboots complete.' | |
| 56 | |
| 57 | |
| 58 @decorators.WithExplicitTimeoutAndRetries( | 22 @decorators.WithExplicitTimeoutAndRetries( |
| 59 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) | 23 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) |
| 60 def GetAVDs(): | 24 def GetAVDs(): |
| 61 """ Returns a list of Android Virtual Devices. | 25 """ Returns a list of Android Virtual Devices. |
| 62 | 26 |
| 63 Returns: | 27 Returns: |
| 64 A list containing the configured AVDs. | 28 A list containing the configured AVDs. |
| 65 """ | 29 """ |
| 66 return pylib.android_commands.GetAVDs() | 30 return pylib.android_commands.GetAVDs() |
| 67 | 31 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 Args: | 107 Args: |
| 144 timeout: Same as for |IsOnline|. | 108 timeout: Same as for |IsOnline|. |
| 145 retries: Same as for |IsOnline|. | 109 retries: Same as for |IsOnline|. |
| 146 Raises: | 110 Raises: |
| 147 CommandFailedError if root could not be enabled. | 111 CommandFailedError if root could not be enabled. |
| 148 """ | 112 """ |
| 149 if not self.old_interface.EnableAdbRoot(): | 113 if not self.old_interface.EnableAdbRoot(): |
| 150 raise device_errors.CommandFailedError( | 114 raise device_errors.CommandFailedError( |
| 151 'adb root', 'Could not enable root.') | 115 'adb root', 'Could not enable root.') |
| 152 | 116 |
| 117 def __str__(self): | |
| 118 return self.old_interface.GetDevice() | |
| 119 | |
| 120 @staticmethod | |
| 121 def parallel(devices): | |
|
frankf
2014/05/21 22:34:27
add docstring for this
| |
| 122 if not devices or len(devices) == 0: | |
| 123 devices = pylib.android_commands.AndroidCommands.GetAttachedDevices() | |
| 124 return parallelizer.Parallelizer([ | |
| 125 d if isinstance(d, DeviceUtils) else DeviceUtils(d) | |
| 126 for d in devices]) | |
| 127 | |
| OLD | NEW |