https://github.com/python/cpython/commit/6c8c72f7feb4207c62ac857443943e61977d6a94
commit: 6c8c72f7feb4207c62ac857443943e61977d6a94
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-03-06T16:51:36+01:00
summary:
gh-145548: Use VMADDR_CID_LOCAL in VSOCK socket tests (#145589)
Prefer VMADDR_CID_LOCAL instead of VMADDR_CID_ANY for bind() in the
server. Skip the test if bind() fails with EADDRNOTAVAIL.
Log vsock CID in test.pythoninfo.
files:
M Lib/test/pythoninfo.py
M Lib/test/test_socket.py
diff --git a/Lib/test/pythoninfo.py b/Lib/test/pythoninfo.py
index 6df59946574a17..219fbb4bb1bbe2 100644
--- a/Lib/test/pythoninfo.py
+++ b/Lib/test/pythoninfo.py
@@ -751,6 +751,10 @@ def collect_test_socket(info_add):
if name.startswith('HAVE_')]
copy_attributes(info_add, test_socket, 'test_socket.%s', attributes)
+ # Get IOCTL_VM_SOCKETS_GET_LOCAL_CID of /dev/vsock
+ cid = test_socket.get_cid()
+ info_add('test_socket.get_cid', cid)
+
def collect_support(info_add):
try:
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 9ad5b29ea58ecb..9e03069494345b 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -563,8 +563,8 @@ def clientTearDown(self):
@unittest.skipIf(WSL, 'VSOCK does not work on Microsoft WSL')
@unittest.skipUnless(HAVE_SOCKET_VSOCK,
'VSOCK sockets required for this test.')
[email protected](get_cid() != 2, # VMADDR_CID_HOST
- "This test can only be run on a virtual guest.")
[email protected](get_cid() == getattr(socket, 'VMADDR_CID_HOST', 2),
+ "This test can only be run on a virtual guest.")
class ThreadedVSOCKSocketStreamTest(unittest.TestCase, ThreadableTest):
def __init__(self, methodName='runTest'):
@@ -574,7 +574,16 @@ def __init__(self, methodName='runTest'):
def setUp(self):
self.serv = socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)
self.addCleanup(self.serv.close)
- self.serv.bind((socket.VMADDR_CID_ANY, VSOCKPORT))
+ cid = get_cid()
+ if cid in (socket.VMADDR_CID_HOST, socket.VMADDR_CID_ANY):
+ cid = socket.VMADDR_CID_LOCAL
+ try:
+ self.serv.bind((cid, VSOCKPORT))
+ except OSError as exc:
+ if exc.errno == errno.EADDRNOTAVAIL:
+ self.skipTest(f"bind() failed with {exc!r}")
+ else:
+ raise
self.serv.listen()
self.serverExplicitReady()
self.serv.settimeout(support.LOOPBACK_TIMEOUT)
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]