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 import argparse | 9 import argparse |
9 import json | 10 import json |
10 import logging | 11 import logging |
11 import os | 12 import os |
12 import psutil | 13 import psutil |
13 import re | 14 import re |
14 import signal | 15 import signal |
15 import smtplib | |
16 import subprocess | |
17 import sys | 16 import sys |
18 import time | |
19 import urllib | |
20 | |
21 import bb_annotations | |
22 import bb_utils | |
23 | |
24 sys.path.append(os.path.join(os.path.dirname(__file__), | |
25 os.pardir, os.pardir, 'util', 'lib', | |
26 'common')) | |
27 import perf_tests_results_helper # pylint: disable=F0401 | |
28 | 17 |
29 sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | 18 sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) |
30 from devil.android import battery_utils | 19 from devil.android import battery_utils |
31 from devil.android import device_blacklist | 20 from devil.android import device_blacklist |
32 from devil.android import device_errors | 21 from devil.android import device_errors |
33 from devil.android import device_list | 22 from devil.android import device_list |
34 from devil.android import device_utils | 23 from devil.android import device_utils |
35 from devil.android.sdk import adb_wrapper | 24 from devil.android.sdk import adb_wrapper |
36 from devil.utils import lsusb | 25 from devil.utils import lsusb |
37 from devil.utils import reset_usb | 26 from devil.utils import reset_usb |
38 from devil.utils import run_tests_helper | 27 from devil.utils import run_tests_helper |
39 from devil.utils import timeout_retry | |
40 from pylib import constants | 28 from pylib import constants |
41 from pylib.cmd_helper import GetCmdOutput | |
42 | 29 |
43 _RE_DEVICE_ID = re.compile('Device ID = (\d+)') | 30 _RE_DEVICE_ID = re.compile(r'Device ID = (\d+)') |
44 | 31 |
45 | 32 |
46 def KillAllAdb(): | 33 def KillAllAdb(): |
47 def GetAllAdb(): | 34 def GetAllAdb(): |
48 for p in psutil.process_iter(): | 35 for p in psutil.process_iter(): |
49 try: | 36 try: |
50 if 'adb' in p.name: | 37 if 'adb' in p.name: |
51 yield p | 38 yield p |
52 except (psutil.NoSuchProcess, psutil.AccessDenied): | 39 except (psutil.NoSuchProcess, psutil.AccessDenied): |
53 pass | 40 pass |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 """ | 201 """ |
215 | 202 |
216 statuses = DeviceStatus(devices, blacklist) | 203 statuses = DeviceStatus(devices, blacklist) |
217 | 204 |
218 should_restart_usb = set( | 205 should_restart_usb = set( |
219 status['serial'] for status in statuses | 206 status['serial'] for status in statuses |
220 if (not status['usb_status'] | 207 if (not status['usb_status'] |
221 or status['adb_status'] == 'unknown')) | 208 or status['adb_status'] == 'unknown')) |
222 should_restart_adb = should_restart_usb.union(set( | 209 should_restart_adb = should_restart_usb.union(set( |
223 status['serial'] for status in statuses | 210 status['serial'] for status in statuses |
224 if (status['adb_status'] in ('offline', 'unauthorized')))) | 211 if status['adb_status'] in ('offline', 'unauthorized'))) |
225 should_reboot_device = should_restart_adb.union(set( | 212 should_reboot_device = should_restart_adb.union(set( |
226 status['serial'] for status in statuses | 213 status['serial'] for status in statuses |
227 if status['blacklisted'])) | 214 if status['blacklisted'])) |
228 | 215 |
229 logging.debug('Should restart USB for:') | 216 logging.debug('Should restart USB for:') |
230 for d in should_restart_usb: | 217 for d in should_restart_usb: |
231 logging.debug(' %s', d) | 218 logging.debug(' %s', d) |
232 logging.debug('Should restart ADB for:') | 219 logging.debug('Should restart ADB for:') |
233 for d in should_restart_adb: | 220 for d in should_restart_adb: |
234 logging.debug(' %s', d) | 221 logging.debug(' %s', d) |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 build_product=status['type'], | 341 build_product=status['type'], |
355 build_id=status['build'], | 342 build_id=status['build'], |
356 temperature=float(status['battery']['temperature']) / 10, | 343 temperature=float(status['battery']['temperature']) / 10, |
357 level=status['battery']['level'] | 344 level=status['battery']['level'] |
358 )) | 345 )) |
359 else: | 346 else: |
360 f.write('{serial} {adb_status}'.format( | 347 f.write('{serial} {adb_status}'.format( |
361 serial=status['serial'], | 348 serial=status['serial'], |
362 adb_status=status['adb_status'] | 349 adb_status=status['adb_status'] |
363 )) | 350 )) |
364 except Exception: | 351 except Exception: # pylint: disable=broad-except |
365 pass | 352 pass |
366 | 353 |
367 # Dump the device statuses to JSON. | 354 # Dump the device statuses to JSON. |
368 if args.json_output: | 355 if args.json_output: |
369 with open(args.json_output, 'wb') as f: | 356 with open(args.json_output, 'wb') as f: |
370 f.write(json.dumps(statuses, indent=4)) | 357 f.write(json.dumps(statuses, indent=4)) |
371 | 358 |
372 live_devices = [status['serial'] for status in statuses | 359 live_devices = [status['serial'] for status in statuses |
373 if (status['adb_status'] == 'device' | 360 if (status['adb_status'] == 'device' |
374 and status['serial'] not in blacklist.Read())] | 361 and status['serial'] not in blacklist.Read())] |
375 | 362 |
376 # 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. |
377 return 0 if live_devices else constants.INFRA_EXIT_CODE | 364 return 0 if live_devices else constants.INFRA_EXIT_CODE |
378 | 365 |
379 | 366 |
380 if __name__ == '__main__': | 367 if __name__ == '__main__': |
381 sys.exit(main()) | 368 sys.exit(main()) |
OLD | NEW |