aboutsummaryrefslogtreecommitdiff
path: root/test_adb.py
diff options
context:
space:
mode:
authorCallum Ryan <callumryan@fb.com>2019-10-31 07:21:42 -0700
committerCallum Ryan <callumryan@fb.com>2019-11-07 08:32:01 -0800
commit04efea3af004065455be580679842f99c8eed30b (patch)
treeb2eee130277ab8794224d40d36373a076bd4877b /test_adb.py
parentae3f96d5c37cd7bd936497a90641ee5332fa3515 (diff)
downloadadb-04efea3af004065455be580679842f99c8eed30b.tar.gz
Allow the adb server to bind on ::1
Currently the adb server can only bind on 127.0.0.1 or * if -a is provided. This diff adds the ability for adb to bind on ::1 as well for use cases where you might want to force adb to be IPv6 only. To bind the adb server on ::1 ``` $ ./adb -L tcp:[::1]:1234 server $ lsof -nPi :1234 COMMAND ... NODE NAME adb ... TCP [::1]:1234 (LISTEN) ``` The original behaviour is also retained, so this would only affect users explicitly specifying ::1 in the socket spec ``` $ export ANDROID_ADB_SERVER_PORT=1234 $ ./adb server $ lsof -nPi :1234 COMMAND ... NODE NAME adb ... TCP 127.0.0.1:1234 (LISTEN) ``` Note: I've only implemented this behaviour for posix base systems, due to my limited understanding of networking on windows. If needed I can do some research to implement it there as well, but there is currently no IPv6 support at all on the windows side. Test: New unit test and the commands in the summary Change-Id: I23e4531e8dfda4de9348124ad7491d728aecdbf7
Diffstat (limited to 'test_adb.py')
-rwxr-xr-xtest_adb.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/test_adb.py b/test_adb.py
index 8272722e..3d6de266 100755
--- a/test_adb.py
+++ b/test_adb.py
@@ -281,6 +281,37 @@ class ServerTest(unittest.TestCase):
subprocess.check_output(["adb", "-P", str(port), "kill-server"],
stderr=subprocess.STDOUT)
+ @unittest.skipUnless(
+ os.name == "posix",
+ "adb doesn't yet support IPv6 on Windows",
+ )
+ def test_starts_on_ipv6_localhost(self):
+ """
+ Tests that the server can start up on ::1 and that it's accessible
+ """
+ server_port = 5037
+ # Kill any existing server on this non-default port.
+ subprocess.check_output(
+ ["adb", "-P", str(server_port), "kill-server"],
+ stderr=subprocess.STDOUT,
+ )
+ try:
+ subprocess.check_output(
+ ["adb", "-L", "tcp:[::1]:{}".format(server_port), "server"],
+ stderr=subprocess.STDOUT,
+ )
+ with fake_adbd() as (port, _):
+ with adb_connect(self, serial="localhost:{}".format(port)):
+ pass
+ finally:
+ # If we started a server, kill it.
+ subprocess.check_output(
+ ["adb", "-P", str(server_port), "kill-server"],
+ stderr=subprocess.STDOUT,
+ )
+
+
+
class EmulatorTest(unittest.TestCase):
"""Tests for the emulator connection."""