summaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorjrg@google.com <jrg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-13 06:50:01 +0000
committerjrg@google.com <jrg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-13 06:50:01 +0000
commit776e7a7408eeb8dff10e1b22c9673be700892903 (patch)
treee393cf3964891f844edbe9651522072460040507 /build
parentbc073c0623414e6b869a5d83dff00341e1fd4c39 (diff)
downloadchromium_src-776e7a7408eeb8dff10e1b22c9673be700892903.zip
chromium_src-776e7a7408eeb8dff10e1b22c9673be700892903.tar.gz
chromium_src-776e7a7408eeb8dff10e1b22c9673be700892903.tar.bz2
Cycle through port pools for Android emulator.
BUG=None TEST= Review URL: http://codereview.chromium.org/9194006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117616 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build')
-rwxr-xr-xbuild/android/emulator.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/build/android/emulator.py b/build/android/emulator.py
index 07f64bb..5abfadc 100755
--- a/build/android/emulator.py
+++ b/build/android/emulator.py
@@ -50,14 +50,34 @@ def _KillAllEmulators():
return
time.sleep(1)
+
+class PortPool(object):
+ """Pool for emulator port starting position that changes over time."""
+ _port_min = 5554
+ _port_max = 5585
+ _port_current_index = 0
+
+ @classmethod
+ def port_range(cls):
+ """Return a range of valid ports for emulator use.
+
+ The port must be an even number between 5554 and 5584. Sometimes
+ a killed emulator "hangs on" to a port long enough to prevent
+ relaunch. This is especially true on slow machines (like a bot).
+ Cycling through a port start position helps make us resilient."""
+ ports = range(cls._port_min, cls._port_max, 2)
+ n = cls._port_current_index
+ cls._port_current_index = (n + 1) % len(ports)
+ return ports[n:] + ports[:n]
+
+
def _GetAvailablePort():
"""Returns an available TCP port for the console."""
used_ports = []
emulators = android_commands.GetEmulators()
for emulator in emulators:
used_ports.append(emulator.split('-')[1])
- # The port must be an even number between 5554 and 5584.
- for port in range(5554, 5585, 2):
+ for port in PortPool.port_range():
if str(port) not in used_ports:
return port