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

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

Issue 1415413005: Revert of [Android] Add a configurable environment for devil/. (RELAND) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 | « build/android/provision_devices.py ('k') | build/android/pylib/perf/test_runner.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
11 11
12 from devil import devil_env
13 from devil.utils import cmd_helper 12 from devil.utils import cmd_helper
14 from pylib import constants 13 from pylib import constants
15 from pylib import valgrind_tools 14 from pylib import valgrind_tools
16 15
17 16
18 def _GetProcessStartTime(pid): 17 def _GetProcessStartTime(pid):
19 return psutil.Process(pid).create_time 18 return psutil.Process(pid).create_time
20 19
21 20
22 class _FileLock(object): 21 class _FileLock(object):
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 Exception on failure to forward the port. 70 Exception on failure to forward the port.
72 """ 71 """
73 if not tool: 72 if not tool:
74 tool = valgrind_tools.CreateTool(None, device) 73 tool = valgrind_tools.CreateTool(None, device)
75 with _FileLock(Forwarder._LOCK_PATH): 74 with _FileLock(Forwarder._LOCK_PATH):
76 instance = Forwarder._GetInstanceLocked(tool) 75 instance = Forwarder._GetInstanceLocked(tool)
77 instance._InitDeviceLocked(device, tool) 76 instance._InitDeviceLocked(device, tool)
78 77
79 device_serial = str(device) 78 device_serial = str(device)
80 redirection_commands = [ 79 redirection_commands = [
81 ['--adb=' + devil_env.config.FetchPath('adb'), 80 ['--adb=' + constants.GetAdbPath(),
82 '--serial-id=' + device_serial, 81 '--serial-id=' + device_serial,
83 '--map', str(device_port), str(host_port)] 82 '--map', str(device_port), str(host_port)]
84 for device_port, host_port in port_pairs] 83 for device_port, host_port in port_pairs]
85 logging.info('Forwarding using commands: %s', redirection_commands) 84 logging.info('Forwarding using commands: %s', redirection_commands)
86 85
87 for redirection_command in redirection_commands: 86 for redirection_command in redirection_commands:
88 try: 87 try:
89 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput( 88 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput(
90 [instance._host_forwarder_path] + redirection_command) 89 [instance._host_forwarder_path] + redirection_command)
91 except OSError as e: 90 except OSError as e:
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 190
192 Args: 191 Args:
193 tool: Tool class to use to get wrapper, if necessary, for executing the 192 tool: Tool class to use to get wrapper, if necessary, for executing the
194 forwarder (see valgrind_tools.py). 193 forwarder (see valgrind_tools.py).
195 """ 194 """
196 assert not Forwarder._instance 195 assert not Forwarder._instance
197 self._tool = tool 196 self._tool = tool
198 self._initialized_devices = set() 197 self._initialized_devices = set()
199 self._device_to_host_port_map = dict() 198 self._device_to_host_port_map = dict()
200 self._host_to_device_port_map = dict() 199 self._host_to_device_port_map = dict()
201 self._host_forwarder_path = devil_env.config.FetchPath('forwarder_host') 200 self._host_forwarder_path = os.path.join(
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(
204 constants.GetOutDirectory(), 'forwarder_dist')
203 self._InitHostLocked() 205 self._InitHostLocked()
204 206
205 @staticmethod 207 @staticmethod
206 def _UnmapDevicePortLocked(device_port, device): 208 def _UnmapDevicePortLocked(device_port, device):
207 """Internal method used by UnmapDevicePort(). 209 """Internal method used by UnmapDevicePort().
208 210
209 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.
210 """ 212 """
211 instance = Forwarder._GetInstanceLocked(None) 213 instance = Forwarder._GetInstanceLocked(None)
212 serial = str(device) 214 serial = str(device)
213 serial_with_port = (serial, device_port) 215 serial_with_port = (serial, device_port)
214 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:
215 logging.error('Trying to unmap non-forwarded port %d', device_port) 217 logging.error('Trying to unmap non-forwarded port %d', device_port)
216 return 218 return
217 redirection_command = ['--adb=' + devil_env.config.FetchPath('adb'), 219 redirection_command = ['--adb=' + constants.GetAdbPath(),
218 '--serial-id=' + serial, 220 '--serial-id=' + serial,
219 '--unmap', str(device_port)] 221 '--unmap', str(device_port)]
220 logging.info('Undo forwarding using command: %s', redirection_command) 222 logging.info('Undo forwarding using command: %s', redirection_command)
221 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput( 223 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput(
222 [instance._host_forwarder_path] + redirection_command) 224 [instance._host_forwarder_path] + redirection_command)
223 if exit_code != 0: 225 if exit_code != 0:
224 logging.error( 226 logging.error(
225 '%s exited with %d:\n%s', 227 '%s exited with %d:\n%s',
226 instance._host_forwarder_path, exit_code, '\n'.join(output)) 228 instance._host_forwarder_path, exit_code, '\n'.join(output))
227 host_port = instance._device_to_host_port_map[serial_with_port] 229 host_port = instance._device_to_host_port_map[serial_with_port]
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 272
271 Args: 273 Args:
272 device: A DeviceUtils instance. 274 device: A DeviceUtils instance.
273 tool: Tool class to use to get wrapper, if necessary, for executing the 275 tool: Tool class to use to get wrapper, if necessary, for executing the
274 forwarder (see valgrind_tools.py). 276 forwarder (see valgrind_tools.py).
275 """ 277 """
276 device_serial = str(device) 278 device_serial = str(device)
277 if device_serial in self._initialized_devices: 279 if device_serial in self._initialized_devices:
278 return 280 return
279 Forwarder._KillDeviceLocked(device, tool) 281 Forwarder._KillDeviceLocked(device, tool)
280 forwarder_device_path_on_host = devil_env.config.FetchPath(
281 'forwarder_device', device=device)
282 forwarder_device_path_on_device = (
283 Forwarder._DEVICE_FORWARDER_FOLDER
284 if os.path.isdir(forwarder_device_path_on_host)
285 else Forwarder._DEVICE_FORWARDER_PATH)
286 device.PushChangedFiles([( 282 device.PushChangedFiles([(
287 forwarder_device_path_on_host, 283 self._device_forwarder_path_on_host,
288 forwarder_device_path_on_device)]) 284 Forwarder._DEVICE_FORWARDER_FOLDER)])
289
290 cmd = '%s %s' % (tool.GetUtilWrapper(), Forwarder._DEVICE_FORWARDER_PATH) 285 cmd = '%s %s' % (tool.GetUtilWrapper(), Forwarder._DEVICE_FORWARDER_PATH)
291 device.RunShellCommand( 286 device.RunShellCommand(
292 cmd, env={'LD_LIBRARY_PATH': Forwarder._DEVICE_FORWARDER_FOLDER}, 287 cmd, env={'LD_LIBRARY_PATH': Forwarder._DEVICE_FORWARDER_FOLDER},
293 check_return=True) 288 check_return=True)
294 self._initialized_devices.add(device_serial) 289 self._initialized_devices.add(device_serial)
295 290
296 def _KillHostLocked(self): 291 def _KillHostLocked(self):
297 """Kills the forwarder process running on the host. 292 """Kills the forwarder process running on the host.
298 293
299 Note that the global lock must be acquired before calling this method. 294 Note that the global lock must be acquired before calling this method.
(...skipping 22 matching lines...) Expand all
322 logging.info('Killing device_forwarder.') 317 logging.info('Killing device_forwarder.')
323 Forwarder._instance._initialized_devices.discard(str(device)) 318 Forwarder._instance._initialized_devices.discard(str(device))
324 if not device.FileExists(Forwarder._DEVICE_FORWARDER_PATH): 319 if not device.FileExists(Forwarder._DEVICE_FORWARDER_PATH):
325 return 320 return
326 321
327 cmd = '%s %s --kill-server' % (tool.GetUtilWrapper(), 322 cmd = '%s %s --kill-server' % (tool.GetUtilWrapper(),
328 Forwarder._DEVICE_FORWARDER_PATH) 323 Forwarder._DEVICE_FORWARDER_PATH)
329 device.RunShellCommand( 324 device.RunShellCommand(
330 cmd, env={'LD_LIBRARY_PATH': Forwarder._DEVICE_FORWARDER_FOLDER}, 325 cmd, env={'LD_LIBRARY_PATH': Forwarder._DEVICE_FORWARDER_FOLDER},
331 check_return=True) 326 check_return=True)
OLDNEW
« no previous file with comments | « build/android/provision_devices.py ('k') | build/android/pylib/perf/test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698