Skip to content

Commit c971cb3

Browse files
vstinnerhroncok
authored andcommitted
00491: pythongh-149776: Skip UDP Lite tests if it's not supported
Fix test_socket on Linux kernel 7.1 and newer: skip UDP Lite tests if it's not supported. (cherry picked from commit 3cfc249) (cherry picked from commit 49d0867)
1 parent e4380e0 commit c971cb3

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎Lib/test/test_socket.py‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,26 @@ def _have_socket_bluetooth():
145145
return True
146146

147147

148+
def _have_udp_lite():
149+
if not hasattr(socket, "IPPROTO_UDPLITE"):
150+
return False
151+
# Older Android versions block UDPLITE with SELinux.
152+
if support.is_android and platform.android_ver().api_level < 29:
153+
return False
154+
155+
try:
156+
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDPLITE)
157+
except OSError as exc:
158+
# Linux 7.1 removed UDP Lite support
159+
if exc.errno == errno.EPROTONOSUPPORT:
160+
return False
161+
raise
162+
sock.close()
163+
164+
return True
165+
166+
167+
148168
@contextlib.contextmanager
149169
def socket_setdefaulttimeout(timeout):
150170
old_timeout = socket.getdefaulttimeout()
@@ -169,7 +189,7 @@ def socket_setdefaulttimeout(timeout):
169189

170190
HAVE_SOCKET_VSOCK = _have_socket_vsock()
171191

172-
HAVE_SOCKET_UDPLITE = hasattr(socket, "IPPROTO_UDPLITE")
192+
HAVE_SOCKET_UDPLITE = _have_udp_lite()
173193

174194
HAVE_SOCKET_BLUETOOTH = _have_socket_bluetooth()
175195

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix test_socket on Linux kernel 7.1 and newer: skip UDP Lite tests if it's
2+
not supported. Patch by Victor Stinner.

0 commit comments

Comments
 (0)