https://github.com/python/cpython/commit/68922ace4dabb6635e6d5b51bbe6485ef2e9dad2
commit: 68922ace4dabb6635e6d5b51bbe6485ef2e9dad2
branch: main
author: Victor Stinner <vstin...@python.org>
committer: vstinner <vstin...@python.org>
date: 2025-03-13T10:33:46+01:00
summary:

gh-131032: Add support.linked_to_musl() function (#131071)

Skip test_math.test_fma_zero_result() if Python is linked to the musl
C library.

files:
M Lib/test/support/__init__.py
M Lib/test/test_math.py
M Lib/test/test_support.py

diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 37a69fda8ef74c..b9ccf7bb4c67de 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -3015,3 +3015,22 @@ def is_libssl_fips_mode():
     except ImportError:
         return False  # more of a maybe, unless we add this to the _ssl module.
     return get_fips_mode() != 0
+
+
+def linked_to_musl():
+    """
+    Test if the Python executable is linked to the musl C library.
+    """
+    if sys.platform != 'linux':
+        return False
+
+    import subprocess
+    exe = getattr(sys, '_base_executable', sys.executable)
+    cmd = ['ldd', exe]
+    try:
+        stdout = subprocess.check_output(cmd,
+                                         text=True,
+                                         stderr=subprocess.STDOUT)
+    except (OSError, subprocess.CalledProcessError):
+        return False
+    return ('musl' in stdout)
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py
index ba94a29800c871..2649be86e5086e 100644
--- a/Lib/test/test_math.py
+++ b/Lib/test/test_math.py
@@ -2769,7 +2769,8 @@ def test_fma_infinities(self):
     # properly: it doesn't use the right sign when the result is zero.
     @unittest.skipIf(
         sys.platform.startswith(("freebsd", "wasi", "netbsd", "emscripten"))
-        or (sys.platform == "android" and platform.machine() == "x86_64"),
+        or (sys.platform == "android" and platform.machine() == "x86_64")
+        or support.linked_to_musl(),  # gh-131032
         f"this platform doesn't implement IEE 754-2008 properly")
     def test_fma_zero_result(self):
         nonnegative_finites = [0.0, 1e-300, 2.3, 1e300]
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index d900db546ada8d..46d796379fa212 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -744,6 +744,10 @@ def test_get_signal_name(self):
             self.assertEqual(support.get_signal_name(exitcode), expected,
                              exitcode)
 
+    def test_linked_to_musl(self):
+        linked = support.linked_to_musl()
+        self.assertIsInstance(linked, bool)
+
     # XXX -follows a list of untested API
     # make_legacy_pyc
     # is_resource_enabled

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to