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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 os.close(self._fd) | 43 os.close(self._fd) |
44 | 44 |
45 | 45 |
46 class Forwarder(object): | 46 class Forwarder(object): |
47 """Thread-safe class to manage port forwards from the device to the host.""" | 47 """Thread-safe class to manage port forwards from the device to the host.""" |
48 | 48 |
49 _DEVICE_FORWARDER_FOLDER = (constants.TEST_EXECUTABLE_DIR + | 49 _DEVICE_FORWARDER_FOLDER = (constants.TEST_EXECUTABLE_DIR + |
50 '/forwarder/') | 50 '/forwarder/') |
51 _DEVICE_FORWARDER_PATH = (constants.TEST_EXECUTABLE_DIR + | 51 _DEVICE_FORWARDER_PATH = (constants.TEST_EXECUTABLE_DIR + |
52 '/forwarder/device_forwarder') | 52 '/forwarder/device_forwarder') |
53 _LD_LIBRARY_PATH = 'LD_LIBRARY_PATH=%s' % _DEVICE_FORWARDER_FOLDER | |
54 _LOCK_PATH = '/tmp/chrome.forwarder.lock' | 53 _LOCK_PATH = '/tmp/chrome.forwarder.lock' |
55 _MULTIPROCESSING_ENV_VAR = 'CHROME_FORWARDER_USE_MULTIPROCESSING' | 54 _MULTIPROCESSING_ENV_VAR = 'CHROME_FORWARDER_USE_MULTIPROCESSING' |
56 # Defined in host_forwarder_main.cc | 55 # Defined in host_forwarder_main.cc |
57 _HOST_FORWARDER_LOG = '/tmp/host_forwarder_log' | 56 _HOST_FORWARDER_LOG = '/tmp/host_forwarder_log' |
58 | 57 |
59 _instance = None | 58 _instance = None |
60 | 59 |
61 @staticmethod | 60 @staticmethod |
62 def UseMultiprocessing(): | 61 def UseMultiprocessing(): |
63 """Tells the forwarder that multiprocessing is used.""" | 62 """Tells the forwarder that multiprocessing is used.""" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 tool: Tool class to use to get wrapper, if necessary, for executing the | 285 tool: Tool class to use to get wrapper, if necessary, for executing the |
287 forwarder (see valgrind_tools.py). | 286 forwarder (see valgrind_tools.py). |
288 """ | 287 """ |
289 device_serial = device.old_interface.Adb().GetSerialNumber() | 288 device_serial = device.old_interface.Adb().GetSerialNumber() |
290 if device_serial in self._initialized_devices: | 289 if device_serial in self._initialized_devices: |
291 return | 290 return |
292 Forwarder._KillDeviceLocked(device, tool) | 291 Forwarder._KillDeviceLocked(device, tool) |
293 device.old_interface.PushIfNeeded( | 292 device.old_interface.PushIfNeeded( |
294 self._device_forwarder_path_on_host, | 293 self._device_forwarder_path_on_host, |
295 Forwarder._DEVICE_FORWARDER_FOLDER) | 294 Forwarder._DEVICE_FORWARDER_FOLDER) |
296 (exit_code, output) = device.old_interface.GetShellCommandStatusAndOutput( | 295 cmd = '%s %s' % (tool.GetUtilWrapper(), Forwarder._DEVICE_FORWARDER_PATH) |
297 '%s %s %s' % (Forwarder._LD_LIBRARY_PATH, tool.GetUtilWrapper(), | 296 (exit_code, output) = device.old_interface.GetAndroidToolStatusAndOutput( |
298 Forwarder._DEVICE_FORWARDER_PATH)) | 297 cmd, lib_path=Forwarder._DEVICE_FORWARDER_FOLDER) |
299 if exit_code != 0: | 298 if exit_code != 0: |
300 raise Exception( | 299 raise Exception( |
301 'Failed to start device forwarder:\n%s' % '\n'.join(output)) | 300 'Failed to start device forwarder:\n%s' % '\n'.join(output)) |
302 self._initialized_devices.add(device_serial) | 301 self._initialized_devices.add(device_serial) |
303 | 302 |
304 def _KillHostLocked(self): | 303 def _KillHostLocked(self): |
305 """Kills the forwarder process running on the host. | 304 """Kills the forwarder process running on the host. |
306 | 305 |
307 Note that the global lock must be acquired before calling this method. | 306 Note that the global lock must be acquired before calling this method. |
308 """ | 307 """ |
(...skipping 15 matching lines...) Expand all Loading... |
324 | 323 |
325 Args: | 324 Args: |
326 device: Instance of DeviceUtils for talking to the device. | 325 device: Instance of DeviceUtils for talking to the device. |
327 tool: Wrapper tool (e.g. valgrind) that can be used to execute the device | 326 tool: Wrapper tool (e.g. valgrind) that can be used to execute the device |
328 forwarder (see valgrind_tools.py). | 327 forwarder (see valgrind_tools.py). |
329 """ | 328 """ |
330 logging.info('Killing device_forwarder.') | 329 logging.info('Killing device_forwarder.') |
331 if not device.old_interface.FileExistsOnDevice( | 330 if not device.old_interface.FileExistsOnDevice( |
332 Forwarder._DEVICE_FORWARDER_PATH): | 331 Forwarder._DEVICE_FORWARDER_PATH): |
333 return | 332 return |
334 device.old_interface.GetShellCommandStatusAndOutput( | 333 |
335 '%s %s --kill-server' % (tool.GetUtilWrapper(), | 334 cmd = '%s %s --kill-server' % (tool.GetUtilWrapper(), |
336 Forwarder._DEVICE_FORWARDER_PATH)) | 335 Forwarder._DEVICE_FORWARDER_PATH) |
| 336 device.old_interface.GetAndroidToolStatusAndOutput( |
| 337 cmd, lib_path=Forwarder._DEVICE_FORWARDER_FOLDER) |
| 338 |
337 # TODO(pliard): Remove the following call to KillAllBlocking() when we are | 339 # TODO(pliard): Remove the following call to KillAllBlocking() when we are |
338 # sure that the old version of device_forwarder (not supporting | 340 # sure that the old version of device_forwarder (not supporting |
339 # 'kill-server') is not running on the bots anymore. | 341 # 'kill-server') is not running on the bots anymore. |
340 timeout_sec = 5 | 342 timeout_sec = 5 |
341 processes_killed = device.old_interface.KillAllBlocking( | 343 processes_killed = device.old_interface.KillAllBlocking( |
342 'device_forwarder', timeout_sec) | 344 'device_forwarder', timeout_sec) |
343 if not processes_killed: | 345 if not processes_killed: |
344 pids = device.old_interface.ExtractPid('device_forwarder') | 346 pids = device.old_interface.ExtractPid('device_forwarder') |
345 if pids: | 347 if pids: |
346 raise Exception('Timed out while killing device_forwarder') | 348 raise Exception('Timed out while killing device_forwarder') |
OLD | NEW |