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 import datetime | 5 import datetime |
6 import logging | 6 import logging |
7 import os | 7 import os |
8 import shutil | 8 import shutil |
9 import tempfile | 9 import tempfile |
10 import threading | 10 import threading |
(...skipping 16 matching lines...) Expand all Loading... |
27 class LocalDeviceEnvironment(environment.Environment): | 27 class LocalDeviceEnvironment(environment.Environment): |
28 | 28 |
29 def __init__(self, args, _error_func): | 29 def __init__(self, args, _error_func): |
30 super(LocalDeviceEnvironment, self).__init__() | 30 super(LocalDeviceEnvironment, self).__init__() |
31 self._blacklist = (device_blacklist.Blacklist(args.blacklist_file) | 31 self._blacklist = (device_blacklist.Blacklist(args.blacklist_file) |
32 if args.blacklist_file | 32 if args.blacklist_file |
33 else None) | 33 else None) |
34 self._device_serial = args.test_device | 34 self._device_serial = args.test_device |
35 self._devices_lock = threading.Lock() | 35 self._devices_lock = threading.Lock() |
36 self._devices = [] | 36 self._devices = [] |
37 self._max_tries = 1 + args.num_retries | 37 self._concurrent_adb = args.enable_concurrent_adb |
38 self._tool_name = args.tool | |
39 self._enable_device_cache = args.enable_device_cache | 38 self._enable_device_cache = args.enable_device_cache |
40 self._concurrent_adb = args.enable_concurrent_adb | 39 self._logcat_monitors = [] |
41 self._logcat_output_dir = args.logcat_output_dir | 40 self._logcat_output_dir = args.logcat_output_dir |
42 self._logcat_output_file = args.logcat_output_file | 41 self._logcat_output_file = args.logcat_output_file |
43 self._logcat_monitors = [] | 42 self._max_tries = 1 + args.num_retries |
| 43 self._skip_clear_data = args.skip_clear_data |
| 44 self._tool_name = args.tool |
44 | 45 |
45 #override | 46 #override |
46 def SetUp(self): | 47 def SetUp(self): |
47 available_devices = device_utils.DeviceUtils.HealthyDevices( | 48 available_devices = device_utils.DeviceUtils.HealthyDevices( |
48 self._blacklist, enable_device_files_cache=self._enable_device_cache, | 49 self._blacklist, enable_device_files_cache=self._enable_device_cache, |
49 default_retries=self._max_tries - 1) | 50 default_retries=self._max_tries - 1) |
50 if not available_devices: | 51 if not available_devices: |
51 raise device_errors.NoDevicesError | 52 raise device_errors.NoDevicesError |
52 if self._device_serial: | 53 if self._device_serial: |
53 self._devices = [d for d in available_devices | 54 self._devices = [d for d in available_devices |
(...skipping 20 matching lines...) Expand all Loading... |
74 logcat_file = os.path.join( | 75 logcat_file = os.path.join( |
75 self._logcat_output_dir, | 76 self._logcat_output_dir, |
76 '%s_%s' % (d.adb.GetDeviceSerial(), | 77 '%s_%s' % (d.adb.GetDeviceSerial(), |
77 datetime.datetime.utcnow().strftime('%Y%m%dT%H%M%S'))) | 78 datetime.datetime.utcnow().strftime('%Y%m%dT%H%M%S'))) |
78 monitor = logcat_monitor.LogcatMonitor( | 79 monitor = logcat_monitor.LogcatMonitor( |
79 d.adb, clear=True, output_file=logcat_file) | 80 d.adb, clear=True, output_file=logcat_file) |
80 self._logcat_monitors.append(monitor) | 81 self._logcat_monitors.append(monitor) |
81 monitor.Start() | 82 monitor.Start() |
82 | 83 |
83 @property | 84 @property |
| 85 def concurrent_adb(self): |
| 86 return self._concurrent_adb |
| 87 |
| 88 @property |
84 def devices(self): | 89 def devices(self): |
85 if not self._devices: | 90 if not self._devices: |
86 raise device_errors.NoDevicesError() | 91 raise device_errors.NoDevicesError() |
87 return self._devices | 92 return self._devices |
88 | 93 |
89 @property | 94 @property |
90 def concurrent_adb(self): | 95 def max_tries(self): |
91 return self._concurrent_adb | 96 return self._max_tries |
92 | 97 |
93 @property | 98 @property |
94 def parallel_devices(self): | 99 def parallel_devices(self): |
95 return parallelizer.SyncParallelizer(self.devices) | 100 return parallelizer.SyncParallelizer(self.devices) |
96 | 101 |
97 @property | 102 @property |
98 def max_tries(self): | 103 def skip_clear_data(self): |
99 return self._max_tries | 104 return self._skip_clear_data |
100 | 105 |
101 @property | 106 @property |
102 def tool(self): | 107 def tool(self): |
103 return self._tool_name | 108 return self._tool_name |
104 | 109 |
105 #override | 110 #override |
106 def TearDown(self): | 111 def TearDown(self): |
107 # Write the cache even when not using it so that it will be ready the first | 112 # Write the cache even when not using it so that it will be ready the first |
108 # time that it is enabled. Writing it every time is also necessary so that | 113 # time that it is enabled. Writing it every time is also necessary so that |
109 # an invalid cache can be flushed just by disabling it for one run. | 114 # an invalid cache can be flushed just by disabling it for one run. |
(...skipping 11 matching lines...) Expand all Loading... |
121 [m.output_file for m in self._logcat_monitors]) | 126 [m.output_file for m in self._logcat_monitors]) |
122 shutil.rmtree(self._logcat_output_dir) | 127 shutil.rmtree(self._logcat_output_dir) |
123 | 128 |
124 def BlacklistDevice(self, device, reason='local_device_failure'): | 129 def BlacklistDevice(self, device, reason='local_device_failure'): |
125 device_serial = device.adb.GetDeviceSerial() | 130 device_serial = device.adb.GetDeviceSerial() |
126 if self._blacklist: | 131 if self._blacklist: |
127 self._blacklist.Extend([device_serial], reason=reason) | 132 self._blacklist.Extend([device_serial], reason=reason) |
128 with self._devices_lock: | 133 with self._devices_lock: |
129 self._devices = [d for d in self._devices if str(d) != device_serial] | 134 self._devices = [d for d in self._devices if str(d) != device_serial] |
130 | 135 |
OLD | NEW |