Skip to content

Commit 1bec465

Browse files
committed
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. (cherry picked from commit 3cfc249)
1 parent 1f8a87a commit 1bec465

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

Lib/test/test_socket.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,25 @@ def _have_socket_hyperv():
157157
return True
158158

159159

160+
def _have_udp_lite():
161+
if not hasattr(socket, "IPPROTO_UDPLITE"):
162+
return False
163+
# Older Android versions block UDPLITE with SELinux.
164+
if support.is_android and platform.android_ver().api_level < 29:
165+
return False
166+
167+
try:
168+
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDPLITE)
169+
except OSError as exc:
170+
# Linux 7.1 removed UDP Lite support
171+
if exc.errno == errno.EPROTONOSUPPORT:
172+
return False
173+
raise
174+
sock.close()
175+
176+
return True
177+
178+
160179
@contextlib.contextmanager
161180
def socket_setdefaulttimeout(timeout):
162181
old_timeout = socket.getdefaulttimeout()
@@ -181,7 +200,7 @@ def socket_setdefaulttimeout(timeout):
181200

182201
HAVE_SOCKET_VSOCK = _have_socket_vsock()
183202

184-
HAVE_SOCKET_UDPLITE = hasattr(socket, "IPPROTO_UDPLITE")
203+
HAVE_SOCKET_UDPLITE = _have_udp_lite()
185204

186205
HAVE_SOCKET_BLUETOOTH = _have_socket_bluetooth()
187206

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)