Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / build / android / pylib / local / device / local_device_environment.py
blobee0ff987afd353f22095d06d3c52f4014dddcf44
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
3 # found in the LICENSE file.
5 import logging
6 import threading
8 from devil.android import device_blacklist
9 from devil.android import device_errors
10 from devil.android import device_utils
11 from devil.utils import parallelizer
12 from pylib.base import environment
15 class LocalDeviceEnvironment(environment.Environment):
17 def __init__(self, args, _error_func):
18 super(LocalDeviceEnvironment, self).__init__()
19 self._blacklist = (device_blacklist.Blacklist(args.blacklist_file)
20 if args.blacklist_file
21 else None)
22 self._device_serial = args.test_device
23 self._devices_lock = threading.Lock()
24 self._devices = []
25 self._max_tries = 1 + args.num_retries
26 self._tool_name = args.tool
28 #override
29 def SetUp(self):
30 available_devices = device_utils.DeviceUtils.HealthyDevices(
31 self._blacklist)
32 if not available_devices:
33 raise device_errors.NoDevicesError
34 if self._device_serial:
35 self._devices = [d for d in available_devices
36 if d.adb.GetDeviceSerial() == self._device_serial]
37 if not self._devices:
38 raise device_errors.DeviceUnreachableError(
39 'Could not find device %r' % self._device_serial)
40 else:
41 self._devices = available_devices
43 @property
44 def devices(self):
45 if not self._devices:
46 raise device_errors.NoDevicesError()
47 return self._devices
49 @property
50 def parallel_devices(self):
51 return parallelizer.SyncParallelizer(self.devices)
53 @property
54 def max_tries(self):
55 return self._max_tries
57 @property
58 def tool(self):
59 return self._tool_name
61 #override
62 def TearDown(self):
63 pass
65 def BlacklistDevice(self, device):
66 if not self._blacklist:
67 logging.warning(
68 'Attempted to blacklist %s, but no blacklist was provided.',
69 str(device))
70 return
72 device_serial = device.adb.GetDeviceSerial()
73 self._blacklist.Extend([device_serial])
74 with self._devices_lock:
75 self._devices = [d for d in self._devices if str(d) != device_serial]