Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e94dbe4

Browse filesBrowse files
authored
gh-119461: Fix ThreadedVSOCKSocketStreamTest (#119465)
Add socket.VMADDR_CID_LOCAL constant. 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).
1 parent be1dfcc commit e94dbe4
Copy full SHA for e94dbe4

File tree

3 files changed

+8
-4
lines changed
Filter options

3 files changed

+8
-4
lines changed

‎Lib/test/test_socket.py

Copy file name to clipboardExpand all lines: Lib/test/test_socket.py
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ def _have_socket_qipcrtr():
160160

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

166166

167167
def _have_socket_bluetooth():
@@ -520,8 +520,6 @@ def clientTearDown(self):
520520
@unittest.skipIf(WSL, 'VSOCK does not work on Microsoft WSL')
521521
@unittest.skipUnless(HAVE_SOCKET_VSOCK,
522522
'VSOCK sockets required for this test.')
523-
@unittest.skipUnless(get_cid() != 2,
524-
"This test can only be run on a virtual guest.")
525523
class ThreadedVSOCKSocketStreamTest(unittest.TestCase, ThreadableTest):
526524

527525
def __init__(self, methodName='runTest'):
@@ -543,6 +541,9 @@ def clientSetUp(self):
543541
self.cli = socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)
544542
self.addCleanup(self.cli.close)
545543
cid = get_cid()
544+
if cid in (socket.VMADDR_CID_HOST, socket.VMADDR_CID_ANY):
545+
# gh-119461: Use the local communication address (loopback)
546+
cid = socket.VMADDR_CID_LOCAL
546547
self.cli.connect((cid, VSOCKPORT))
547548

548549
def testStream(self):
@@ -2515,6 +2516,7 @@ def testVSOCKConstants(self):
25152516
socket.SO_VM_SOCKETS_BUFFER_MAX_SIZE
25162517
socket.VMADDR_CID_ANY
25172518
socket.VMADDR_PORT_ANY
2519+
socket.VMADDR_CID_LOCAL
25182520
socket.VMADDR_CID_HOST
25192521
socket.VM_SOCKETS_INVALID_VERSION
25202522
socket.IOCTL_VM_SOCKETS_GET_LOCAL_CID
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ``socket.VMADDR_CID_LOCAL`` constant. Patch by Victor Stinner.

‎Modules/socketmodule.c

Copy file name to clipboardExpand all lines: Modules/socketmodule.c
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7596,6 +7596,7 @@ socket_exec(PyObject *m)
75967596
ADD_INT_CONST(m, "SO_VM_SOCKETS_BUFFER_MAX_SIZE", 2);
75977597
ADD_INT_CONST(m, "VMADDR_CID_ANY", 0xffffffff);
75987598
ADD_INT_CONST(m, "VMADDR_PORT_ANY", 0xffffffff);
7599+
ADD_INT_CONST(m, "VMADDR_CID_LOCAL", 1);
75997600
ADD_INT_CONST(m, "VMADDR_CID_HOST", 2);
76007601
ADD_INT_CONST(m, "VM_SOCKETS_INVALID_VERSION", 0xffffffff);
76017602
ADD_INT_CONST(m, "IOCTL_VM_SOCKETS_GET_LOCAL_CID", _IO(7, 0xb9));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.