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 13 matching lines...) Expand all Loading... |
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 device_blacklist | 33 from pylib.device import device_blacklist |
34 from pylib.device import device_errors | |
35 from pylib.device import device_list | 34 from pylib.device import device_list |
36 from pylib.device import device_utils | 35 from pylib.device import device_utils |
37 | 36 |
38 def DeviceInfo(serial, options): | 37 def DeviceInfo(serial, options): |
39 """Gathers info on a device via various adb calls. | 38 """Gathers info on a device via various adb calls. |
40 | 39 |
41 Args: | 40 Args: |
42 serial: The serial of the attached device to construct info about. | 41 serial: The serial of the attached device to construct info about. |
43 | 42 |
44 Returns: | 43 Returns: |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 ' Current Battery Service state: ', | 75 ' Current Battery Service state: ', |
77 '\n'.join([' %s: %s' % (k, v) | 76 '\n'.join([' %s: %s' % (k, v) |
78 for k, v in battery_info.iteritems()]), | 77 for k, v in battery_info.iteritems()]), |
79 ' IMEI slice: %s' % imei_slice, | 78 ' IMEI slice: %s' % imei_slice, |
80 ' Wifi IP: %s' % device_adb.GetProp('dhcp.wlan0.ipaddress'), | 79 ' Wifi IP: %s' % device_adb.GetProp('dhcp.wlan0.ipaddress'), |
81 ''] | 80 ''] |
82 | 81 |
83 errors = [] | 82 errors = [] |
84 dev_good = True | 83 dev_good = True |
85 if battery_level < 15: | 84 if battery_level < 15: |
86 errors += ['Device critically low in battery. Turning off device.'] | 85 errors += ['Device critically low in battery. Will add to blacklist.'] |
87 dev_good = False | 86 dev_good = False |
| 87 if not device_adb.old_interface.IsDeviceCharging(): |
| 88 if device_adb.old_interface.CanControlUsbCharging(): |
| 89 device_adb.old_interface.EnableUsbCharging() |
| 90 else: |
| 91 logging.error('Device %s is not charging' % serial) |
88 if not options.no_provisioning_check: | 92 if not options.no_provisioning_check: |
89 setup_wizard_disabled = ( | 93 setup_wizard_disabled = ( |
90 device_adb.GetProp('ro.setupwizard.mode') == 'DISABLED') | 94 device_adb.GetProp('ro.setupwizard.mode') == 'DISABLED') |
91 if not setup_wizard_disabled and device_build_type != 'user': | 95 if not setup_wizard_disabled and device_build_type != 'user': |
92 errors += ['Setup wizard not disabled. Was it provisioned correctly?'] | 96 errors += ['Setup wizard not disabled. Was it provisioned correctly?'] |
93 if (device_product_name == 'mantaray' and | 97 if (device_product_name == 'mantaray' and |
94 battery_info.get('AC powered', None) != 'true'): | 98 battery_info.get('AC powered', None) != 'true'): |
95 errors += ['Mantaray device not connected to AC power.'] | 99 errors += ['Mantaray device not connected to AC power.'] |
96 | 100 |
97 # Turn off devices with low battery. | |
98 if battery_level < 15: | |
99 try: | |
100 device_adb.EnableRoot() | |
101 except device_errors.CommandFailedError as e: | |
102 # Attempt shutdown anyway. | |
103 # TODO(jbudorick) Handle this exception appropriately after interface | |
104 # conversions are finished. | |
105 logging.error(str(e)) | |
106 device_adb.old_interface.Shutdown() | |
107 full_report = '\n'.join(report) | 101 full_report = '\n'.join(report) |
108 return device_type, device_build, battery_level, full_report, errors, dev_good | 102 return device_type, device_build, battery_level, full_report, errors, dev_good |
109 | 103 |
110 | 104 |
111 def CheckForMissingDevices(options, adb_online_devs): | 105 def CheckForMissingDevices(options, adb_online_devs): |
112 """Uses file of previous online devices to detect broken phones. | 106 """Uses file of previous online devices to detect broken phones. |
113 | 107 |
114 Args: | 108 Args: |
115 options: out_dir parameter of options argument is used as the base | 109 options: out_dir parameter of options argument is used as the base |
116 directory to load and update the cache file. | 110 directory to load and update the cache file. |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 if options.json_output: | 364 if options.json_output: |
371 with open(options.json_output, 'wb') as f: | 365 with open(options.json_output, 'wb') as f: |
372 f.write(json.dumps({ | 366 f.write(json.dumps({ |
373 'online_devices': devices, | 367 'online_devices': devices, |
374 'offline_devices': offline_devices, | 368 'offline_devices': offline_devices, |
375 'expected_devices': expected_devices, | 369 'expected_devices': expected_devices, |
376 'unique_types': unique_types, | 370 'unique_types': unique_types, |
377 'unique_builds': unique_builds, | 371 'unique_builds': unique_builds, |
378 })) | 372 })) |
379 | 373 |
380 if False in fail_step_lst: | 374 num_failed_devs = 0 |
381 # TODO(navabi): Build fails on device status check step if there exists any | 375 for fail_status, device in zip(fail_step_lst, devices): |
382 # devices with critically low battery. Remove those devices from testing, | 376 if not fail_status: |
383 # allowing build to continue with good devices. | 377 device_blacklist.ExtendBlacklist([str(device)]) |
| 378 num_failed_devs += 1 |
| 379 |
| 380 if num_failed_devs == len(devices): |
384 return 2 | 381 return 2 |
385 | 382 |
386 if not devices: | 383 if not devices: |
387 return 1 | 384 return 1 |
388 | 385 |
389 | 386 |
390 if __name__ == '__main__': | 387 if __name__ == '__main__': |
391 sys.exit(main()) | 388 sys.exit(main()) |
OLD | NEW |