OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # pylint: disable=W0212 | 5 # pylint: disable=W0212 |
6 | 6 |
7 import fcntl | 7 import fcntl |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import psutil | 10 import psutil |
(...skipping 28 matching lines...) Expand all Loading... |
39 logger.info(' %s', line) | 39 logger.info(' %s', line) |
40 except Exception: # pylint: disable=broad-except | 40 except Exception: # pylint: disable=broad-except |
41 # Grabbing the host forwarder log is best-effort. Ignore all errors. | 41 # Grabbing the host forwarder log is best-effort. Ignore all errors. |
42 logger.warning('Failed to get the contents of host_forwarder_log.') | 42 logger.warning('Failed to get the contents of host_forwarder_log.') |
43 | 43 |
44 # The device forwarder daemon logs to the logcat, so print the end of that. | 44 # The device forwarder daemon logs to the logcat, so print the end of that. |
45 try: | 45 try: |
46 logger.info('Last 50 lines of logcat:') | 46 logger.info('Last 50 lines of logcat:') |
47 for logcat_line in device.adb.Logcat(dump=True)[-50:]: | 47 for logcat_line in device.adb.Logcat(dump=True)[-50:]: |
48 logger.info(' %s', logcat_line) | 48 logger.info(' %s', logcat_line) |
49 except device_errors.CommandFailedError: | 49 except (device_errors.CommandFailedError, |
| 50 device_errors.DeviceUnreachableError): |
50 # Grabbing the device forwarder log is also best-effort. Ignore all errors. | 51 # Grabbing the device forwarder log is also best-effort. Ignore all errors. |
51 logger.warning('Failed to get the contents of the logcat.') | 52 logger.warning('Failed to get the contents of the logcat.') |
52 | 53 |
53 # Log alive device forwarders. | 54 # Log alive device forwarders. |
54 try: | 55 try: |
55 ps_out = device.RunShellCommand(['ps'], check_return=True) | 56 ps_out = device.RunShellCommand(['ps'], check_return=True) |
56 logger.info('Currently running device_forwarders:') | 57 logger.info('Currently running device_forwarders:') |
57 for line in ps_out: | 58 for line in ps_out: |
58 if 'device_forwarder' in line: | 59 if 'device_forwarder' in line: |
59 logger.info(' %s', line) | 60 logger.info(' %s', line) |
60 except device_errors.CommandFailedError: | 61 except (device_errors.CommandFailedError, |
| 62 device_errors.DeviceUnreachableError): |
61 logger.warning('Failed to list currently running device_forwarder ' | 63 logger.warning('Failed to list currently running device_forwarder ' |
62 'instances.') | 64 'instances.') |
63 | 65 |
64 | 66 |
65 class _FileLock(object): | 67 class _FileLock(object): |
66 """With statement-aware implementation of a file lock. | 68 """With statement-aware implementation of a file lock. |
67 | 69 |
68 File locks are needed for cross-process synchronization when the | 70 File locks are needed for cross-process synchronization when the |
69 multiprocessing Python module is used. | 71 multiprocessing Python module is used. |
70 """ | 72 """ |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 '`%s` timed out:\n%s' % (' '.join(map_cmd), e.output)) | 149 '`%s` timed out:\n%s' % (' '.join(map_cmd), e.output)) |
148 except OSError as e: | 150 except OSError as e: |
149 if e.errno == 2: | 151 if e.errno == 2: |
150 raise HostForwarderError( | 152 raise HostForwarderError( |
151 'Unable to start host forwarder. ' | 153 'Unable to start host forwarder. ' |
152 'Make sure you have built host_forwarder.') | 154 'Make sure you have built host_forwarder.') |
153 else: raise | 155 else: raise |
154 if exit_code != 0: | 156 if exit_code != 0: |
155 try: | 157 try: |
156 instance._KillDeviceLocked(device, tool) | 158 instance._KillDeviceLocked(device, tool) |
157 except device_errors.CommandFailedError: | 159 except (device_errors.CommandFailedError, |
| 160 device_errors.DeviceUnreachableError): |
158 # We don't want the failure to kill the device forwarder to | 161 # We don't want the failure to kill the device forwarder to |
159 # supersede the original failure to map. | 162 # supersede the original failure to map. |
160 logging.warning( | 163 logging.warning( |
161 'Failed to kill the device forwarder after map failure: %s', | 164 'Failed to kill the device forwarder after map failure: %s', |
162 str(e)) | 165 str(e)) |
163 _LogMapFailureDiagnostics(device) | 166 _LogMapFailureDiagnostics(device) |
164 formatted_output = ('\n'.join(output) if isinstance(output, list) | 167 formatted_output = ('\n'.join(output) if isinstance(output, list) |
165 else output) | 168 else output) |
166 raise HostForwarderError( | 169 raise HostForwarderError( |
167 '`%s` exited with %d:\n%s' % ( | 170 '`%s` exited with %d:\n%s' % ( |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 if not device.FileExists(Forwarder._DEVICE_FORWARDER_PATH): | 458 if not device.FileExists(Forwarder._DEVICE_FORWARDER_PATH): |
456 return | 459 return |
457 | 460 |
458 cmd = [Forwarder._DEVICE_FORWARDER_PATH, '--kill-server'] | 461 cmd = [Forwarder._DEVICE_FORWARDER_PATH, '--kill-server'] |
459 wrapper = tool.GetUtilWrapper() | 462 wrapper = tool.GetUtilWrapper() |
460 if wrapper: | 463 if wrapper: |
461 cmd.insert(0, wrapper) | 464 cmd.insert(0, wrapper) |
462 device.RunShellCommand( | 465 device.RunShellCommand( |
463 cmd, env={'LD_LIBRARY_PATH': Forwarder._DEVICE_FORWARDER_FOLDER}, | 466 cmd, env={'LD_LIBRARY_PATH': Forwarder._DEVICE_FORWARDER_FOLDER}, |
464 check_return=True) | 467 check_return=True) |
OLD | NEW |