diff options
author | pliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-12 12:46:37 +0000 |
---|---|---|
committer | pliard@chromium.org <pliard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-12 12:46:37 +0000 |
commit | 4c0871855cba62292ca55b2f7467d075247c725a (patch) | |
tree | 8b96fdf32f0c50b5e9e97e438f83921a9158dac4 /build/android/pylib/ports.py | |
parent | a756e8791d0ef190b89a80cb71c0722270f0731d (diff) | |
download | chromium_src-4c0871855cba62292ca55b2f7467d075247c725a.zip chromium_src-4c0871855cba62292ca55b2f7467d075247c725a.tar.gz chromium_src-4c0871855cba62292ca55b2f7467d075247c725a.tar.bz2 |
Support HTTP test-server based net unit tests on Android.
This changes forwarder2 to support both test-server spawner and HTTP server
forwarding.
The main issue was that the device_forwarder was killed when instantiating a
second Forwarder (Python object).
Test server based unit tests require two device-to-host redirections, one for
the test server spawner and one for the HTTP server.
The port used by the HTTP server is allocated dynamically which means that we
can't know the full forwarding configuration before we spawn a HTTP server
(through the test server spawner).
This CL changes the forwarder to let it forward new ports while it is running
by making host_forwarder a daemon. This is similar to how ADB works.
This also means that a single host_forwarder process (daemon) can now handle
multiple devices.
BUG=146979
Review URL: https://chromiumcodereview.appspot.com/11269036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167167 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build/android/pylib/ports.py')
-rw-r--r-- | build/android/pylib/ports.py | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/build/android/pylib/ports.py b/build/android/pylib/ports.py index 06b9f58..74c84c1 100644 --- a/build/android/pylib/ports.py +++ b/build/android/pylib/ports.py @@ -2,7 +2,7 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -"""Functions that deals with local and device ports.""" +"""Functions that deal with local and device ports.""" import contextlib import fcntl @@ -17,12 +17,13 @@ import cmd_helper import constants -#The following two methods are used to allocate the port source for various -# types of test servers. Because some net relates tests can be run on shards -# at same time, it's important to have a mechanism to allocate the port process -# safe. In here, we implement the safe port allocation by leveraging flock. +# The following two methods are used to allocate the port source for various +# types of test servers. Because some net-related tests can be run on shards at +# same time, it's important to have a mechanism to allocate the port +# process-safe. In here, we implement the safe port allocation by leveraging +# flock. def ResetTestServerPortAllocation(): - """Reset the port allocation to start from TEST_SERVER_PORT_FIRST. + """Resets the port allocation to start from TEST_SERVER_PORT_FIRST. Returns: Returns True if reset successes. Otherwise returns False. @@ -39,7 +40,7 @@ def ResetTestServerPortAllocation(): def AllocateTestServerPort(): - """Allocate a port incrementally. + """Allocates a port incrementally. Returns: Returns a valid port which should be in between TEST_SERVER_PORT_FIRST and @@ -90,10 +91,12 @@ def IsHostPortUsed(host_port): Returns: True if the port on host is already used, otherwise returns False. """ - port_info = '(127\.0\.0\.1)|(localhost)\:%d' % host_port - # TODO(jnd): Find a better way to filter the port. + port_info = '(\*)|(127\.0\.0\.1)|(localhost):%d' % host_port + # TODO(jnd): Find a better way to filter the port. Note that connecting to the + # socket and closing it would leave it in the TIME_WAIT state. Setting + # SO_LINGER on it and then closing it makes the Python HTTP server crash. re_port = re.compile(port_info, re.MULTILINE) - if re_port.findall(cmd_helper.GetCmdOutput(['lsof', '-nPi:%d' % host_port])): + if re_port.search(cmd_helper.GetCmdOutput(['lsof', '-nPi:%d' % host_port])): return True return False @@ -115,6 +118,11 @@ def IsDevicePortUsed(adb, device_port, state=''): for single_connect in netstat_results: # Column 3 is the local address which we want to check with. connect_results = single_connect.split() + if connect_results[0] != 'tcp': + continue + if len(connect_results) < 6: + raise Exception('Unexpected format while parsing netstat line: ' + + single_connect) is_state_match = connect_results[5] == state if state else True if connect_results[3] == base_url and is_state_match: return True |