Reland "Add --serial-id option to host_forwarder."
This relands r209945. r242846 slightly changed the CLI <-> device daemon message sequence which made the following check fail in case the device daemon was started but already running on the device: device_forwarder_main.cc:10: CHECK_GT(bytes_read, 0). This was actually caused by an unexposed long standing issue in daemon.cc. ConnectToUnixDomainSocket() is performing a hand check to make sure that the CLI is connecting to the forwarder daemon. While doing this hand check, rather than only reading the expected fixed-size message, the function was reading all the available bytes in the socket thus consuming the client data. BUG=242846 R=bulach@chromium.org Review URL: https://codereview.chromium.org/18635005 git-svn-id: http://src.chromium.org/svn/trunk/src/build@210273 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
Родитель
749841ee04
Коммит
c664eec31b
|
@ -12,7 +12,6 @@ import time
|
|||
import android_commands
|
||||
import cmd_helper
|
||||
import constants
|
||||
import ports
|
||||
|
||||
from pylib import pexpect
|
||||
|
||||
|
@ -24,10 +23,6 @@ def _MakeBinaryPath(build_type, binary_name):
|
|||
class Forwarder(object):
|
||||
"""Thread-safe class to manage port forwards from the device to the host."""
|
||||
|
||||
# Unix Abstract socket path:
|
||||
_DEVICE_ADB_CONTROL_PORT = 'chrome_device_forwarder'
|
||||
_TIMEOUT_SECS = 30
|
||||
|
||||
_DEVICE_FORWARDER_FOLDER = (constants.TEST_EXECUTABLE_DIR +
|
||||
'/forwarder/')
|
||||
_DEVICE_FORWARDER_PATH = (constants.TEST_EXECUTABLE_DIR +
|
||||
|
@ -71,19 +66,16 @@ class Forwarder(object):
|
|||
"""
|
||||
with self._lock:
|
||||
self._InitDeviceLocked(tool)
|
||||
self._InitHostLocked()
|
||||
host_name = '127.0.0.1'
|
||||
redirection_commands = [
|
||||
'%d:%d:%d:%s' % (self._host_adb_control_port, device, host,
|
||||
host_name) for device, host in port_pairs]
|
||||
logging.info('Command format: <ADB port>:<Device port>' +
|
||||
'[:<Forward to port>:<Forward to address>]')
|
||||
['--serial-id=' + self._adb.Adb().GetSerialNumber(), '--map',
|
||||
str(device), str(host)] for device, host in port_pairs]
|
||||
logging.info('Forwarding using commands: %s', redirection_commands)
|
||||
|
||||
for redirection_command in redirection_commands:
|
||||
try:
|
||||
(exit_code, output) = cmd_helper.GetCmdStatusAndOutput(
|
||||
[self._host_forwarder_path, redirection_command])
|
||||
[self._host_forwarder_path] + redirection_command)
|
||||
except OSError as e:
|
||||
if e.errno == 2:
|
||||
raise Exception('Unable to start host forwarder. Make sure you have'
|
||||
|
@ -94,8 +86,8 @@ class Forwarder(object):
|
|||
self._host_forwarder_path, exit_code, '\n'.join(output)))
|
||||
tokens = output.split(':')
|
||||
if len(tokens) != 2:
|
||||
raise Exception('Unexpected host forwarder output "%s", ' +
|
||||
'expected "device_port:host_port"' % output)
|
||||
raise Exception(('Unexpected host forwarder output "%s", ' +
|
||||
'expected "device_port:host_port"') % output)
|
||||
device_port = int(tokens[0])
|
||||
host_port = int(tokens[1])
|
||||
self._device_to_host_port_map[device_port] = host_port
|
||||
|
@ -103,19 +95,6 @@ class Forwarder(object):
|
|||
logging.info('Forwarding device port: %d to host port: %d.',
|
||||
device_port, host_port)
|
||||
|
||||
def _InitHostLocked(self):
|
||||
"""Initializes the host forwarder process (only once)."""
|
||||
if self._host_adb_control_port:
|
||||
return
|
||||
self._host_adb_control_port = ports.AllocateTestServerPort()
|
||||
if not self._host_adb_control_port:
|
||||
raise Exception('Failed to allocate a TCP port in the host machine.')
|
||||
if cmd_helper.RunCmd(
|
||||
['adb', '-s', self._adb._adb.GetSerialNumber(), 'forward',
|
||||
'tcp:%s' % self._host_adb_control_port,
|
||||
'localabstract:%s' % Forwarder._DEVICE_ADB_CONTROL_PORT]) != 0:
|
||||
raise Exception('Error while running adb forward.')
|
||||
|
||||
def _InitDeviceLocked(self, tool):
|
||||
"""Initializes the device forwarder process (only once)."""
|
||||
if self._device_initialized:
|
||||
|
@ -124,9 +103,8 @@ class Forwarder(object):
|
|||
self._device_forwarder_path_on_host,
|
||||
Forwarder._DEVICE_FORWARDER_FOLDER)
|
||||
(exit_code, output) = self._adb.GetShellCommandStatusAndOutput(
|
||||
'%s %s %s %s' % (Forwarder._LD_LIBRARY_PATH, tool.GetUtilWrapper(),
|
||||
Forwarder._DEVICE_FORWARDER_PATH,
|
||||
Forwarder._DEVICE_ADB_CONTROL_PORT))
|
||||
'%s %s %s' % (Forwarder._LD_LIBRARY_PATH, tool.GetUtilWrapper(),
|
||||
Forwarder._DEVICE_FORWARDER_PATH))
|
||||
if exit_code != 0:
|
||||
raise Exception(
|
||||
'Failed to start device forwarder:\n%s' % '\n'.join(output))
|
||||
|
@ -144,11 +122,11 @@ class Forwarder(object):
|
|||
def _UnmapDevicePortInternalLocked(self, device_port):
|
||||
if not device_port in self._device_to_host_port_map:
|
||||
return
|
||||
# Please note the minus sign below.
|
||||
redirection_command = '%d:-%d' % (
|
||||
self._host_adb_control_port, device_port)
|
||||
redirection_command = [
|
||||
'--serial-id=' + self._adb.Adb().GetSerialNumber(), '--unmap',
|
||||
str(device_port)]
|
||||
(exit_code, output) = cmd_helper.GetCmdStatusAndOutput(
|
||||
[self._host_forwarder_path, redirection_command])
|
||||
[self._host_forwarder_path] + redirection_command)
|
||||
if exit_code != 0:
|
||||
raise Exception('%s exited with %d:\n%s' % (
|
||||
self._host_forwarder_path, exit_code, '\n'.join(output)))
|
||||
|
@ -170,7 +148,7 @@ class Forwarder(object):
|
|||
'Release' if build_type == 'Debug' else 'Debug', 'host_forwarder')
|
||||
assert os.path.exists(host_forwarder_path), 'Please build forwarder2'
|
||||
(exit_code, output) = cmd_helper.GetCmdStatusAndOutput(
|
||||
[host_forwarder_path, 'kill-server'])
|
||||
[host_forwarder_path, '--kill-server'])
|
||||
if exit_code != 0:
|
||||
(exit_code, output) = cmd_helper.GetCmdStatusAndOutput(
|
||||
['pkill', 'host_forwarder'])
|
||||
|
@ -191,8 +169,8 @@ class Forwarder(object):
|
|||
if not adb.FileExistsOnDevice(Forwarder._DEVICE_FORWARDER_PATH):
|
||||
return
|
||||
(exit_code, output) = adb.GetShellCommandStatusAndOutput(
|
||||
'%s %s kill-server' % (tool.GetUtilWrapper(),
|
||||
Forwarder._DEVICE_FORWARDER_PATH))
|
||||
'%s %s --kill-server' % (tool.GetUtilWrapper(),
|
||||
Forwarder._DEVICE_FORWARDER_PATH))
|
||||
# TODO(pliard): Remove the following call to KillAllBlocking() when we are
|
||||
# sure that the old version of device_forwarder (not supporting
|
||||
# 'kill-server') is not running on the bots anymore.
|
||||
|
|
Загрузка…
Ссылка в новой задаче