Skip to content

Commit 050813c

Browse files
authored
[3.13] pythongh-131032: Add support.linked_to_musl() function (python#131071) (python#131179)
pythongh-131032: Add support.linked_to_musl() function (python#131071) Skip test_math.test_fma_zero_result() if Python is linked to the musl C library. (cherry picked from commit 68922ac)
1 parent 589382b commit 050813c

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

Lib/test/support/__init__.py

+19
Original file line numberDiff line numberDiff line change
@@ -2767,3 +2767,22 @@ def __iter__(self):
27672767
if self.iter_raises:
27682768
1/0
27692769
return self
2770+
2771+
2772+
def linked_to_musl():
2773+
"""
2774+
Test if the Python executable is linked to the musl C library.
2775+
"""
2776+
if sys.platform != 'linux':
2777+
return False
2778+
2779+
import subprocess
2780+
exe = getattr(sys, '_base_executable', sys.executable)
2781+
cmd = ['ldd', exe]
2782+
try:
2783+
stdout = subprocess.check_output(cmd,
2784+
text=True,
2785+
stderr=subprocess.STDOUT)
2786+
except (OSError, subprocess.CalledProcessError):
2787+
return False
2788+
return ('musl' in stdout)

Lib/test/test_math.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2712,8 +2712,9 @@ def test_fma_infinities(self):
27122712
# gh-73468: On some platforms, libc fma() doesn't implement IEE 754-2008
27132713
# properly: it doesn't use the right sign when the result is zero.
27142714
@unittest.skipIf(
2715-
sys.platform.startswith(("freebsd", "wasi", "netbsd"))
2716-
or (sys.platform == "android" and platform.machine() == "x86_64"),
2715+
sys.platform.startswith(("freebsd", "wasi", "netbsd", "emscripten"))
2716+
or (sys.platform == "android" and platform.machine() == "x86_64")
2717+
or support.linked_to_musl(), # gh-131032
27172718
f"this platform doesn't implement IEE 754-2008 properly")
27182719
def test_fma_zero_result(self):
27192720
nonnegative_finites = [0.0, 1e-300, 2.3, 1e300]

Lib/test/test_support.py

+4
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,10 @@ def test_copy_python_src_ignore(self):
733733
self.assertEqual(support.copy_python_src_ignore(path, os.listdir(path)),
734734
ignored)
735735

736+
def test_linked_to_musl(self):
737+
linked = support.linked_to_musl()
738+
self.assertIsInstance(linked, bool)
739+
736740
# XXX -follows a list of untested API
737741
# make_legacy_pyc
738742
# is_resource_enabled

0 commit comments

Comments
 (0)