Skip to content

Commit 3cfc249

Browse files
authored
gh-149776: Skip UDP Lite tests if it's not supported (#149777)
Fix test_socket on Linux kernel 7.1 and newer: skip UDP Lite tests if it's not supported.
1 parent 6304eb1 commit 3cfc249

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

Lib/test/test_socket.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,25 @@ def _have_socket_hyperv():
205205
return True
206206

207207

208+
def _have_udp_lite():
209+
if not hasattr(socket, "IPPROTO_UDPLITE"):
210+
return False
211+
# Older Android versions block UDPLITE with SELinux.
212+
if support.is_android and platform.android_ver().api_level < 29:
213+
return False
214+
215+
try:
216+
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDPLITE)
217+
except OSError as exc:
218+
# Linux 7.1 removed UDP Lite support
219+
if exc.errno == errno.EPROTONOSUPPORT:
220+
return False
221+
raise
222+
sock.close()
223+
224+
return True
225+
226+
208227
@contextlib.contextmanager
209228
def socket_setdefaulttimeout(timeout):
210229
old_timeout = socket.getdefaulttimeout()
@@ -247,10 +266,7 @@ def downgrade_malformed_data_warning():
247266

248267
HAVE_SOCKET_VSOCK = _have_socket_vsock()
249268

250-
# Older Android versions block UDPLITE with SELinux.
251-
HAVE_SOCKET_UDPLITE = (
252-
hasattr(socket, "IPPROTO_UDPLITE")
253-
and not (support.is_android and platform.android_ver().api_level < 29))
269+
HAVE_SOCKET_UDPLITE = _have_udp_lite()
254270

255271
HAVE_SOCKET_BLUETOOTH = _have_socket_bluetooth()
256272

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)