Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: devil/devil/android/forwarder.py

Issue 2808763004: [devil] Raise DeviceUnreachableError on device not found (Closed)
Patch Set: match specific device Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « devil/devil/android/device_test_case.py ('k') | devil/devil/android/sdk/adb_wrapper.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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)
OLDNEW
« no previous file with comments | « devil/devil/android/device_test_case.py ('k') | devil/devil/android/sdk/adb_wrapper.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698