Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Unified Diff: build/android/pylib/device/device_utils.py

Issue 290573004: [Android] Support generic parallel execution across devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix the parallelizer tests Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/provision_devices.py ('k') | build/android/pylib/utils/parallelizer.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/device/device_utils.py
diff --git a/build/android/pylib/device/device_utils.py b/build/android/pylib/device/device_utils.py
index ea1019d3de996f44b6bcb95785541b7570ee4344..ff99fccdc83729d0b3c88199cba46e116401875e 100644
--- a/build/android/pylib/device/device_utils.py
+++ b/build/android/pylib/device/device_utils.py
@@ -9,52 +9,16 @@ Eventually, this will be based on adb_wrapper.
"""
# pylint: disable=W0613
-import multiprocessing
-import os
-import sys
-
import pylib.android_commands
from pylib.device import adb_wrapper
from pylib.device import decorators
from pylib.device import device_errors
-
-CHROME_SRC_DIR = os.path.abspath(
- os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
-sys.path.append(os.path.join(
- CHROME_SRC_DIR, 'third_party', 'android_testrunner'))
-import errors
+from pylib.utils import parallelizer
_DEFAULT_TIMEOUT = 30
_DEFAULT_RETRIES = 3
-# multiprocessing map_async requires a top-level function for pickle library.
-def RebootDeviceSafe(device):
- """Reboot a device, wait for it to start, and squelch timeout exceptions."""
- try:
- DeviceUtils(device).old_interface.Reboot(True)
- except errors.DeviceUnresponsiveError as e:
- return e
-
-
-def RebootDevices():
- """Reboot all attached and online devices."""
- devices = pylib.android_commands.GetAttachedDevices()
- print 'Rebooting: %s' % devices
- if devices:
- pool = multiprocessing.Pool(len(devices))
- results = pool.map_async(RebootDeviceSafe, devices).get(99999)
-
- for device, result in zip(devices, results):
- if result:
- print '%s failed to startup.' % device
-
- if any(results):
- print 'RebootDevices() Warning: %s' % results
- else:
- print 'Reboots complete.'
-
-
@decorators.WithExplicitTimeoutAndRetries(
_DEFAULT_TIMEOUT, _DEFAULT_RETRIES)
def GetAVDs():
@@ -150,3 +114,26 @@ class DeviceUtils(object):
raise device_errors.CommandFailedError(
'adb root', 'Could not enable root.')
+ def __str__(self):
+ """Returns the device serial."""
+ return self.old_interface.GetDevice()
+
+ @staticmethod
+ def parallel(devices):
+ """ Creates a Parallelizer to operate over the provided list of devices.
+
+ If |devices| is either |None| or an empty list, the Parallelizer will
+ operate over all attached devices.
+
+ Args:
+ devices: A list of either DeviceUtils instances or objects from
+ from which DeviceUtils instances can be constructed.
+ Returns:
+ A Parallelizer operating over |devices|.
+ """
+ if not devices or len(devices) == 0:
+ devices = pylib.android_commands.AndroidCommands.GetAttachedDevices()
+ return parallelizer.Parallelizer([
+ d if isinstance(d, DeviceUtils) else DeviceUtils(d)
+ for d in devices])
+
« no previous file with comments | « build/android/provision_devices.py ('k') | build/android/pylib/utils/parallelizer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698