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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 return 'Unknown' | 62 return 'Unknown' |
63 found = re.findall(re_expression, line) | 63 found = re.findall(re_expression, line) |
64 if found and len(found): | 64 if found and len(found): |
65 return lambda_function(found[0]) | 65 return lambda_function(found[0]) |
66 return 'Unknown' | 66 return 'Unknown' |
67 | 67 |
68 battery_level = int(battery_info.get('level', 100)) | 68 battery_level = int(battery_info.get('level', 100)) |
69 imei_slice = _GetData(r'Device ID = (\d+)', | 69 imei_slice = _GetData(r'Device ID = (\d+)', |
70 device_adb.old_interface.GetSubscriberInfo(), | 70 device_adb.old_interface.GetSubscriberInfo(), |
71 lambda x: x[-6:]) | 71 lambda x: x[-6:]) |
| 72 json_data = { |
| 73 'serial': serial, |
| 74 'type': device_type, |
| 75 'build': device_build, |
| 76 'build_detail': device_adb.GetProp('ro.build.fingerprint'), |
| 77 'battery': battery_info, |
| 78 'imei_slice': imei_slice, |
| 79 'wifi_ip': device_adb.GetProp('dhcp.wlan0.ipaddress'), |
| 80 } |
72 report = ['Device %s (%s)' % (serial, device_type), | 81 report = ['Device %s (%s)' % (serial, device_type), |
73 ' Build: %s (%s)' % | 82 ' Build: %s (%s)' % |
74 (device_build, device_adb.build_fingerprint), | 83 (device_build, json_data['build_detail']), |
75 ' Current Battery Service state: ', | 84 ' Current Battery Service state: ', |
76 '\n'.join([' %s: %s' % (k, v) | 85 '\n'.join([' %s: %s' % (k, v) |
77 for k, v in battery_info.iteritems()]), | 86 for k, v in battery_info.iteritems()]), |
78 ' IMEI slice: %s' % imei_slice, | 87 ' IMEI slice: %s' % imei_slice, |
79 ' Wifi IP: %s' % device_adb.GetProp('dhcp.wlan0.ipaddress'), | 88 ' Wifi IP: %s' % json_data['wifi_ip'], |
80 ''] | 89 ''] |
81 | 90 |
82 errors = [] | 91 errors = [] |
83 dev_good = True | 92 dev_good = True |
84 if battery_level < 15: | 93 if battery_level < 15: |
85 errors += ['Device critically low in battery. Will add to blacklist.'] | 94 errors += ['Device critically low in battery. Will add to blacklist.'] |
86 dev_good = False | 95 dev_good = False |
87 if not device_adb.old_interface.IsDeviceCharging(): | 96 if not device_adb.old_interface.IsDeviceCharging(): |
88 if device_adb.old_interface.CanControlUsbCharging(): | 97 if device_adb.old_interface.CanControlUsbCharging(): |
89 device_adb.old_interface.EnableUsbCharging() | 98 device_adb.old_interface.EnableUsbCharging() |
90 else: | 99 else: |
91 logging.error('Device %s is not charging' % serial) | 100 logging.error('Device %s is not charging' % serial) |
92 if not options.no_provisioning_check: | 101 if not options.no_provisioning_check: |
93 setup_wizard_disabled = ( | 102 setup_wizard_disabled = ( |
94 device_adb.GetProp('ro.setupwizard.mode') == 'DISABLED') | 103 device_adb.GetProp('ro.setupwizard.mode') == 'DISABLED') |
95 if not setup_wizard_disabled and device_build_type != 'user': | 104 if not setup_wizard_disabled and device_build_type != 'user': |
96 errors += ['Setup wizard not disabled. Was it provisioned correctly?'] | 105 errors += ['Setup wizard not disabled. Was it provisioned correctly?'] |
97 if (device_product_name == 'mantaray' and | 106 if (device_product_name == 'mantaray' and |
98 battery_info.get('AC powered', None) != 'true'): | 107 battery_info.get('AC powered', None) != 'true'): |
99 errors += ['Mantaray device not connected to AC power.'] | 108 errors += ['Mantaray device not connected to AC power.'] |
100 | 109 |
101 full_report = '\n'.join(report) | 110 full_report = '\n'.join(report) |
102 return device_type, device_build, battery_level, full_report, errors, dev_good | 111 |
| 112 return (device_type, device_build, battery_level, full_report, errors, |
| 113 dev_good, json_data) |
103 | 114 |
104 | 115 |
105 def CheckForMissingDevices(options, adb_online_devs): | 116 def CheckForMissingDevices(options, adb_online_devs): |
106 """Uses file of previous online devices to detect broken phones. | 117 """Uses file of previous online devices to detect broken phones. |
107 | 118 |
108 Args: | 119 Args: |
109 options: out_dir parameter of options argument is used as the base | 120 options: out_dir parameter of options argument is used as the base |
110 directory to load and update the cache file. | 121 directory to load and update the cache file. |
111 adb_online_devs: A list of serial numbers of the currently visible | 122 adb_online_devs: A list of serial numbers of the currently visible |
112 and online attached devices. | 123 and online attached devices. |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 if not usb_restarted and devices: | 323 if not usb_restarted and devices: |
313 # The USB wasn't restarted, but there's at least one device online. | 324 # The USB wasn't restarted, but there's at least one device online. |
314 # No point in trying to wait for all devices. | 325 # No point in trying to wait for all devices. |
315 break | 326 break |
316 retries -= 1 | 327 retries -= 1 |
317 | 328 |
318 # TODO(navabi): Test to make sure this fails and then fix call | 329 # TODO(navabi): Test to make sure this fails and then fix call |
319 offline_devices = android_commands.GetAttachedDevices( | 330 offline_devices = android_commands.GetAttachedDevices( |
320 hardware=False, emulator=False, offline=True) | 331 hardware=False, emulator=False, offline=True) |
321 | 332 |
322 types, builds, batteries, reports, errors = [], [], [], [], [] | 333 types, builds, batteries, reports, errors, json_data = [], [], [], [], [], [] |
323 fail_step_lst = [] | 334 fail_step_lst = [] |
324 if devices: | 335 if devices: |
325 types, builds, batteries, reports, errors, fail_step_lst = ( | 336 types, builds, batteries, reports, errors, fail_step_lst, json_data = ( |
326 zip(*[DeviceInfo(dev, options) for dev in devices])) | 337 zip(*[DeviceInfo(dev, options) for dev in devices])) |
327 | 338 |
328 err_msg = CheckForMissingDevices(options, devices) or [] | 339 err_msg = CheckForMissingDevices(options, devices) or [] |
329 | 340 |
330 unique_types = list(set(types)) | 341 unique_types = list(set(types)) |
331 unique_builds = list(set(builds)) | 342 unique_builds = list(set(builds)) |
332 | 343 |
333 bb_annotations.PrintMsg('Online devices: %d. Device types %s, builds %s' | 344 bb_annotations.PrintMsg('Online devices: %d. Device types %s, builds %s' |
334 % (len(devices), unique_types, unique_builds)) | 345 % (len(devices), unique_types, unique_builds)) |
335 print '\n'.join(reports) | 346 print '\n'.join(reports) |
(...skipping 20 matching lines...) Expand all Loading... |
356 perf_tests_results_helper.PrintPerfResult('BotDevices', 'OfflineDevices', | 367 perf_tests_results_helper.PrintPerfResult('BotDevices', 'OfflineDevices', |
357 [len(offline_devices)], 'devices', | 368 [len(offline_devices)], 'devices', |
358 'unimportant') | 369 'unimportant') |
359 for serial, battery in zip(devices, batteries): | 370 for serial, battery in zip(devices, batteries): |
360 perf_tests_results_helper.PrintPerfResult('DeviceBattery', serial, | 371 perf_tests_results_helper.PrintPerfResult('DeviceBattery', serial, |
361 [battery], '%', | 372 [battery], '%', |
362 'unimportant') | 373 'unimportant') |
363 | 374 |
364 if options.json_output: | 375 if options.json_output: |
365 with open(options.json_output, 'wb') as f: | 376 with open(options.json_output, 'wb') as f: |
366 f.write(json.dumps({ | 377 f.write(json.dumps(json_data, indent=4)) |
367 'online_devices': devices, | |
368 'offline_devices': offline_devices, | |
369 'expected_devices': expected_devices, | |
370 'unique_types': unique_types, | |
371 'unique_builds': unique_builds, | |
372 })) | |
373 | 378 |
374 num_failed_devs = 0 | 379 num_failed_devs = 0 |
375 for fail_status, device in zip(fail_step_lst, devices): | 380 for fail_status, device in zip(fail_step_lst, devices): |
376 if not fail_status: | 381 if not fail_status: |
377 device_blacklist.ExtendBlacklist([str(device)]) | 382 device_blacklist.ExtendBlacklist([str(device)]) |
378 num_failed_devs += 1 | 383 num_failed_devs += 1 |
379 | 384 |
380 if num_failed_devs == len(devices): | 385 if num_failed_devs == len(devices): |
381 return 2 | 386 return 2 |
382 | 387 |
383 if not devices: | 388 if not devices: |
384 return 1 | 389 return 1 |
385 | 390 |
386 | 391 |
387 if __name__ == '__main__': | 392 if __name__ == '__main__': |
388 sys.exit(main()) | 393 sys.exit(main()) |
OLD | NEW |