mirror of
https://github.com/python/cpython.git
synced 2026-06-29 04:10:54 +00:00
[3.13] gh-145548: Use VMADDR_CID_LOCAL in VSOCK socket tests (GH-145589) (#145594)
gh-145548: Use VMADDR_CID_LOCAL in VSOCK socket tests (GH-145589)
Prefer VMADDR_CID_LOCAL instead of VMADDR_CID_ANY for bind() in the
server. Skip the test if bind() fails with EADDRNOTAVAIL.
Log vsock CID in test.pythoninfo.
(cherry picked from commit 6c8c72f7fe)
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
5db017755b
commit
16dbbe56f0
2 changed files with 16 additions and 3 deletions
|
|
@ -738,6 +738,10 @@ def collect_test_socket(info_add):
|
||||||
if name.startswith('HAVE_')]
|
if name.startswith('HAVE_')]
|
||||||
copy_attributes(info_add, test_socket, 'test_socket.%s', attributes)
|
copy_attributes(info_add, test_socket, 'test_socket.%s', attributes)
|
||||||
|
|
||||||
|
# Get IOCTL_VM_SOCKETS_GET_LOCAL_CID of /dev/vsock
|
||||||
|
cid = test_socket.get_cid()
|
||||||
|
info_add('test_socket.get_cid', cid)
|
||||||
|
|
||||||
|
|
||||||
def collect_support(info_add):
|
def collect_support(info_add):
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -555,8 +555,8 @@ def clientTearDown(self):
|
||||||
@unittest.skipIf(WSL, 'VSOCK does not work on Microsoft WSL')
|
@unittest.skipIf(WSL, 'VSOCK does not work on Microsoft WSL')
|
||||||
@unittest.skipUnless(HAVE_SOCKET_VSOCK,
|
@unittest.skipUnless(HAVE_SOCKET_VSOCK,
|
||||||
'VSOCK sockets required for this test.')
|
'VSOCK sockets required for this test.')
|
||||||
@unittest.skipUnless(get_cid() != 2, # VMADDR_CID_HOST
|
@unittest.skipIf(get_cid() == getattr(socket, 'VMADDR_CID_HOST', 2),
|
||||||
"This test can only be run on a virtual guest.")
|
"This test can only be run on a virtual guest.")
|
||||||
class ThreadedVSOCKSocketStreamTest(unittest.TestCase, ThreadableTest):
|
class ThreadedVSOCKSocketStreamTest(unittest.TestCase, ThreadableTest):
|
||||||
|
|
||||||
def __init__(self, methodName='runTest'):
|
def __init__(self, methodName='runTest'):
|
||||||
|
|
@ -566,7 +566,16 @@ def __init__(self, methodName='runTest'):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.serv = socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)
|
self.serv = socket.socket(socket.AF_VSOCK, socket.SOCK_STREAM)
|
||||||
self.addCleanup(self.serv.close)
|
self.addCleanup(self.serv.close)
|
||||||
self.serv.bind((socket.VMADDR_CID_ANY, VSOCKPORT))
|
cid = get_cid()
|
||||||
|
if cid in (socket.VMADDR_CID_HOST, socket.VMADDR_CID_ANY):
|
||||||
|
cid = socket.VMADDR_CID_LOCAL
|
||||||
|
try:
|
||||||
|
self.serv.bind((cid, VSOCKPORT))
|
||||||
|
except OSError as exc:
|
||||||
|
if exc.errno == errno.EADDRNOTAVAIL:
|
||||||
|
self.skipTest(f"bind() failed with {exc!r}")
|
||||||
|
else:
|
||||||
|
raise
|
||||||
self.serv.listen()
|
self.serv.listen()
|
||||||
self.serverExplicitReady()
|
self.serverExplicitReady()
|
||||||
self.serv.settimeout(support.LOOPBACK_TIMEOUT)
|
self.serv.settimeout(support.LOOPBACK_TIMEOUT)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue