Skip to content

Commit c750061

Browse files
authored
[3.13] gh-119461: Fix ThreadedVSOCKSocketStreamTest (#119465) (#119479)
gh-119461: Fix ThreadedVSOCKSocketStreamTest (#119465) Fix ThreadedVSOCKSocketStreamTest: if get_cid() returns the host address or the "any" address, use the local communication address (loopback): VMADDR_CID_LOCAL. On Linux 6.9, apparently, the /dev/vsock device is now available but get_cid() returns VMADDR_CID_ANY (-1). (cherry picked from commit e94dbe4)
1 parent d98d6b1 commit c750061

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Lib/test/test_socket.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
# test unicode string and carriage return
4848
MSG = 'Michael Gilfix was here\u1234\r\n'.encode('utf-8')
4949

50+
VMADDR_CID_LOCAL = 1
5051
VSOCKPORT = 1234
5152
AIX = platform.system() == "AIX"
5253
WSL = "microsoft-standard-WSL" in platform.release()
@@ -160,8 +161,8 @@ def _have_socket_qipcrtr():
160161

161162
def _have_socket_vsock():
162163
"""Check whether AF_VSOCK sockets are supported on this host."""
163-
ret = get_cid() is not None
164-
return ret
164+
cid = get_cid()
165+
return (cid is not None)
165166

166167

167168
def _have_socket_bluetooth():
@@ -520,8 +521,6 @@ def clientTearDown(self):
520521
@unittest.skipIf(WSL, 'VSOCK does not work on Microsoft WSL')
521522
@unittest.skipUnless(HAVE_SOCKET_VSOCK,
522523
'VSOCK sockets required for this test.')
523-
@unittest.skipUnless(get_cid() != 2,
524-
"This test can only be run on a virtual guest.")
525524
class ThreadedVSOCKSocketStreamTest(unittest.TestCase, ThreadableTest):
526525

527526
def __init__(self, methodName='runTest'):
@@ -543,6 +542,9 @@ def clientSetUp(self):
543542
self.cli = socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)
544543
self.addCleanup(self.cli.close)
545544
cid = get_cid()
545+
if cid in (socket.VMADDR_CID_HOST, socket.VMADDR_CID_ANY):
546+
# gh-119461: Use the local communication address (loopback)
547+
cid = VMADDR_CID_LOCAL
546548
self.cli.connect((cid, VSOCKPORT))
547549

548550
def testStream(self):

0 commit comments

Comments
 (0)