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

Side by Side Diff: build/android/buildbot/bb_device_status_check.py

Issue 1299573002: [Android] Revise recovery logic in device_status_check. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2013 The Chromium Authors. All rights reserved. 3 # Copyright 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """A class to keep track of devices across builds and report state.""" 7 """A class to keep track of devices across builds and report state."""
8 import json 8 import json
9 import logging 9 import logging
10 import optparse 10 import optparse
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 except (psutil.NoSuchProcess, psutil.AccessDenied): 217 except (psutil.NoSuchProcess, psutil.AccessDenied):
218 pass 218 pass
219 for p in GetAllAdb(): 219 for p in GetAllAdb():
220 try: 220 try:
221 logging.error('Unable to kill %d (%s [%s])', p.pid, p.name, 221 logging.error('Unable to kill %d (%s [%s])', p.pid, p.name,
222 ' '.join(p.cmdline)) 222 ' '.join(p.cmdline))
223 except (psutil.NoSuchProcess, psutil.AccessDenied): 223 except (psutil.NoSuchProcess, psutil.AccessDenied):
224 pass 224 pass
225 225
226 226
227 def main(): 227 def RecoverDevices(args):
228 parser = optparse.OptionParser()
229 parser.add_option('', '--out-dir',
230 help='Directory where the device path is stored',
231 default=os.path.join(constants.DIR_SOURCE_ROOT, 'out'))
232 parser.add_option('--no-provisioning-check', action='store_true',
233 help='Will not check if devices are provisioned properly.')
234 parser.add_option('--device-status-dashboard', action='store_true',
235 help='Output device status data for dashboard.')
236 parser.add_option('--restart-usb', action='store_true',
237 help='DEPRECATED. '
238 'This script now always tries to reset USB.')
239 parser.add_option('--json-output',
240 help='Output JSON information into a specified file.')
241 parser.add_option('-v', '--verbose', action='count', default=1,
242 help='Log more information.')
243
244 options, args = parser.parse_args()
245 if args:
246 parser.error('Unknown options %s' % args)
247
248 run_tests_helper.SetLogLevel(options.verbose)
249
250 # Remove the last build's "bad devices" before checking device statuses. 228 # Remove the last build's "bad devices" before checking device statuses.
251 device_blacklist.ResetBlacklist() 229 device_blacklist.ResetBlacklist()
252 230
231 previous_devices = set(a.GetDeviceSerial()
232 for a in adb_wrapper.AdbWrapper.Devices())
233
253 KillAllAdb() 234 KillAllAdb()
254 reset_usb.reset_all_android_devices() 235 reset_usb.reset_all_android_devices()
255 236
256 try: 237 try:
257 expected_devices = set(device_list.GetPersistentDeviceList( 238 expected_devices = set(device_list.GetPersistentDeviceList(
258 os.path.join(options.out_dir, device_list.LAST_DEVICES_FILENAME))) 239 os.path.join(args.out_dir, device_list.LAST_DEVICES_FILENAME)))
259 except IOError: 240 except IOError:
260 expected_devices = set() 241 expected_devices = set()
261 242
262 def all_devices_found(): 243 all_devices = [device_utils.DeviceUtils(d)
263 devices = device_utils.DeviceUtils.HealthyDevices() 244 for d in previous_devices.union(expected_devices)]
264 device_serials = set(d.adb.GetDeviceSerial() for d in devices)
265 return not bool(expected_devices.difference(device_serials))
266 245
267 timeout_retry.WaitFor(all_devices_found, wait_period=1, max_tries=5) 246 def blacklisting_recovery(device):
247 try:
248 device.WaitUntilFullyBooted()
249 except device_errors.CommandFailedError:
250 logging.exception('Failure while waiting for %s. Adding to blacklist.',
251 str(device))
252 device_blacklist.ExtendBlacklist([str(device)])
253 except device_errors.CommandTimeoutError:
254 logging.exception('Timed out while waiting for %s. Adding to blacklist.',
255 str(device))
256 device_blacklist.ExtendBlacklist([str(device)])
257
258 device_utils.DeviceUtils.parallel(all_devices).pMap(blacklisting_recovery)
268 259
269 devices = device_utils.DeviceUtils.HealthyDevices() 260 devices = device_utils.DeviceUtils.HealthyDevices()
270 device_serials = set(d.adb.GetDeviceSerial() for d in devices) 261 device_serials = set(d.adb.GetDeviceSerial() for d in devices)
271 262
272 missing_devices = expected_devices.difference(device_serials) 263 missing_devices = expected_devices.difference(device_serials)
273 new_devices = device_serials.difference(expected_devices) 264 new_devices = device_serials.difference(expected_devices)
274 265
275 if missing_devices or new_devices: 266 if missing_devices or new_devices:
276 logging.warning('expected_devices:') 267 logging.warning('expected_devices:')
277 for d in sorted(expected_devices): 268 for d in sorted(expected_devices):
278 logging.warning(' %s', d) 269 logging.warning(' %s', d)
279 logging.warning('devices:') 270 logging.warning('devices:')
280 for d in sorted(device_serials): 271 for d in sorted(device_serials):
281 logging.warning(' %s', d) 272 logging.warning(' %s', d)
282 273
274 return devices
275
276
277 def main():
278 parser = optparse.OptionParser()
279 parser.add_option('', '--out-dir',
280 help='Directory where the device path is stored',
281 default=os.path.join(constants.DIR_SOURCE_ROOT, 'out'))
282 parser.add_option('--no-provisioning-check', action='store_true',
283 help='Will not check if devices are provisioned properly.')
284 parser.add_option('--device-status-dashboard', action='store_true',
285 help='Output device status data for dashboard.')
286 parser.add_option('--restart-usb', action='store_true',
287 help='DEPRECATED. '
288 'This script now always tries to reset USB.')
289 parser.add_option('--json-output',
290 help='Output JSON information into a specified file.')
291 parser.add_option('-v', '--verbose', action='count', default=1,
292 help='Log more information.')
293
294 options, args = parser.parse_args()
295 if args:
296 parser.error('Unknown options %s' % args)
297
298 run_tests_helper.SetLogLevel(options.verbose)
299
300 devices = RecoverDevices(options)
301
283 types, builds, batteries, errors, devices_ok, json_data = ( 302 types, builds, batteries, errors, devices_ok, json_data = (
284 [], [], [], [], [], []) 303 [], [], [], [], [], [])
285 if devices: 304 if devices:
286 types, builds, batteries, errors, devices_ok, json_data = ( 305 types, builds, batteries, errors, devices_ok, json_data = (
287 zip(*[DeviceInfo(dev, options) for dev in devices])) 306 zip(*[DeviceInfo(dev, options) for dev in devices]))
288 307
289 # Write device info to file for buildbot info display. 308 # Write device info to file for buildbot info display.
290 if os.path.exists('/home/chrome-bot'): 309 if os.path.exists('/home/chrome-bot'):
291 with open('/home/chrome-bot/.adb_device_info', 'w') as f: 310 with open('/home/chrome-bot/.adb_device_info', 'w') as f:
292 for device in json_data: 311 for device in json_data:
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 379
361 if num_failed_devs == len(devices): 380 if num_failed_devs == len(devices):
362 return 2 381 return 2
363 382
364 if not devices: 383 if not devices:
365 return 1 384 return 1
366 385
367 386
368 if __name__ == '__main__': 387 if __name__ == '__main__':
369 sys.exit(main()) 388 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698