Chromium Code Reviews| 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 import json | 8 import json |
| 9 import logging | 9 import logging |
| 10 import optparse | 10 import optparse |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 | 23 |
| 24 sys.path.append(os.path.join(os.path.dirname(__file__), | 24 sys.path.append(os.path.join(os.path.dirname(__file__), |
| 25 os.pardir, os.pardir, 'util', 'lib', | 25 os.pardir, os.pardir, 'util', 'lib', |
| 26 'common')) | 26 'common')) |
| 27 import perf_tests_results_helper # pylint: disable=F0401 | 27 import perf_tests_results_helper # pylint: disable=F0401 |
| 28 | 28 |
| 29 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | 29 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
| 30 from pylib import android_commands | 30 from pylib import android_commands |
| 31 from pylib import constants | 31 from pylib import constants |
| 32 from pylib.cmd_helper import GetCmdOutput | 32 from pylib.cmd_helper import GetCmdOutput |
| 33 from pylib.device import battery_utils | |
| 33 from pylib.device import device_blacklist | 34 from pylib.device import device_blacklist |
| 35 from pylib.device import device_errors | |
| 34 from pylib.device import device_list | 36 from pylib.device import device_list |
| 35 from pylib.device import device_utils | 37 from pylib.device import device_utils |
| 36 | 38 |
| 39 _RE_DEVICE_ID = re.compile('Device ID = (\d+)') | |
| 40 | |
| 37 def DeviceInfo(serial, options): | 41 def DeviceInfo(serial, options): |
| 38 """Gathers info on a device via various adb calls. | 42 """Gathers info on a device via various adb calls. |
| 39 | 43 |
| 40 Args: | 44 Args: |
| 41 serial: The serial of the attached device to construct info about. | 45 serial: The serial of the attached device to construct info about. |
| 42 | 46 |
| 43 Returns: | 47 Returns: |
| 44 Tuple of device type, build id, report as a string, error messages, and | 48 Tuple of device type, build id, report as a string, error messages, and |
| 45 boolean indicating whether or not device can be used for testing. | 49 boolean indicating whether or not device can be used for testing. |
| 46 """ | 50 """ |
| 51 device = device_utils.DeviceUtils(serial) | |
| 52 battery = battery_utils.BatteryUtils(device) | |
| 47 | 53 |
| 48 device_adb = device_utils.DeviceUtils(serial) | 54 battery_info = {} |
| 49 device_type = device_adb.build_product | |
| 50 device_build = device_adb.build_id | |
| 51 device_build_type = device_adb.build_type | |
| 52 device_product_name = device_adb.product_name | |
| 53 | |
| 54 try: | 55 try: |
| 55 battery_info = device_adb.old_interface.GetBatteryInfo() | 56 battery_info = battery.GetBatteryInfo() |
| 56 except Exception as e: | 57 except Exception as e: |
| 57 battery_info = {} | 58 battery_info = {} |
| 58 logging.error('Unable to obtain battery info for %s, %s', serial, e) | 59 logging.error('Unable to obtain battery info for %s, %s', serial, e) |
| 59 | 60 |
| 60 def _GetData(re_expression, line, lambda_function=lambda x: x): | 61 battery_level = int(battery_info.get('level', 100)) |
| 61 if not line: | |
| 62 return 'Unknown' | |
| 63 found = re.findall(re_expression, line) | |
| 64 if found and len(found): | |
| 65 return lambda_function(found[0]) | |
| 66 return 'Unknown' | |
| 67 | 62 |
| 68 battery_level = int(battery_info.get('level', 100)) | 63 imei_slice = 'Unknown' |
| 69 imei_slice = _GetData(r'Device ID = (\d+)', | 64 try: |
|
jbudorick
2015/04/06 17:29:30
Note that catching exceptions here is a functional
navabi
2015/04/07 17:55:17
Acknowledged.
| |
| 70 device_adb.old_interface.GetSubscriberInfo(), | 65 for l in device.RunShellCommand(['dumpsys', 'iphonesubinfo'], |
| 71 lambda x: x[-6:]) | 66 check_return=True): |
| 67 m = _RE_DEVICE_ID.match(l) | |
| 68 if m: | |
| 69 imei_slice = m.group(1)[-6:] | |
| 70 except device_errors.CommandFailedError: | |
| 71 logging.exception('Failed to get IMEI slice.') | |
| 72 except device_errors.CommandTimeoutError: | |
| 73 logging.exception('Timed out while attempting to get IMEI slice.') | |
| 74 | |
| 72 json_data = { | 75 json_data = { |
| 73 'serial': serial, | 76 'serial': serial, |
| 74 'type': device_type, | 77 'type': device.build_product, |
| 75 'build': device_build, | 78 'build': device.build_id, |
| 76 'build_detail': device_adb.GetProp('ro.build.fingerprint'), | 79 'build_detail': device.GetProp('ro.build.fingerprint'), |
| 77 'battery': battery_info, | 80 'battery': battery_info, |
| 78 'imei_slice': imei_slice, | 81 'imei_slice': imei_slice, |
| 79 'wifi_ip': device_adb.GetProp('dhcp.wlan0.ipaddress'), | 82 'wifi_ip': device.GetProp('dhcp.wlan0.ipaddress'), |
| 80 } | 83 } |
| 81 report = ['Device %s (%s)' % (serial, device_type), | 84 report = [ |
| 82 ' Build: %s (%s)' % | 85 'Device %s (%s)' % (str(device), device.build_product), |
| 83 (device_build, json_data['build_detail']), | 86 ' Build: %s (%s)' % (device.build_id, json_data['build_detail']), |
| 84 ' Current Battery Service state: ', | 87 ' Current Battery Service state: ', |
| 85 '\n'.join([' %s: %s' % (k, v) | 88 '\n'.join(' %s: %s' % (k, v) for k, v in battery_info.iteritems()), |
| 86 for k, v in battery_info.iteritems()]), | 89 ' IMEI slice: %s' % imei_slice, |
| 87 ' IMEI slice: %s' % imei_slice, | 90 ' Wifi IP: %s' % json_data['wifi_ip'], |
| 88 ' Wifi IP: %s' % json_data['wifi_ip'], | 91 '' |
| 89 ''] | 92 ] |
| 90 | 93 |
| 91 errors = [] | 94 errors = [] |
| 92 dev_good = True | 95 dev_good = True |
| 93 if battery_level < 15: | 96 if battery_level < 15: |
| 94 errors += ['Device critically low in battery. Will add to blacklist.'] | 97 errors += ['Device critically low in battery. Will add to blacklist.'] |
| 95 dev_good = False | 98 dev_good = False |
| 96 if not device_adb.old_interface.IsDeviceCharging(): | 99 if not battery.GetCharging(): |
| 97 if device_adb.old_interface.CanControlUsbCharging(): | 100 try: |
| 98 device_adb.old_interface.EnableUsbCharging() | 101 battery.SetCharging(True) |
| 99 else: | 102 except device_errors.CommandFailedError: |
| 100 logging.error('Device %s is not charging' % serial) | 103 logging.exception('Device %s is not charging', str(device)) |
| 101 if not options.no_provisioning_check: | 104 if not options.no_provisioning_check: |
| 102 setup_wizard_disabled = ( | 105 setup_wizard_disabled = ( |
| 103 device_adb.GetProp('ro.setupwizard.mode') == 'DISABLED') | 106 device.GetProp('ro.setupwizard.mode') == 'DISABLED') |
| 104 if not setup_wizard_disabled and device_build_type != 'user': | 107 if not setup_wizard_disabled and device.build_type != 'user': |
| 105 errors += ['Setup wizard not disabled. Was it provisioned correctly?'] | 108 errors += ['Setup wizard not disabled. Was it provisioned correctly?'] |
| 106 if (device_product_name == 'mantaray' and | 109 if (device.product_name == 'mantaray' and |
| 107 battery_info.get('AC powered', None) != 'true'): | 110 battery_info.get('AC powered', None) != 'true'): |
| 108 errors += ['Mantaray device not connected to AC power.'] | 111 errors += ['Mantaray device not connected to AC power.'] |
| 109 | 112 |
| 110 full_report = '\n'.join(report) | 113 full_report = '\n'.join(report) |
| 111 | 114 |
| 112 return (device_type, device_build, battery_level, full_report, errors, | 115 return (device.build_product, device.build_id, battery_level, full_report, |
| 113 dev_good, json_data) | 116 errors, dev_good, json_data) |
| 114 | 117 |
| 115 | 118 |
| 116 def CheckForMissingDevices(options, adb_online_devs): | 119 def CheckForMissingDevices(options, adb_online_devs): |
| 117 """Uses file of previous online devices to detect broken phones. | 120 """Uses file of previous online devices to detect broken phones. |
| 118 | 121 |
| 119 Args: | 122 Args: |
| 120 options: out_dir parameter of options argument is used as the base | 123 options: out_dir parameter of options argument is used as the base |
| 121 directory to load and update the cache file. | 124 directory to load and update the cache file. |
| 122 adb_online_devs: A list of serial numbers of the currently visible | 125 adb_online_devs: A list of serial numbers of the currently visible |
| 123 and online attached devices. | 126 and online attached devices. |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 | 398 |
| 396 if num_failed_devs == len(devices): | 399 if num_failed_devs == len(devices): |
| 397 return 2 | 400 return 2 |
| 398 | 401 |
| 399 if not devices: | 402 if not devices: |
| 400 return 1 | 403 return 1 |
| 401 | 404 |
| 402 | 405 |
| 403 if __name__ == '__main__': | 406 if __name__ == '__main__': |
| 404 sys.exit(main()) | 407 sys.exit(main()) |
| OLD | NEW |