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

Side by Side Diff: build/android/pylib/local/device/local_device_environment.py

Issue 2320903002: Allow test_runner.py to run host perf tests without devices attached (Closed)
Patch Set: Created 4 years, 3 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 unified diff | Download patch
OLDNEW
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 functools 6 import functools
7 import logging 7 import logging
8 import os 8 import os
9 import shutil 9 import shutil
10 import tempfile 10 import tempfile
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 class LocalDeviceEnvironment(environment.Environment): 74 class LocalDeviceEnvironment(environment.Environment):
75 75
76 def __init__(self, args, _error_func): 76 def __init__(self, args, _error_func):
77 super(LocalDeviceEnvironment, self).__init__() 77 super(LocalDeviceEnvironment, self).__init__()
78 self._blacklist = (device_blacklist.Blacklist(args.blacklist_file) 78 self._blacklist = (device_blacklist.Blacklist(args.blacklist_file)
79 if args.blacklist_file 79 if args.blacklist_file
80 else None) 80 else None)
81 self._device_serial = args.test_device 81 self._device_serial = args.test_device
82 self._devices_lock = threading.Lock() 82 self._devices_lock = threading.Lock()
83 self._devices = [] 83 self._devices = None
84 self._concurrent_adb = args.enable_concurrent_adb 84 self._concurrent_adb = args.enable_concurrent_adb
85 self._enable_device_cache = args.enable_device_cache 85 self._enable_device_cache = args.enable_device_cache
86 self._logcat_monitors = [] 86 self._logcat_monitors = []
87 self._logcat_output_dir = args.logcat_output_dir 87 self._logcat_output_dir = args.logcat_output_dir
88 self._logcat_output_file = args.logcat_output_file 88 self._logcat_output_file = args.logcat_output_file
89 self._max_tries = 1 + args.num_retries 89 self._max_tries = 1 + args.num_retries
90 self._skip_clear_data = args.skip_clear_data 90 self._skip_clear_data = args.skip_clear_data
91 self._target_devices_file = args.target_devices_file 91 self._target_devices_file = args.target_devices_file
92 self._tool_name = args.tool 92 self._tool_name = args.tool
93 93
94 #override 94 #override
95 def SetUp(self): 95 def SetUp(self):
96 pass
97
98 def _InitDevices(self):
96 device_arg = 'default' 99 device_arg = 'default'
97 if self._target_devices_file: 100 if self._target_devices_file:
98 device_arg = device_list.GetPersistentDeviceList( 101 device_arg = device_list.GetPersistentDeviceList(
99 self._target_devices_file) 102 self._target_devices_file)
100 if not device_arg: 103 if not device_arg:
101 logging.warning('No target devices specified. Falling back to ' 104 logging.warning('No target devices specified. Falling back to '
102 'running on all available devices.') 105 'running on all available devices.')
103 device_arg = 'default' 106 device_arg = 'default'
104 else: 107 else:
105 logging.info( 108 logging.info(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 @property 145 @property
143 def blacklist(self): 146 def blacklist(self):
144 return self._blacklist 147 return self._blacklist
145 148
146 @property 149 @property
147 def concurrent_adb(self): 150 def concurrent_adb(self):
148 return self._concurrent_adb 151 return self._concurrent_adb
149 152
150 @property 153 @property
151 def devices(self): 154 def devices(self):
155 # Initialize lazily so that host-only tests do not fail when no devices are
156 # attached.
157 if self._devices is None:
158 self._InitDevices()
152 if not self._devices: 159 if not self._devices:
153 raise device_errors.NoDevicesError() 160 raise device_errors.NoDevicesError()
154 return self._devices 161 return self._devices
155 162
156 @property 163 @property
157 def max_tries(self): 164 def max_tries(self):
158 return self._max_tries 165 return self._max_tries
159 166
160 @property 167 @property
161 def parallel_devices(self): 168 def parallel_devices(self):
162 return parallelizer.SyncParallelizer(self.devices) 169 return parallelizer.SyncParallelizer(self.devices)
163 170
164 @property 171 @property
165 def skip_clear_data(self): 172 def skip_clear_data(self):
166 return self._skip_clear_data 173 return self._skip_clear_data
167 174
168 @property 175 @property
169 def tool(self): 176 def tool(self):
170 return self._tool_name 177 return self._tool_name
171 178
172 #override 179 #override
173 def TearDown(self): 180 def TearDown(self):
181 if self._devices is None:
182 return
174 @handle_shard_failures_with(on_failure=self.BlacklistDevice) 183 @handle_shard_failures_with(on_failure=self.BlacklistDevice)
175 def tear_down_device(d): 184 def tear_down_device(d):
176 # Write the cache even when not using it so that it will be ready the 185 # Write the cache even when not using it so that it will be ready the
177 # first time that it is enabled. Writing it every time is also necessary 186 # first time that it is enabled. Writing it every time is also necessary
178 # so that an invalid cache can be flushed just by disabling it for one 187 # so that an invalid cache can be flushed just by disabling it for one
179 # run. 188 # run.
180 cache_path = _DeviceCachePath(d) 189 cache_path = _DeviceCachePath(d)
181 with open(cache_path, 'w') as f: 190 with open(cache_path, 'w') as f:
182 f.write(d.DumpCacheData()) 191 f.write(d.DumpCacheData())
183 logging.info('Wrote device cache: %s', cache_path) 192 logging.info('Wrote device cache: %s', cache_path)
(...skipping 24 matching lines...) Expand all
208 if os.path.exists(m.output_file)]) 217 if os.path.exists(m.output_file)])
209 shutil.rmtree(self._logcat_output_dir) 218 shutil.rmtree(self._logcat_output_dir)
210 219
211 def BlacklistDevice(self, device, reason='local_device_failure'): 220 def BlacklistDevice(self, device, reason='local_device_failure'):
212 device_serial = device.adb.GetDeviceSerial() 221 device_serial = device.adb.GetDeviceSerial()
213 if self._blacklist: 222 if self._blacklist:
214 self._blacklist.Extend([device_serial], reason=reason) 223 self._blacklist.Extend([device_serial], reason=reason)
215 with self._devices_lock: 224 with self._devices_lock:
216 self._devices = [d for d in self._devices if str(d) != device_serial] 225 self._devices = [d for d in self._devices if str(d) != device_serial]
217 226
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698