Skip to content

Commit e5fb458

Browse files
miss-islingtonvstinner
authored andcommitted
00438: Fix ThreadedVSOCKSocketStreamTest (pythonGH-119465) (pythonGH-119479) (python#119484)
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 c750061) Co-authored-by: Victor Stinner <[email protected]> (cherry picked from commit e94dbe4) Co-authored-by: Victor Stinner <[email protected]>
1 parent 128192c commit e5fb458

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
@@ -39,6 +39,7 @@
3939
# test unicode string and carriage return
4040
MSG = 'Michael Gilfix was here\u1234\r\n'.encode('utf-8')
4141

42+
VMADDR_CID_LOCAL = 1
4243
VSOCKPORT = 1234
4344
AIX = platform.system() == "AIX"
4445

@@ -122,8 +123,8 @@ def _have_socket_qipcrtr():
122123

123124
def _have_socket_vsock():
124125
"""Check whether AF_VSOCK sockets are supported on this host."""
125-
ret = get_cid() is not None
126-
return ret
126+
cid = get_cid()
127+
return (cid is not None)
127128

128129

129130
def _have_socket_bluetooth():
@@ -485,8 +486,6 @@ def clientTearDown(self):
485486
@unittest.skipIf(fcntl is None, "need fcntl")
486487
@unittest.skipUnless(HAVE_SOCKET_VSOCK,
487488
'VSOCK sockets required for this test.')
488-
@unittest.skipUnless(get_cid() != 2,
489-
"This test can only be run on a virtual guest.")
490489
class ThreadedVSOCKSocketStreamTest(unittest.TestCase, ThreadableTest):
491490

492491
def __init__(self, methodName='runTest'):
@@ -507,6 +506,9 @@ def clientSetUp(self):
507506
self.cli = socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)
508507
self.addCleanup(self.cli.close)
509508
cid = get_cid()
509+
if cid in (socket.VMADDR_CID_HOST, socket.VMADDR_CID_ANY):
510+
# gh-119461: Use the local communication address (loopback)
511+
cid = VMADDR_CID_LOCAL
510512
self.cli.connect((cid, VSOCKPORT))
511513

512514
def testStream(self):

0 commit comments

Comments
 (0)