8000 gh-119461: Fix ThreadedVSOCKSocketStreamTest by vstinner · Pull Request #119465 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-119461: Fix ThreadedVSOCKSocketStreamTest #119465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-119461: Fix ThreadedVSOCKSocketStreamTest
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).
  • Loading branch information
vstinner committed May 23, 2024
commit d81cb0ba9c1c1f5634a44f1105035106eb1df538
10 changes: 6 additions & 4 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ def _have_socket_qipcrtr():

def _have_socket_vsock():
"""Check whether AF_VSOCK sockets are supported on this host."""
ret = get_cid() is not None
return ret
cid = get_cid()
return (cid is not None)


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

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

def testStream(self):
Expand Down Expand Up @@ -2515,6 +2516,7 @@ def testVSOCKConstants(self):
socket.SO_VM_SOCKETS_BUFFER_MAX_SIZE
socket.VMADDR_CID_ANY
socket.VMADDR_PORT_ANY
socket.VMADDR_CID_LOCAL
socket.VMADDR_CID_HOST
socket.VM_SOCKETS_INVALID_VERSION
socket.IOCTL_VM_SOCKETS_GET_LOCAL_CID
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``socket.VMADDR_CID_LOCAL`` constant. Patch by Victor Stinner.
1 change: 1 addition & 0 deletions Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -7596,6 +7596,7 @@ socket_exec(PyObject *m)
ADD_INT_CONST(m, "SO_VM_SOCKETS_BUFFER_MAX_SIZE", 2);
ADD_INT_CONST(m, "VMADDR_CID_ANY", 0xffffffff);
ADD_INT_CONST(m, "VMADDR_PORT_ANY", 0xffffffff);
ADD_INT_CONST(m, "VMADDR_CID_LOCAL", 1);
ADD_INT_CONST(m, "VMADDR_CID_HOST", 2);
ADD_INT_CONST(m, "VM_SOCKETS_INVALID_VERSION", 0xffffffff);
ADD_INT_CONST(m, "IOCTL_VM_SOCKETS_GET_LOCAL_CID", _IO(7, 0xb9));
Expand Down
Loading
0