Skip to content

Commit 2491831

Browse files
vstinnermiss-islington
authored andcommitted
[3.11] gh-119461: Fix ThreadedVSOCKSocketStreamTest (GH-129171)
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 45db419) Co-authored-by: Victor Stinner <[email protected]> (cherry picked from commit e94dbe4) (cherry picked from commit c750061) (cherry picked from commit cbfe302)
1 parent 10a2a9b commit 2491831

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Lib/test/test_socket.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
# test unicode string and carriage return
4242
MSG = 'Michael Gilfix was here\u1234\r\n'.encode('utf-8')
4343

44+
VMADDR_CID_LOCAL = 1
4445
VSOCKPORT = 1234
4546
AIX = platform.system() == "AIX"
4647

@@ -124,8 +125,8 @@ def _have_socket_qipcrtr():
124125

125126
def _have_socket_vsock():
126127
"""Check whether AF_VSOCK sockets are supported on this host."""
127-
ret = get_cid() is not None
128-
return ret
128+
cid = get_cid()
129+
return (cid is not None)
129130

130131

131132
def _have_socket_bluetooth():
@@ -487,8 +488,6 @@ def clientTearDown(self):
487488
@unittest.skipIf(fcntl is None, "need fcntl")
488489
@unittest.skipUnless(HAVE_SOCKET_VSOCK,
489490
'VSOCK sockets required for this test.')
490-
@unittest.skipUnless(get_cid() != 2,
491-
"This test can only be run on a virtual guest.")
492491
class ThreadedVSOCKSocketStreamTest(unittest.TestCase, ThreadableTest):
493492

494493
def __init__(self, methodName='runTest'):
@@ -509,10 +508,16 @@ def clientSetUp(self):
509508
self.cli = socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)
510509
self.addCleanup(self.cli.close)
511510
cid = get_cid()
511+
if cid in (socket.VMADDR_CID_HOST, socket.VMADDR_CID_ANY):
512+
# gh-119461: Use the local communication address (loopback)
513+
cid = VMADDR_CID_LOCAL
512514
self.cli.connect((cid, VSOCKPORT))
513515

514516
def testStream(self):
515-
msg = self.conn.recv(1024)
517+
try:
518+
msg = self.conn.recv(1024)
519+
except PermissionError as exc:
520+
self.skipTest(repr(exc))
516521
self.assertEqual(msg, MSG)
517522

518523
def _testStream(self):

0 commit comments

Comments
 (0)