Skip to content

Commit 67d79df

Browse files
authored
[3.11] gh-149776: Skip UDP Lite tests if it's not supported (#149777) (#153593)
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 5f13018 commit 67d79df

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
@@ -145,6 +145,25 @@ 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+
148167
@contextlib.contextmanager
149168
def socket_setdefaulttimeout(timeout):
150169
old_timeout = socket.getdefaulttimeout()
@@ -169,7 +188,7 @@ def socket_setdefaulttimeout(timeout):
169188

170189
HAVE_SOCKET_VSOCK = _have_socket_vsock()
171190

172-
HAVE_SOCKET_UDPLITE = hasattr(socket, "IPPROTO_UDPLITE")
191+
HAVE_SOCKET_UDPLITE = _have_udp_lite()
173192

174193
HAVE_SOCKET_BLUETOOTH = _have_socket_bluetooth()
175194

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)