| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 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 logging | 8 import logging |
| 9 import optparse | 9 import optparse |
| 10 import os | 10 import os |
| 11 import smtplib | 11 import smtplib |
| 12 import sys | 12 import sys |
| 13 import re | 13 import re |
| 14 | 14 |
| 15 from pylib import buildbot_report | 15 from pylib import buildbot_report |
| 16 from pylib import android_commands | 16 from pylib import android_commands |
| 17 from pylib.cmd_helper import GetCmdOutput | 17 from pylib.cmd_helper import GetCmdOutput |
| 18 | 18 |
| 19 | 19 |
| 20 def DeviceInfo(serial): | 20 def DeviceInfo(serial): |
| 21 """Gathers info on a device via various adb calls. | 21 """Gathers info on a device via various adb calls. |
| 22 | 22 |
| 23 Args: | 23 Args: |
| 24 serial: The serial of the attached device to construct info about. | 24 serial: The serial of the attached device to construct info about. |
| 25 | 25 |
| 26 Returns: | 26 Returns: |
| 27 Tuple of device type, build id, report as a string, error messages, and | 27 Tuple of device type, build id and report as a string. |
| 28 boolean indicating whether or not device can be used for testing. | |
| 29 """ | 28 """ |
| 30 | 29 |
| 31 def AdbShellCmd(cmd): | 30 def AdbShellCmd(cmd): |
| 32 return GetCmdOutput('adb -s %s shell %s' % (serial, cmd), | 31 return GetCmdOutput('adb -s %s shell %s' % (serial, cmd), |
| 33 shell=True).strip() | 32 shell=True).strip() |
| 34 | 33 |
| 35 device_type = AdbShellCmd('getprop ro.build.product') | 34 device_type = AdbShellCmd('getprop ro.build.product') |
| 36 device_build = AdbShellCmd('getprop ro.build.id') | 35 device_build = AdbShellCmd('getprop ro.build.id') |
| 37 device_product_name = AdbShellCmd('getprop ro.product.name') | 36 device_product_name = AdbShellCmd('getprop ro.product.name') |
| 38 | 37 |
| 39 setup_wizard_disabled = AdbShellCmd( | 38 setup_wizard_disabled = AdbShellCmd( |
| 40 'getprop ro.setupwizard.mode') == 'DISABLED' | 39 'getprop ro.setupwizard.mode') == 'DISABLED' |
| 41 battery = AdbShellCmd('dumpsys battery') | 40 battery = AdbShellCmd('dumpsys battery') |
| 42 install_output = GetCmdOutput(['build/android/adb_install_apk.py', '--apk', | |
| 43 'build/android/CheckInstallApk-debug.apk']) | |
| 44 install_speed_found = re.findall('(\d+) KB/s', install_output) | |
| 45 if install_speed_found: | |
| 46 install_speed = int(install_speed_found[0]) | |
| 47 else: | |
| 48 install_speed = 'Unknown' | |
| 49 if 'Error' in battery: | 41 if 'Error' in battery: |
| 50 ac_power = 'Unknown' | 42 ac_power = 'Unknown' |
| 51 battery_level = 'Unknown' | 43 battery_level = 'Unknown' |
| 52 battery_temp = 'Unknown' | 44 battery_temp = 'Unknown' |
| 53 else: | 45 else: |
| 54 ac_power = re.findall('AC powered: (\w+)', battery)[0] | 46 ac_power = re.findall('AC powered: (\w+)', battery)[0] |
| 55 battery_level = int(re.findall('level: (\d+)', battery)[0]) | 47 battery_level = int(re.findall('level: (\d+)', battery)[0]) |
| 56 battery_temp = float(re.findall('temperature: (\d+)', battery)[0]) / 10 | 48 battery_temp = float(re.findall('temperature: (\d+)', battery)[0]) / 10 |
| 57 report = ['Device %s (%s)' % (serial, device_type), | 49 report = ['Device %s (%s)' % (serial, device_type), |
| 58 ' Build: %s (%s)' % (device_build, | 50 ' Build: %s (%s)' % (device_build, |
| 59 AdbShellCmd('getprop ro.build.fingerprint')), | 51 AdbShellCmd('getprop ro.build.fingerprint')), |
| 60 ' Battery: %s%%' % battery_level, | 52 ' Battery: %s%%' % battery_level, |
| 61 ' Battery temp: %s' % battery_temp, | 53 ' Battery temp: %s' % battery_temp, |
| 62 ' IMEI slice: %s' % AdbShellCmd('dumpsys iphonesubinfo ' | 54 ' IMEI slice: %s' % AdbShellCmd('dumpsys iphonesubinfo ' |
| 63 '| grep Device' | 55 '| grep Device' |
| 64 "| awk '{print $4}'")[-6:], | 56 "| awk '{print $4}'")[-6:], |
| 65 ' Wifi IP: %s' % AdbShellCmd('getprop dhcp.wlan0.ipaddress'), | 57 ' Wifi IP: %s' % AdbShellCmd('getprop dhcp.wlan0.ipaddress'), |
| 66 ' Install Speed: %s KB/s' % install_speed, | |
| 67 ''] | 58 ''] |
| 68 | 59 |
| 69 errors = [] | 60 errors = [] |
| 70 if battery_level < 5: | 61 if battery_level < 5: |
| 71 errors += ['Device critically low in battery. Do not use for testing.'] | 62 errors += ['Device critically low in battery.'] |
| 72 if not setup_wizard_disabled: | 63 if not setup_wizard_disabled: |
| 73 errors += ['Setup wizard not disabled. Was it provisioned correctly?'] | 64 errors += ['Setup wizard not disabled. Was it provisioned correctly?'] |
| 74 if device_product_name == 'mantaray' and ac_power != 'true': | 65 if device_product_name == 'mantaray' and ac_power != 'true': |
| 75 errors += ['Mantaray device not connected to AC power.'] | 66 errors += ['Mantaray device not connected to AC power.'] |
| 76 if install_speed < 800: | |
| 77 errors += ['Device install speed too low. Do not use for testing.'] | |
| 78 | 67 |
| 79 use_device = (battery_level != 'Unknown' and battery_level >= 5 and | 68 return device_type, device_build, '\n'.join(report), errors |
| 80 install_speed != 'Unknown' and install_speed >= 800) | |
| 81 return device_type, device_build, '\n'.join(report), errors, use_device | |
| 82 | 69 |
| 83 | 70 |
| 84 def CheckForMissingDevices(options, adb_online_devs): | 71 def CheckForMissingDevices(options, adb_online_devs): |
| 85 """Uses file of previous online devices to detect broken phones. | 72 """Uses file of previous online devices to detect broken phones. |
| 86 | 73 |
| 87 Args: | 74 Args: |
| 88 options: out_dir parameter of options argument is used as the base | 75 options: out_dir parameter of options argument is used as the base |
| 89 directory to load and update the cache file. | 76 directory to load and update the cache file. |
| 90 adb_online_devs: A list of serial numbers of the currently visible | 77 adb_online_devs: A list of serial numbers of the currently visible |
| 91 and online attached devices. | 78 and online attached devices. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 help='Directory where the device path is stored', | 160 help='Directory where the device path is stored', |
| 174 default=os.path.join(os.path.dirname(__file__), '..', | 161 default=os.path.join(os.path.dirname(__file__), '..', |
| 175 '..', 'out')) | 162 '..', 'out')) |
| 176 | 163 |
| 177 options, args = parser.parse_args() | 164 options, args = parser.parse_args() |
| 178 if args: | 165 if args: |
| 179 parser.error('Unknown options %s' % args) | 166 parser.error('Unknown options %s' % args) |
| 180 devices = android_commands.GetAttachedDevices() | 167 devices = android_commands.GetAttachedDevices() |
| 181 types, builds, reports, errors = [], [], [], [] | 168 types, builds, reports, errors = [], [], [], [] |
| 182 if devices: | 169 if devices: |
| 183 types, builds, reports, errors, use_device_lst = zip(*[DeviceInfo(dev) | 170 types, builds, reports, errors = zip(*[DeviceInfo(dev) for dev in devices]) |
| 184 for dev in devices]) | |
| 185 | 171 |
| 186 err_msg = CheckForMissingDevices(options, devices) or [] | 172 err_msg = CheckForMissingDevices(options, devices) or [] |
| 187 | 173 |
| 188 unique_types = list(set(types)) | 174 unique_types = list(set(types)) |
| 189 unique_builds = list(set(builds)) | 175 unique_builds = list(set(builds)) |
| 190 | 176 |
| 191 buildbot_report.PrintMsg('Online devices: %d. Device types %s, builds %s' | 177 buildbot_report.PrintMsg('Online devices: %d. Device types %s, builds %s' |
| 192 % (len(devices), unique_types, unique_builds)) | 178 % (len(devices), unique_types, unique_builds)) |
| 193 print '\n'.join(reports) | 179 print '\n'.join(reports) |
| 194 | 180 |
| 195 for serial, dev_errors in zip(devices, errors): | 181 for serial, dev_errors in zip(devices, errors): |
| 196 if dev_errors: | 182 if dev_errors: |
| 197 err_msg += ['%s errors:' % serial] | 183 err_msg += ['%s errors:' % serial] |
| 198 err_msg += [' %s' % error for error in dev_errors] | 184 err_msg += [' %s' % error for error in dev_errors] |
| 199 | 185 |
| 200 if err_msg: | 186 if err_msg: |
| 201 buildbot_report.PrintWarning() | 187 buildbot_report.PrintWarning() |
| 202 msg = '\n'.join(err_msg) | 188 msg = '\n'.join(err_msg) |
| 203 print msg | 189 print msg |
| 204 SendDeviceStatusAlert(msg) | 190 SendDeviceStatusAlert(msg) |
| 205 | 191 |
| 206 if False in use_device_lst: | |
| 207 # TODO(navabi): Build fails on device status check step if there exists any | |
| 208 # devices with critically low battery or install speed. Remove those devices | |
| 209 # from testing, allowing build to continue with good devices. | |
| 210 return 1 | |
| 211 | |
| 212 if not devices: | 192 if not devices: |
| 213 return 1 | 193 return 1 |
| 214 | 194 |
| 215 | 195 |
| 216 if __name__ == '__main__': | 196 if __name__ == '__main__': |
| 217 sys.exit(main()) | 197 sys.exit(main()) |
| OLD | NEW |