4343# test unicode string and carriage return
4444MSG = 'Michael Gilfix was here\u1234 \r \n ' .encode ('utf-8' )
4545
46+ VMADDR_CID_LOCAL = 1
4647VSOCKPORT = 1234
4748AIX = platform .system () == "AIX"
4849WSL = "microsoft-standard-WSL" in platform .release ()
@@ -127,8 +128,8 @@ def _have_socket_qipcrtr():
127128
128129def _have_socket_vsock ():
129130 """Check whether AF_VSOCK sockets are supported on this host."""
130- ret = get_cid () is not None
131- return ret
131+ cid = get_cid ()
132+ return ( cid is not None )
132133
133134
134135def _have_socket_bluetooth ():
@@ -471,8 +472,6 @@ def clientTearDown(self):
471472@unittest .skipIf (WSL , 'VSOCK does not work on Microsoft WSL' )
472473@unittest .skipUnless (HAVE_SOCKET_VSOCK ,
473474 'VSOCK sockets required for this test.' )
474- @unittest .skipUnless (get_cid () != 2 ,
475- "This test can only be run on a virtual guest." )
476475class ThreadedVSOCKSocketStreamTest (unittest .TestCase , ThreadableTest ):
477476
478477 def __init__ (self , methodName = 'runTest' ):
@@ -494,10 +493,16 @@ def clientSetUp(self):
494493 self .cli = socket .socket (socket .AF_VSOCK , socket .SOCK_STREAM )
495494 self .addCleanup (self .cli .close )
496495 cid = get_cid ()
496+ if cid in (socket .VMADDR_CID_HOST , socket .VMADDR_CID_ANY ):
497+ # gh-119461: Use the local communication address (loopback)
498+ cid = VMADDR_CID_LOCAL
497499 self .cli .connect ((cid , VSOCKPORT ))
498500
499501 def testStream (self ):
500- msg = self .conn .recv (1024 )
502+ try :
503+ msg = self .conn .recv (1024 )
504+ except PermissionError as exc :
505+ self .skipTest (repr (exc ))
501506 self .assertEqual (msg , MSG )
502507
503508 def _testStream (self ):
0 commit comments