OLD | NEW |
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 | 8 |
9 import argparse | 9 import argparse |
10 import json | 10 import json |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 except (IOError, device_errors.DeviceUnreachableError): | 238 except (IOError, device_errors.DeviceUnreachableError): |
239 logging.exception('Unable to reset USB for %s.', serial) | 239 logging.exception('Unable to reset USB for %s.', serial) |
240 if blacklist: | 240 if blacklist: |
241 blacklist.Extend([serial]) | 241 blacklist.Extend([serial]) |
242 | 242 |
243 def blacklisting_recovery(device): | 243 def blacklisting_recovery(device): |
244 if _IsBlacklisted(device.adb.GetDeviceSerial(), blacklist): | 244 if _IsBlacklisted(device.adb.GetDeviceSerial(), blacklist): |
245 logging.debug('%s is blacklisted, skipping recovery.', str(device)) | 245 logging.debug('%s is blacklisted, skipping recovery.', str(device)) |
246 return | 246 return |
247 | 247 |
248 if device in should_reboot_device: | 248 if str(device) in should_reboot_device: |
249 try: | 249 try: |
250 device.WaitUntilFullyBooted() | 250 device.WaitUntilFullyBooted(retries=0) |
251 return | 251 return |
252 except (device_errors.CommandTimeoutError, | 252 except (device_errors.CommandTimeoutError, |
253 device_errors.CommandFailedError): | 253 device_errors.CommandFailedError): |
254 logging.exception('Failure while waiting for %s. ' | 254 logging.exception('Failure while waiting for %s. ' |
255 'Attempting to recover.', str(device)) | 255 'Attempting to recover.', str(device)) |
256 | 256 |
257 try: | 257 try: |
258 device.Reboot() | 258 try: |
259 device.WaitUntilFullyBooted() | 259 device.Reboot(block=False, timeout=5, retries=0) |
| 260 except device_errors.CommandTimeoutError: |
| 261 logging.warning('Timed out while attempting to reboot %s normally.' |
| 262 'Attempting alternative reboot.', str(device)) |
| 263 # The device drops offline before we can grab the exit code, so |
| 264 # we don't check for status. |
| 265 device.adb.Root() |
| 266 device.adb.Shell('echo b > /proc/sysrq-trigger', expect_status=None, |
| 267 timeout=5, retries=0) |
| 268 except device_errors.CommandFailedError: |
| 269 logging.exception('Failed to reboot %s.', str(device)) |
| 270 if blacklist: |
| 271 blacklist.Extend([device.adb.GetDeviceSerial()]) |
| 272 except device_errors.CommandTimeoutError: |
| 273 logging.exception('Timed out while rebooting %s.', str(device)) |
| 274 if blacklist: |
| 275 blacklist.Extend([device.adb.GetDeviceSerial()]) |
| 276 |
| 277 try: |
| 278 device.WaitUntilFullyBooted(retries=0) |
260 except device_errors.CommandFailedError: | 279 except device_errors.CommandFailedError: |
261 logging.exception('Failure while waiting for %s.', str(device)) | 280 logging.exception('Failure while waiting for %s.', str(device)) |
262 if blacklist: | 281 if blacklist: |
263 blacklist.Extend([device.adb.GetDeviceSerial()]) | 282 blacklist.Extend([device.adb.GetDeviceSerial()]) |
264 except device_errors.CommandTimeoutError: | 283 except device_errors.CommandTimeoutError: |
265 logging.exception('Timed out while waiting for %s. ', str(device)) | 284 logging.exception('Timed out while waiting for %s.', str(device)) |
266 if blacklist: | 285 if blacklist: |
267 blacklist.Extend([device.adb.GetDeviceSerial()]) | 286 blacklist.Extend([device.adb.GetDeviceSerial()]) |
268 | 287 |
269 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_recovery) | 288 device_utils.DeviceUtils.parallel(devices).pMap(blacklisting_recovery) |
270 | 289 |
271 | 290 |
272 def main(): | 291 def main(): |
273 parser = argparse.ArgumentParser() | 292 parser = argparse.ArgumentParser() |
274 parser.add_argument('--out-dir', | 293 parser.add_argument('--out-dir', |
275 help='Directory where the device path is stored', | 294 help='Directory where the device path is stored', |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 live_devices = [status['serial'] for status in statuses | 381 live_devices = [status['serial'] for status in statuses |
363 if (status['adb_status'] == 'device' | 382 if (status['adb_status'] == 'device' |
364 and not _IsBlacklisted(status['serial'], blacklist))] | 383 and not _IsBlacklisted(status['serial'], blacklist))] |
365 | 384 |
366 # If all devices failed, or if there are no devices, it's an infra error. | 385 # If all devices failed, or if there are no devices, it's an infra error. |
367 return 0 if live_devices else constants.INFRA_EXIT_CODE | 386 return 0 if live_devices else constants.INFRA_EXIT_CODE |
368 | 387 |
369 | 388 |
370 if __name__ == '__main__': | 389 if __name__ == '__main__': |
371 sys.exit(main()) | 390 sys.exit(main()) |
OLD | NEW |