https://github.com/python/cpython/commit/1d5fa349d7cc9884c76a0dce3818419cad494e19 commit: 1d5fa349d7cc9884c76a0dce3818419cad494e19 branch: 3.10 author: Miss Islington (bot) <[email protected]> committer: pablogsal <[email protected]> date: 2026-08-13T01:29:57+01:00 summary:
[3.10] gh-145548: Use VMADDR_CID_LOCAL in VSOCK socket tests (GH-145589) (GH-145809) (#148617) [3.12] gh-145548: Use VMADDR_CID_LOCAL in VSOCK socket tests (GH-145589) (GH-145809) * [3.12] gh-145548: Use VMADDR_CID_LOCAL in VSOCK socket tests (GH-145589) (GH-145594) 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. (cherry picked from commit 6c8c72f7feb4207c62ac857443943e61977d6a94) (cherry picked from commit 16dbbe5) * [3.13] gh-145548: Don't use VMADDR_CID_LOCAL from `socket` (GH-145735) VMADDR_CID_LOCAL was added to `socekt` in 3.14. The test needs a local constant in setUp(), as in clientSetUp(). (cherry picked from commit e378eda980ff786eb2211738aac0b6f76da88f91) Co-authored-by: Petr Viktorin <[email protected]> Co-authored-by: Victor Stinner <[email protected]> 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 eef34f081218112..45c51d46e3c8762 100644 --- a/Lib/test/pythoninfo.py +++ b/Lib/test/pythoninfo.py @@ -654,6 +654,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_test_support(info_add): try: diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index e472e807a0ab3d5..6511da8151c56a7 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -507,8 +507,8 @@ def clientTearDown(self): @unittest.skipIf(fcntl is None, "need fcntl") @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'): @@ -518,7 +518,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 = 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.conn, self.connaddr = self.serv.accept() _______________________________________________ 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]
