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 |
11 | 11 |
| 12 from devil import devil_env |
12 from devil.utils import cmd_helper | 13 from devil.utils import cmd_helper |
13 from pylib import constants | 14 from pylib import constants |
14 from pylib import valgrind_tools | 15 from pylib import valgrind_tools |
15 | 16 |
16 | 17 |
17 def _GetProcessStartTime(pid): | 18 def _GetProcessStartTime(pid): |
18 return psutil.Process(pid).create_time | 19 return psutil.Process(pid).create_time |
19 | 20 |
20 | 21 |
21 class _FileLock(object): | 22 class _FileLock(object): |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 Exception on failure to forward the port. | 71 Exception on failure to forward the port. |
71 """ | 72 """ |
72 if not tool: | 73 if not tool: |
73 tool = valgrind_tools.CreateTool(None, device) | 74 tool = valgrind_tools.CreateTool(None, device) |
74 with _FileLock(Forwarder._LOCK_PATH): | 75 with _FileLock(Forwarder._LOCK_PATH): |
75 instance = Forwarder._GetInstanceLocked(tool) | 76 instance = Forwarder._GetInstanceLocked(tool) |
76 instance._InitDeviceLocked(device, tool) | 77 instance._InitDeviceLocked(device, tool) |
77 | 78 |
78 device_serial = str(device) | 79 device_serial = str(device) |
79 redirection_commands = [ | 80 redirection_commands = [ |
80 ['--adb=' + constants.GetAdbPath(), | 81 ['--adb=' + devil_env.config.adb_path, |
81 '--serial-id=' + device_serial, | 82 '--serial-id=' + device_serial, |
82 '--map', str(device_port), str(host_port)] | 83 '--map', str(device_port), str(host_port)] |
83 for device_port, host_port in port_pairs] | 84 for device_port, host_port in port_pairs] |
84 logging.info('Forwarding using commands: %s', redirection_commands) | 85 logging.info('Forwarding using commands: %s', redirection_commands) |
85 | 86 |
86 for redirection_command in redirection_commands: | 87 for redirection_command in redirection_commands: |
87 try: | 88 try: |
88 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput( | 89 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput( |
89 [instance._host_forwarder_path] + redirection_command) | 90 [instance._host_forwarder_path] + redirection_command) |
90 except OSError as e: | 91 except OSError as e: |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 191 |
191 Args: | 192 Args: |
192 tool: Tool class to use to get wrapper, if necessary, for executing the | 193 tool: Tool class to use to get wrapper, if necessary, for executing the |
193 forwarder (see valgrind_tools.py). | 194 forwarder (see valgrind_tools.py). |
194 """ | 195 """ |
195 assert not Forwarder._instance | 196 assert not Forwarder._instance |
196 self._tool = tool | 197 self._tool = tool |
197 self._initialized_devices = set() | 198 self._initialized_devices = set() |
198 self._device_to_host_port_map = dict() | 199 self._device_to_host_port_map = dict() |
199 self._host_to_device_port_map = dict() | 200 self._host_to_device_port_map = dict() |
200 self._host_forwarder_path = os.path.join( | 201 self._host_forwarder_path = devil_env.config.forwarder_host_path |
201 constants.GetOutDirectory(), 'host_forwarder') | |
202 assert os.path.exists(self._host_forwarder_path), 'Please build forwarder2' | 202 assert os.path.exists(self._host_forwarder_path), 'Please build forwarder2' |
203 self._device_forwarder_path_on_host = os.path.join( | 203 self._device_forwarder_path_on_host = ( |
204 constants.GetOutDirectory(), 'forwarder_dist') | 204 devil_env.config.forwarder_device_path) |
205 self._InitHostLocked() | 205 self._InitHostLocked() |
206 | 206 |
207 @staticmethod | 207 @staticmethod |
208 def _UnmapDevicePortLocked(device_port, device): | 208 def _UnmapDevicePortLocked(device_port, device): |
209 """Internal method used by UnmapDevicePort(). | 209 """Internal method used by UnmapDevicePort(). |
210 | 210 |
211 Note that the global lock must be acquired before calling this method. | 211 Note that the global lock must be acquired before calling this method. |
212 """ | 212 """ |
213 instance = Forwarder._GetInstanceLocked(None) | 213 instance = Forwarder._GetInstanceLocked(None) |
214 serial = str(device) | 214 serial = str(device) |
215 serial_with_port = (serial, device_port) | 215 serial_with_port = (serial, device_port) |
216 if not serial_with_port in instance._device_to_host_port_map: | 216 if not serial_with_port in instance._device_to_host_port_map: |
217 logging.error('Trying to unmap non-forwarded port %d', device_port) | 217 logging.error('Trying to unmap non-forwarded port %d', device_port) |
218 return | 218 return |
219 redirection_command = ['--adb=' + constants.GetAdbPath(), | 219 redirection_command = ['--adb=' + devil_env.config.adb_path, |
220 '--serial-id=' + serial, | 220 '--serial-id=' + serial, |
221 '--unmap', str(device_port)] | 221 '--unmap', str(device_port)] |
222 logging.info('Undo forwarding using command: %s', redirection_command) | 222 logging.info('Undo forwarding using command: %s', redirection_command) |
223 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput( | 223 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput( |
224 [instance._host_forwarder_path] + redirection_command) | 224 [instance._host_forwarder_path] + redirection_command) |
225 if exit_code != 0: | 225 if exit_code != 0: |
226 logging.error( | 226 logging.error( |
227 '%s exited with %d:\n%s', | 227 '%s exited with %d:\n%s', |
228 instance._host_forwarder_path, exit_code, '\n'.join(output)) | 228 instance._host_forwarder_path, exit_code, '\n'.join(output)) |
229 host_port = instance._device_to_host_port_map[serial_with_port] | 229 host_port = instance._device_to_host_port_map[serial_with_port] |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 logging.info('Killing device_forwarder.') | 317 logging.info('Killing device_forwarder.') |
318 Forwarder._instance._initialized_devices.discard(str(device)) | 318 Forwarder._instance._initialized_devices.discard(str(device)) |
319 if not device.FileExists(Forwarder._DEVICE_FORWARDER_PATH): | 319 if not device.FileExists(Forwarder._DEVICE_FORWARDER_PATH): |
320 return | 320 return |
321 | 321 |
322 cmd = '%s %s --kill-server' % (tool.GetUtilWrapper(), | 322 cmd = '%s %s --kill-server' % (tool.GetUtilWrapper(), |
323 Forwarder._DEVICE_FORWARDER_PATH) | 323 Forwarder._DEVICE_FORWARDER_PATH) |
324 device.RunShellCommand( | 324 device.RunShellCommand( |
325 cmd, env={'LD_LIBRARY_PATH': Forwarder._DEVICE_FORWARDER_FOLDER}, | 325 cmd, env={'LD_LIBRARY_PATH': Forwarder._DEVICE_FORWARDER_FOLDER}, |
326 check_return=True) | 326 check_return=True) |
OLD | NEW |