Skip to content

Commit cb48867

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 cf23b91 commit cb48867

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
@@ -142,6 +142,25 @@ def _have_socket_bluetooth():
142142
return True
143143

144144

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

167186
HAVE_SOCKET_VSOCK = _have_socket_vsock()
168187

169-
HAVE_SOCKET_UDPLITE = hasattr(socket, "IPPROTO_UDPLITE")
188+
HAVE_SOCKET_UDPLITE = _have_udp_lite()
170189

171190
HAVE_SOCKET_BLUETOOTH = _have_socket_bluetooth()
172191

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)