https://github.com/python/cpython/commit/dc4adb090a236df4c94dc77ad4aab9ec7554f4b9
commit: dc4adb090a236df4c94dc77ad4aab9ec7554f4b9
branch: 3.15
author: Miss Islington (bot) <[email protected]>
committer: vstinner <[email protected]>
date: 2026-10-17T02:54:35+02:00
summary:

[3.15] gh-98894: Fix test_dtrace on Solaris (GH-154803) (#159602)

gh-98894: Fix test_dtrace on Solaris (GH-154803)

Fix 'CheckDtraceProbes' tests by reading available probes from the test process 
itself.
(cherry picked from commit 967fb3afc7e2f706d757925e9346f0bc8aab3c46)

Co-authored-by: Jakub KulĂ­k <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>

files:
M Lib/test/test_dtrace.py

diff --git a/Lib/test/test_dtrace.py b/Lib/test/test_dtrace.py
index d398c0789d24a1..ea5cc7c8871db0 100644
--- a/Lib/test/test_dtrace.py
+++ b/Lib/test/test_dtrace.py
@@ -113,7 +113,7 @@ def terminate_process_group(proc):
         proc.communicate(timeout=TERMINATE_TIMEOUT)  # Clean up
 
 
-def run_readelf(cmd):
+def run_command(cmd):
     # Force the C locale to disable localization.
     env = dict(os.environ, LC_ALL="C")
     try:
@@ -125,7 +125,7 @@ def run_readelf(cmd):
             env=env,
         )
     except OSError:
-        raise unittest.SkipTest("Couldn't find readelf on the path")
+        raise unittest.SkipTest(f"Couldn't find {cmd[0]!r} on the path")
 
     with proc:
         stdout, stderr = proc.communicate()
@@ -528,6 +528,12 @@ class BPFTraceOptimizedTests(TraceTests, 
unittest.TestCase):
 class CheckDtraceProbes(unittest.TestCase):
     @classmethod
     def setUpClass(cls):
+        if sys.platform == "sunos5":
+            # Solaris does not expose available probes through readable ELF
+            # section; it uses DTrace itself instead.
+            DTraceBackend().assert_usable()
+            return
+
         readelf_major_version, readelf_minor_version = 
cls.get_readelf_version()
         if support.verbose:
             print(f"readelf version: 
{readelf_major_version}.{readelf_minor_version}")
@@ -535,7 +541,7 @@ def setUpClass(cls):
 
     @staticmethod
     def get_readelf_version():
-        version = run_readelf(["readelf", "--version"])
+        version = run_command(["readelf", "--version"])
 
         # Regex to parse:
         # 'GNU readelf (GNU Binutils) 2.40.0\n' -> 2.40
@@ -545,38 +551,50 @@ def get_readelf_version():
 
         return int(match.group(1)), int(match.group(2))
 
-    def get_readelf_output(self):
-        return run_readelf(["readelf", "-n", get_probe_binary()])
+    def get_probe_output(self):
+        if sys.platform == "sunos5":
+            # Get probes available in this process.
+            return run_command(
+                ["dtrace", "-l", "-P", f"python{os.getpid()}"]
+            )
+
+        return run_command(["readelf", "-n", get_probe_binary()])
+
+    def assert_probe_present(self, probe_name, output):
+        if sys.platform == "sunos5":
+            self.assertIn(probe_name.replace("__", "-"), output)
+        else:
+            self.assertIn(f"Name: {probe_name}", output)
 
     def test_check_probes(self):
-        readelf_output = self.get_readelf_output()
+        probe_output = self.get_probe_output()
 
         available_probe_names = [
-            "Name: import__find__load__done",
-            "Name: import__find__load__start",
-            "Name: audit",
-            "Name: gc__start",
-            "Name: gc__done",
-            "Name: function__entry",
-            "Name: function__return",
+            "import__find__load__done",
+            "import__find__load__start",
+            "audit",
+            "gc__start",
+            "gc__done",
+            "function__entry",
+            "function__return",
         ]
 
         for probe_name in available_probe_names:
             with self.subTest(probe_name=probe_name):
-                self.assertIn(probe_name, readelf_output)
+                self.assert_probe_present(probe_name, probe_output)
 
     @unittest.expectedFailure
     def test_missing_probes(self):
-        readelf_output = self.get_readelf_output()
+        probe_output = self.get_probe_output()
 
         # Missing probes will be added in the future.
         missing_probe_names = [
-            "Name: line",
+            "line",
         ]
 
         for probe_name in missing_probe_names:
             with self.subTest(probe_name=probe_name):
-                self.assertIn(probe_name, readelf_output)
+                self.assert_probe_present(probe_name, probe_output)
 
 
 if __name__ == '__main__':

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to