]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-149776: Skip UDP Lite tests if it's not supported (GH-149777) (#149782)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 13 May 2026 15:27:56 +0000 (17:27 +0200)
committerGitHub <noreply@github.com>
Wed, 13 May 2026 15:27:56 +0000 (15:27 +0000)
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 3cfc249e11a132dc69624150843779aa96c72b2b)

Co-authored-by: Victor Stinner <vstinner@python.org>
Lib/test/test_socket.py
Misc/NEWS.d/next/Tests/2026-05-13-14-53-23.gh-issue-149776.orqgsn.rst [new file with mode: 0644]

index 8a5e85824392bc326f240e8b5b781cd00080558c..c6f6985faefd5f59d10db27c3d85bad20b3e89ff 100644 (file)
@@ -203,6 +203,25 @@ def _have_socket_hyperv():
     return True
 
 
+def _have_udp_lite():
+    if not hasattr(socket, "IPPROTO_UDPLITE"):
+        return False
+    # Older Android versions block UDPLITE with SELinux.
+    if support.is_android and platform.android_ver().api_level < 29:
+        return False
+
+    try:
+        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDPLITE)
+    except OSError as exc:
+        # Linux 7.1 removed UDP Lite support
+        if exc.errno == errno.EPROTONOSUPPORT:
+            return False
+        raise
+    sock.close()
+
+    return True
+
+
 @contextlib.contextmanager
 def socket_setdefaulttimeout(timeout):
     old_timeout = socket.getdefaulttimeout()
@@ -245,10 +264,7 @@ HAVE_SOCKET_QIPCRTR = _have_socket_qipcrtr()
 
 HAVE_SOCKET_VSOCK = _have_socket_vsock()
 
-# Older Android versions block UDPLITE with SELinux.
-HAVE_SOCKET_UDPLITE = (
-    hasattr(socket, "IPPROTO_UDPLITE")
-    and not (support.is_android and platform.android_ver().api_level < 29))
+HAVE_SOCKET_UDPLITE = _have_udp_lite()
 
 HAVE_SOCKET_BLUETOOTH = _have_socket_bluetooth()
 
diff --git a/Misc/NEWS.d/next/Tests/2026-05-13-14-53-23.gh-issue-149776.orqgsn.rst b/Misc/NEWS.d/next/Tests/2026-05-13-14-53-23.gh-issue-149776.orqgsn.rst
new file mode 100644 (file)
index 0000000..e86a913
--- /dev/null
@@ -0,0 +1,2 @@
+Fix test_socket on Linux kernel 7.1 and newer: skip UDP Lite tests if it's
+not supported. Patch by Victor Stinner.