Skip to content

Commit 68922ac

Browse files
authored
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.
1 parent 2ed671b commit 68922ac

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

Lib/test/support/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3015,3 +3015,22 @@ def is_libssl_fips_mode():
30153015
except ImportError:
30163016
return False # more of a maybe, unless we add this to the _ssl module.
30173017
return get_fips_mode() != 0
3018+
3019+
3020+
def linked_to_musl():
3021+
"""
3022+
Test if the Python executable is linked to the musl C library.
3023+
"""
3024+
if sys.platform != 'linux':
3025+
return False
3026+
3027+
import subprocess
3028+
exe = getattr(sys, '_base_executable', sys.executable)
3029+
cmd = ['ldd', exe]
3030+
try:
3031+
stdout = subprocess.check_output(cmd,
3032+
text=True,
3033+
stderr=subprocess.STDOUT)
3034+
except (OSError, subprocess.CalledProcessError):
3035+
return False
3036+
return ('musl' in stdout)

Lib/test/test_math.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2769,7 +2769,8 @@ def test_fma_infinities(self):
27692769
# properly: it doesn't use the right sign when the result is zero.
27702770
@unittest.skipIf(
27712771
sys.platform.startswith(("freebsd", "wasi", "netbsd", "emscripten"))
2772-
or (sys.platform == "android" and platform.machine() == "x86_64"),
2772+
or (sys.platform == "android" and platform.machine() == "x86_64")
2773+
or support.linked_to_musl(), # gh-131032
27732774
f"this platform doesn't implement IEE 754-2008 properly")
27742775
def test_fma_zero_result(self):
27752776
nonnegative_finites = [0.0, 1e-300, 2.3, 1e300]

Lib/test/test_support.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,10 @@ def test_get_signal_name(self):
744744
self.assertEqual(support.get_signal_name(exitcode), expected,
745745
exitcode)
746746

747+
def test_linked_to_musl(self):
748+
linked = support.linked_to_musl()
749+
self.assertIsInstance(linked, bool)
750+
747751
# XXX -follows a list of untested API
748752
# make_legacy_pyc
749753
# is_resource_enabled

0 commit comments

Comments
 (0)