Skip to content

Commit 2dedb4c

Browse files
[3.14] gh-149776: Skip UDP Lite tests if it's not supported (GH-149777) (#149781)
gh-149776: Skip UDP Lite tests if it's not supported (GH-149777) Fix test_socket on Linux kernel 7.1 and newer: skip UDP Lite tests if it's not supported. (cherry picked from commit 3cfc249) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent bb5a81a commit 2dedb4c

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
@@ -203,6 +203,25 @@ def _have_socket_hyperv():
203203
return True
204204

205205

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

246265
HAVE_SOCKET_VSOCK = _have_socket_vsock()
247266

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

253269
HAVE_SOCKET_BLUETOOTH = _have_socket_bluetooth()
254270

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)