summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej Żenczykowski <maze@google.com>2020-05-27 09:24:01 +0000
committerMaciej Zenczykowski <maze@google.com>2020-05-27 09:41:14 +0000
commita1197aaead58f2b78c829d1615833aecdc32f2c0 (patch)
tree4e89fe4575db7e202bccb2e259e84d4df9520638
parent4ce0aed14cec158294e022111bde85940bd46012 (diff)
downloadtests-a1197aaead58f2b78c829d1615833aecdc32f2c0.tar.gz
net-test: attempt to use namespaces on devices with ADB/TCPandroid-cts-11.0_r2
I'm not really sure if a test for tcp/5555 being occupied is a good test or not as a means of detecting ADB over TCP... (because what guarantees it's port 5555...) 4.14-based RVC phone (via USB): $ adb shell lsof | egrep ^adbd | egrep IP adbd 1372 root 8u IPv6 0t0 37835 TCP []:5037->[]:0 (LISTEN) 5.4 RVC cuttlefish device (via vsock:4:5555): $ adb shell lsof | egrep ^adbd | egrep IP adbd 410 root 11u IPv6 0t0 10914 TCP []:5555->[]:0 (LISTEN) Bug: 149894399 Test: a_test vts_kernel_net_tests (on rvc cuttlefish x86_64) Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I76bba37498ceccc48eb724f5357ec14eed84ae48 Merged-In: I76bba37498ceccc48eb724f5357ec14eed84ae48
-rwxr-xr-xnet/test/all_tests.py5
-rw-r--r--net/test/namespace.py17
2 files changed, 22 insertions, 0 deletions
diff --git a/net/test/all_tests.py b/net/test/all_tests.py
index 5f6c583..17d9701 100755
--- a/net/test/all_tests.py
+++ b/net/test/all_tests.py
@@ -18,6 +18,8 @@ import importlib
import sys
import unittest
+import namespace
+
test_modules = [
'anycast_test',
'bpf_test',
@@ -46,6 +48,9 @@ test_modules = [
]
if __name__ == '__main__':
+ # Check whether ADB over TCP is occupying TCP port 5555.
+ if namespace.HasEstablishedTcpSessionOnPort(5555):
+ namespace.IfPossibleEnterNewNetworkNamespace()
# First, run InjectTests on all modules, to ensure that any parameterized
# tests in those modules are injected.
for name in test_modules:
diff --git a/net/test/namespace.py b/net/test/namespace.py
index f7fbaf4..85db654 100644
--- a/net/test/namespace.py
+++ b/net/test/namespace.py
@@ -19,8 +19,11 @@
import ctypes
import ctypes.util
import os
+import socket
import net_test
+import sock_diag
+import tcp_test
# //include/linux/fs.h
MNT_FORCE = 1 # Attempt to forcibily umount
@@ -146,3 +149,17 @@ def IfPossibleEnterNewNetworkNamespace():
print 'succeeded.'
return True
+
+
+def HasEstablishedTcpSessionOnPort(port):
+ sd = sock_diag.SockDiag()
+
+ sock_id = sd._EmptyInetDiagSockId()
+ sock_id.sport = port
+
+ states = 1 << tcp_test.TCP_ESTABLISHED
+
+ matches = sd.DumpAllInetSockets(socket.IPPROTO_TCP, "",
+ sock_id=sock_id, states=states)
+
+ return len(matches) > 0