Add device port unmapping support to forwarder2.
There used not to be any way to unmap a previously forwarded port. Since the host and device forwarder processes are kept alive during a whole test suite, both the host and device ended up with an unnecessarily high amount of unused open sockets. That is source of flakiness (e.g. too many opened file descriptors). This adds an UnmapDevicePort() method to the Python Forwarder wrapper class and modifies the native forwarder2 to accept a negative port on the command line. When a negative port is provided, the host forwarder tries to unmap that port (that was mapped previously). BUG=229685,239014 R=bulach@chromium.org, digit@chromium.org Review URL: https://codereview.chromium.org/15008004 git-svn-id: http://src.chromium.org/svn/trunk/src/build@200257 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
Родитель
32001034b5
Коммит
cd400c2477
|
@ -256,7 +256,7 @@ class TestServerThread(threading.Thread):
|
|||
if self.process.poll() is None:
|
||||
self.process.kill()
|
||||
if self._test_server_forwarder:
|
||||
self._test_server_forwarder.Close()
|
||||
self._test_server_forwarder.UnmapDevicePort(self.forwarder_device_port)
|
||||
self.process = None
|
||||
self.is_ready = False
|
||||
if self.pipe_out:
|
||||
|
|
|
@ -67,20 +67,20 @@ class Forwarder(object):
|
|||
Raises:
|
||||
Exception on failure to forward the port.
|
||||
"""
|
||||
host_adb_control_port = ports.AllocateTestServerPort()
|
||||
if not host_adb_control_port:
|
||||
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.')
|
||||
self._adb.PushIfNeeded(
|
||||
self._device_forwarder_path_on_host, Forwarder._DEVICE_FORWARDER_FOLDER)
|
||||
redirection_commands = [
|
||||
'%d:%d:%d:%s' % (host_adb_control_port, device, host,
|
||||
'%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>]')
|
||||
logging.info('Forwarding using commands: %s', redirection_commands)
|
||||
if cmd_helper.RunCmd(
|
||||
['adb', '-s', self._adb._adb.GetSerialNumber(), 'forward',
|
||||
'tcp:%s' % host_adb_control_port,
|
||||
'tcp:%s' % self._host_adb_control_port,
|
||||
'localabstract:%s' % Forwarder._DEVICE_ADB_CONTROL_PORT]) != 0:
|
||||
raise Exception('Error while running adb forward.')
|
||||
|
||||
|
@ -114,6 +114,15 @@ class Forwarder(object):
|
|||
logging.info('Forwarding device port: %d to host port: %d.', device_port,
|
||||
host_port)
|
||||
|
||||
def UnmapDevicePort(self, device_port):
|
||||
# Please note the minus sign below.
|
||||
redirection_command = '%d:-%d' % (self._host_adb_control_port, device_port)
|
||||
(exit_code, output) = cmd_helper.GetCmdStatusAndOutput(
|
||||
[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)))
|
||||
|
||||
@staticmethod
|
||||
def KillHost(build_type):
|
||||
logging.info('Killing host_forwarder.')
|
||||
|
|
Загрузка…
Ссылка в новой задаче