| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 except (psutil.NoSuchProcess, psutil.AccessDenied): | 48 except (psutil.NoSuchProcess, psutil.AccessDenied): |
| 49 pass | 49 pass |
| 50 for p in GetAllAdb(): | 50 for p in GetAllAdb(): |
| 51 try: | 51 try: |
| 52 logging.error('Unable to kill %d (%s [%s])', p.pid, p.name, | 52 logging.error('Unable to kill %d (%s [%s])', p.pid, p.name, |
| 53 ' '.join(p.cmdline)) | 53 ' '.join(p.cmdline)) |
| 54 except (psutil.NoSuchProcess, psutil.AccessDenied): | 54 except (psutil.NoSuchProcess, psutil.AccessDenied): |
| 55 pass | 55 pass |
| 56 | 56 |
| 57 | 57 |
| 58 def _IsBlacklisted(serial, blacklist): | |
| 59 return blacklist and serial in blacklist.Read() | |
| 60 | |
| 61 | |
| 62 def _BatteryStatus(device, blacklist): | 58 def _BatteryStatus(device, blacklist): |
| 63 battery_info = {} | 59 battery_info = {} |
| 64 try: | 60 try: |
| 65 battery = battery_utils.BatteryUtils(device) | 61 battery = battery_utils.BatteryUtils(device) |
| 66 battery_info = battery.GetBatteryInfo(timeout=5) | 62 battery_info = battery.GetBatteryInfo(timeout=5) |
| 67 battery_level = int(battery_info.get('level', 100)) | 63 battery_level = int(battery_info.get('level', 100)) |
| 68 | 64 |
| 69 if battery_level < 15: | 65 if battery_level < 15: |
| 70 logging.error('Critically low battery level (%d)', battery_level) | 66 logging.error('Critically low battery level (%d)', battery_level) |
| 71 battery = battery_utils.BatteryUtils(device) | 67 battery = battery_utils.BatteryUtils(device) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 else 'unknown') | 131 else 'unknown') |
| 136 usb_status = bool(serial in usb_devices) | 132 usb_status = bool(serial in usb_devices) |
| 137 | 133 |
| 138 device_status = { | 134 device_status = { |
| 139 'serial': serial, | 135 'serial': serial, |
| 140 'adb_status': adb_status, | 136 'adb_status': adb_status, |
| 141 'usb_status': usb_status, | 137 'usb_status': usb_status, |
| 142 } | 138 } |
| 143 | 139 |
| 144 if adb_status == 'device': | 140 if adb_status == 'device': |
| 145 if not _IsBlacklisted(serial, blacklist): | 141 if not serial in blacklist.Read(): |
| 146 try: | 142 try: |
| 147 build_product = device.build_product | 143 build_product = device.build_product |
| 148 build_id = device.build_id | 144 build_id = device.build_id |
| 149 build_fingerprint = device.GetProp('ro.build.fingerprint', cache=True) | 145 build_fingerprint = device.GetProp('ro.build.fingerprint', cache=True) |
| 150 wifi_ip = device.GetProp('dhcp.wlan0.ipaddress') | 146 wifi_ip = device.GetProp('dhcp.wlan0.ipaddress') |
| 151 battery_info = _BatteryStatus(device, blacklist) | 147 battery_info = _BatteryStatus(device, blacklist) |
| 152 imei_slice = _IMEISlice(device) | 148 imei_slice = _IMEISlice(device) |
| 153 | 149 |
| 154 if (device.product_name == 'mantaray' and | 150 if (device.product_name == 'mantaray' and |
| 155 battery_info.get('AC powered', None) != 'true'): | 151 battery_info.get('AC powered', None) != 'true'): |
| (...skipping 21 matching lines...) Expand all Loading... |
| 177 | 173 |
| 178 except device_errors.CommandTimeoutError: | 174 except device_errors.CommandTimeoutError: |
| 179 logging.exception('Timeout while getting device status for %s.', | 175 logging.exception('Timeout while getting device status for %s.', |
| 180 str(device)) | 176 str(device)) |
| 181 if blacklist: | 177 if blacklist: |
| 182 blacklist.Extend([serial]) | 178 blacklist.Extend([serial]) |
| 183 | 179 |
| 184 elif blacklist: | 180 elif blacklist: |
| 185 blacklist.Extend([serial]) | 181 blacklist.Extend([serial]) |
| 186 | 182 |
| 187 device_status['blacklisted'] = _IsBlacklisted(serial, blacklist) | 183 device_status['blacklisted'] = serial in blacklist.Read() |
| 188 | 184 |
| 189 return device_status | 185 return device_status |
| 190 | 186 |
| 191 parallel_devices = device_utils.DeviceUtils.parallel(devices) | 187 parallel_devices = device_utils.DeviceUtils.parallel(devices) |
| 192 statuses = parallel_devices.pMap(blacklisting_device_status).pGet(None) | 188 statuses = parallel_devices.pMap(blacklisting_device_status).pGet(None) |
| 193 return statuses | 189 return statuses |
| 194 | 190 |
| 195 | 191 |
| 196 def RecoverDevices(devices, blacklist): | 192 def RecoverDevices(devices, blacklist): |
| 197 """Attempts to recover any inoperable devices in the provided list. | 193 """Attempts to recover any inoperable devices in the provided list. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 220 logging.debug('Should restart USB for:') | 216 logging.debug('Should restart USB for:') |
| 221 for d in should_restart_usb: | 217 for d in should_restart_usb: |
| 222 logging.debug(' %s', d) | 218 logging.debug(' %s', d) |
| 223 logging.debug('Should restart ADB for:') | 219 logging.debug('Should restart ADB for:') |
| 224 for d in should_restart_adb: | 220 for d in should_restart_adb: |
| 225 logging.debug(' %s', d) | 221 logging.debug(' %s', d) |
| 226 logging.debug('Should reboot:') | 222 logging.debug('Should reboot:') |
| 227 for d in should_reboot_device: | 223 for d in should_reboot_device: |
| 228 logging.debug(' %s', d) | 224 logging.debug(' %s', d) |
| 229 | 225 |
| 230 if blacklist: | 226 blacklist.Reset() |
| 231 blacklist.Reset() | |
| 232 | 227 |
| 233 if should_restart_adb: | 228 if should_restart_adb: |
| 234 KillAllAdb() | 229 KillAllAdb() |
| 235 for serial in should_restart_usb: | 230 for serial in should_restart_usb: |
| 236 try: | 231 try: |
| 237 reset_usb.reset_android_usb(serial) | 232 reset_usb.reset_android_usb(serial) |
| 238 except (IOError, device_errors.DeviceUnreachableError): | 233 except (IOError, device_errors.DeviceUnreachableError): |
| 239 logging.exception('Unable to reset USB for %s.', serial) | 234 logging.exception('Unable to reset USB for %s.', serial) |
| 240 if blacklist: | 235 if blacklist: |
| 241 blacklist.Extend([serial]) | 236 blacklist.Extend([serial]) |
| 242 | 237 |
| 243 def blacklisting_recovery(device): | 238 def blacklisting_recovery(device): |
| 244 if _IsBlacklisted(device.adb.GetDeviceSerial(), blacklist): | 239 if blacklist and device.adb.GetDeviceSerial() in blacklist.Read(): |
| 245 logging.debug('%s is blacklisted, skipping recovery.', str(device)) | 240 logging.debug('%s is blacklisted, skipping recovery.', str(device)) |
| 246 return | 241 return |
| 247 | 242 |
| 248 if device in should_reboot_device: | 243 if device in should_reboot_device: |
| 249 try: | 244 try: |
| 250 device.WaitUntilFullyBooted() | 245 device.WaitUntilFullyBooted() |
| 251 return | 246 return |
| 252 except (device_errors.CommandTimeoutError, | 247 except (device_errors.CommandTimeoutError, |
| 253 device_errors.CommandFailedError): | 248 device_errors.CommandFailedError): |
| 254 logging.exception('Failure while waiting for %s. ' | 249 logging.exception('Failure while waiting for %s. ' |
| (...skipping 25 matching lines...) Expand all Loading... |
| 280 parser.add_argument('--json-output', | 275 parser.add_argument('--json-output', |
| 281 help='Output JSON information into a specified file.') | 276 help='Output JSON information into a specified file.') |
| 282 parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') | 277 parser.add_argument('--blacklist-file', help='Device blacklist JSON file.') |
| 283 parser.add_argument('-v', '--verbose', action='count', default=1, | 278 parser.add_argument('-v', '--verbose', action='count', default=1, |
| 284 help='Log more information.') | 279 help='Log more information.') |
| 285 | 280 |
| 286 args = parser.parse_args() | 281 args = parser.parse_args() |
| 287 | 282 |
| 288 run_tests_helper.SetLogLevel(args.verbose) | 283 run_tests_helper.SetLogLevel(args.verbose) |
| 289 | 284 |
| 290 blacklist = (device_blacklist.Blacklist(args.blacklist_file) | 285 if args.blacklist_file: |
| 291 if args.blacklist_file | 286 blacklist = device_blacklist.Blacklist(args.blacklist_file) |
| 292 else None) | 287 else: |
| 288 # TODO(jbudorick): Remove this once bots pass the blacklist file. |
| 289 blacklist = device_blacklist.Blacklist(device_blacklist.BLACKLIST_JSON) |
| 293 | 290 |
| 294 last_devices_path = os.path.join( | 291 last_devices_path = os.path.join( |
| 295 args.out_dir, device_list.LAST_DEVICES_FILENAME) | 292 args.out_dir, device_list.LAST_DEVICES_FILENAME) |
| 296 try: | 293 try: |
| 297 expected_devices = set( | 294 expected_devices = set( |
| 298 device_list.GetPersistentDeviceList(last_devices_path)) | 295 device_list.GetPersistentDeviceList(last_devices_path)) |
| 299 except IOError: | 296 except IOError: |
| 300 expected_devices = set() | 297 expected_devices = set() |
| 301 | 298 |
| 302 usb_devices = set(lsusb.get_android_devices()) | 299 usb_devices = set(lsusb.get_android_devices()) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 except Exception: # pylint: disable=broad-except | 351 except Exception: # pylint: disable=broad-except |
| 355 pass | 352 pass |
| 356 | 353 |
| 357 # Dump the device statuses to JSON. | 354 # Dump the device statuses to JSON. |
| 358 if args.json_output: | 355 if args.json_output: |
| 359 with open(args.json_output, 'wb') as f: | 356 with open(args.json_output, 'wb') as f: |
| 360 f.write(json.dumps(statuses, indent=4)) | 357 f.write(json.dumps(statuses, indent=4)) |
| 361 | 358 |
| 362 live_devices = [status['serial'] for status in statuses | 359 live_devices = [status['serial'] for status in statuses |
| 363 if (status['adb_status'] == 'device' | 360 if (status['adb_status'] == 'device' |
| 364 and not _IsBlacklisted(status['serial'], blacklist))] | 361 and status['serial'] not in blacklist.Read())] |
| 365 | 362 |
| 366 # If all devices failed, or if there are no devices, it's an infra error. | 363 # 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 | 364 return 0 if live_devices else constants.INFRA_EXIT_CODE |
| 368 | 365 |
| 369 | 366 |
| 370 if __name__ == '__main__': | 367 if __name__ == '__main__': |
| 371 sys.exit(main()) | 368 sys.exit(main()) |
| OLD | NEW |