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

Side by Side Diff: build/android/pylib/forwarder.py

Issue 1316413003: [Android] Add a configurable environment for devil/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
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
11 11
12 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
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.android_sdk.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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = os.path.join(
201 constants.GetOutDirectory(), 'host_forwarder') 202 devil.env.binaries.binary_dir, 'host_forwarder')
202 assert os.path.exists(self._host_forwarder_path), 'Please build forwarder2' 203 assert os.path.exists(self._host_forwarder_path), 'Please build forwarder2'
203 self._device_forwarder_path_on_host = os.path.join( 204 self._device_forwarder_path_on_host = os.path.join(
204 constants.GetOutDirectory(), 'forwarder_dist') 205 devil.env.binaries.binary_dir, 'forwarder_dist')
205 self._InitHostLocked() 206 self._InitHostLocked()
206 207
207 @staticmethod 208 @staticmethod
208 def _UnmapDevicePortLocked(device_port, device): 209 def _UnmapDevicePortLocked(device_port, device):
209 """Internal method used by UnmapDevicePort(). 210 """Internal method used by UnmapDevicePort().
210 211
211 Note that the global lock must be acquired before calling this method. 212 Note that the global lock must be acquired before calling this method.
212 """ 213 """
213 instance = Forwarder._GetInstanceLocked(None) 214 instance = Forwarder._GetInstanceLocked(None)
214 serial = str(device) 215 serial = str(device)
215 serial_with_port = (serial, device_port) 216 serial_with_port = (serial, device_port)
216 if not serial_with_port in instance._device_to_host_port_map: 217 if not serial_with_port in instance._device_to_host_port_map:
217 logging.error('Trying to unmap non-forwarded port %d', device_port) 218 logging.error('Trying to unmap non-forwarded port %d', device_port)
218 return 219 return
219 redirection_command = ['--adb=' + constants.GetAdbPath(), 220 redirection_command = ['--adb=' + devil.env.android_sdk.adb_path,
220 '--serial-id=' + serial, 221 '--serial-id=' + serial,
221 '--unmap', str(device_port)] 222 '--unmap', str(device_port)]
222 logging.info('Undo forwarding using command: %s', redirection_command) 223 logging.info('Undo forwarding using command: %s', redirection_command)
223 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput( 224 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput(
224 [instance._host_forwarder_path] + redirection_command) 225 [instance._host_forwarder_path] + redirection_command)
225 if exit_code != 0: 226 if exit_code != 0:
226 logging.error( 227 logging.error(
227 '%s exited with %d:\n%s', 228 '%s exited with %d:\n%s',
228 instance._host_forwarder_path, exit_code, '\n'.join(output)) 229 instance._host_forwarder_path, exit_code, '\n'.join(output))
229 host_port = instance._device_to_host_port_map[serial_with_port] 230 host_port = instance._device_to_host_port_map[serial_with_port]
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 logging.info('Killing device_forwarder.') 318 logging.info('Killing device_forwarder.')
318 Forwarder._instance._initialized_devices.discard(str(device)) 319 Forwarder._instance._initialized_devices.discard(str(device))
319 if not device.FileExists(Forwarder._DEVICE_FORWARDER_PATH): 320 if not device.FileExists(Forwarder._DEVICE_FORWARDER_PATH):
320 return 321 return
321 322
322 cmd = '%s %s --kill-server' % (tool.GetUtilWrapper(), 323 cmd = '%s %s --kill-server' % (tool.GetUtilWrapper(),
323 Forwarder._DEVICE_FORWARDER_PATH) 324 Forwarder._DEVICE_FORWARDER_PATH)
324 device.RunShellCommand( 325 device.RunShellCommand(
325 cmd, env={'LD_LIBRARY_PATH': Forwarder._DEVICE_FORWARDER_FOLDER}, 326 cmd, env={'LD_LIBRARY_PATH': Forwarder._DEVICE_FORWARDER_FOLDER},
326 check_return=True) 327 check_return=True)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698