https://github.com/python/cpython/commit/37959e25cbbe1d207c660b5bc9583b9bd1403f1a
commit: 37959e25cbbe1d207c660b5bc9583b9bd1403f1a
branch: main
author: Pablo Galindo Salgado <[email protected]>
committer: pablogsal <[email protected]>
date: 2024-05-07T20:41:07+01:00
summary:

gh-118518: Check for perf version and not kernel version in test_perf_profiler 
(#118640)

files:
M Lib/test/test_perf_profiler.py

diff --git a/Lib/test/test_perf_profiler.py b/Lib/test/test_perf_profiler.py
index 496983f7b49f52..7c1bbeed168d2e 100644
--- a/Lib/test/test_perf_profiler.py
+++ b/Lib/test/test_perf_profiler.py
@@ -479,17 +479,23 @@ def compile_trampolines_for_all_functions():
             if f"py::foo_fork:{script}" in line or f"py::bar_fork:{script}" in 
line:
                 self.assertIn(line, child_perf_file_contents)
 
-def _is_kernel_version_at_least(major, minor):
+
+def _is_perf_vesion_at_least(major, minor):
+    # The output of perf --version looks like "perf version 6.7-3" but
+    # it can also be perf version "perf version 5.15.143"
     try:
-        with open("/proc/version") as f:
-            version = f.readline().split()[2]
-    except FileNotFoundError:
+        output = subprocess.check_output(["perf", "--version"], text=True)
+    except (subprocess.CalledProcessError, FileNotFoundError):
         return False
+    version = output.split()[2]
+    version = version.split("-")[0]
     version = version.split(".")
-    return int(version[0]) > major or (int(version[0]) == major and 
int(version[1]) >= minor)
+    version = tuple(map(int, version))
+    return version >= (major, minor)
+
 
 @unittest.skipUnless(perf_command_works(), "perf command doesn't work")
[email protected](_is_kernel_version_at_least(6, 6), "perf command may not 
work due to a perf bug")
[email protected](_is_perf_vesion_at_least(6, 6), "perf command may not 
work due to a perf bug")
 class TestPerfProfilerWithDwarf(unittest.TestCase, TestPerfProfilerMixin):
     def run_perf(self, script_dir, script, activate_trampoline=True):
         if activate_trampoline:

_______________________________________________
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