summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_socket.py
diff options
context:
space:
mode:
authorBjorn Andersson <bjorn@kryo.se>2018-09-26 13:47:52 (GMT)
committerTal Einat <taleinat+github@gmail.com>2018-09-26 13:47:52 (GMT)
commitbb8165172ac2ef8c7092e8e82928cc7f5f310ab3 (patch)
tree7674fc11d7cbb19a938d05e4a95d8e56446fb274 /Lib/test/test_socket.py
parent2aaf98c16ae3070378de523a173e29644037d8bd (diff)
downloadcpython-bb8165172ac2ef8c7092e8e82928cc7f5f310ab3.zip
cpython-bb8165172ac2ef8c7092e8e82928cc7f5f310ab3.tar.gz
cpython-bb8165172ac2ef8c7092e8e82928cc7f5f310ab3.tar.bz2
bpo-31425: Expose AF_QIPCRTR in socket module (GH-3706)
The AF_QIPCRTR address family was introduced in Linux v4.7. Co-authored-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r--Lib/test/test_socket.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index bd4fad1..bbbf27b 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -94,6 +94,16 @@ def _have_socket_alg():
s.close()
return True
+def _have_socket_qipcrtr():
+ """Check whether AF_QIPCRTR sockets are supported on this host."""
+ try:
+ s = socket.socket(socket.AF_QIPCRTR, socket.SOCK_DGRAM, 0)
+ except (AttributeError, OSError):
+ return False
+ else:
+ s.close()
+ return True
+
def _have_socket_vsock():
"""Check whether AF_VSOCK sockets are supported on this host."""
ret = get_cid() is not None
@@ -113,6 +123,8 @@ HAVE_SOCKET_RDS = _have_socket_rds()
HAVE_SOCKET_ALG = _have_socket_alg()
+HAVE_SOCKET_QIPCRTR = _have_socket_qipcrtr()
+
HAVE_SOCKET_VSOCK = _have_socket_vsock()
# Size in bytes of the int type
@@ -2054,6 +2066,34 @@ class RDSTest(ThreadedRDSSocketTest):
self.data = b'select'
self.cli.sendto(self.data, 0, (HOST, self.port))
+@unittest.skipUnless(HAVE_SOCKET_QIPCRTR,
+ 'QIPCRTR sockets required for this test.')
+class BasicQIPCRTRTest(unittest.TestCase):
+
+ def testCrucialConstants(self):
+ socket.AF_QIPCRTR
+
+ def testCreateSocket(self):
+ with socket.socket(socket.AF_QIPCRTR, socket.SOCK_DGRAM) as s:
+ pass
+
+ def testUnbound(self):
+ with socket.socket(socket.AF_QIPCRTR, socket.SOCK_DGRAM) as s:
+ self.assertEqual(s.getsockname()[1], 0)
+
+ def testBindSock(self):
+ with socket.socket(socket.AF_QIPCRTR, socket.SOCK_DGRAM) as s:
+ support.bind_port(s, host=s.getsockname()[0])
+ self.assertNotEqual(s.getsockname()[1], 0)
+
+ def testInvalidBindSock(self):
+ with socket.socket(socket.AF_QIPCRTR, socket.SOCK_DGRAM) as s:
+ self.assertRaises(OSError, support.bind_port, s, host=-2)
+
+ def testAutoBindSock(self):
+ with socket.socket(socket.AF_QIPCRTR, socket.SOCK_DGRAM) as s:
+ s.connect((123, 123))
+ self.assertNotEqual(s.getsockname()[1], 0)
@unittest.skipIf(fcntl is None, "need fcntl")
@unittest.skipUnless(HAVE_SOCKET_VSOCK,
@@ -5978,6 +6018,7 @@ def test_main():
tests.extend([BasicCANTest, CANTest])
tests.extend([BasicRDSTest, RDSTest])
tests.append(LinuxKernelCryptoAPI)
+ tests.append(BasicQIPCRTRTest)
tests.extend([
BasicVSOCKTest,
ThreadedVSOCKSocketStreamTest,