|
7 | 7 | from test import support |
8 | 8 | from test.support.script_helper import make_script |
9 | 9 | from test.support.os_helper import temp_dir |
10 | | -from test.support import check_sanitizer |
11 | 10 |
|
12 | 11 |
|
13 | | -def get_perf_version(): |
14 | | - try: |
15 | | - cmd = ["perf", "version"] |
16 | | - proc = subprocess.run( |
17 | | - cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True |
18 | | - ) |
19 | | - except (subprocess.SubprocessError, OSError): |
20 | | - raise unittest.SkipTest("Couldn't find perf on the path") |
21 | | - |
22 | | - version = proc.stdout |
23 | | - |
24 | | - match = re.search(r"^perf version\s+(.*)", version) |
25 | | - if match is None: |
26 | | - raise Exception("unable to parse perf version: %r" % version) |
27 | | - return (version, match.group(1)) |
28 | | - |
29 | 12 | if not support.has_subprocess_support: |
30 | 13 | raise unittest.SkipTest("test module requires subprocess") |
31 | 14 |
|
32 | | - |
33 | | -_, version = get_perf_version() |
34 | | - |
35 | | -if not version: |
36 | | - raise unittest.SkipTest("Could not find valid perf tool") |
37 | | - |
38 | | -if "no-omit-frame-pointer" not in sysconfig.get_config_var("CFLAGS"): |
| 15 | +if "no-omit-frame-pointer" not in sysconfig.get_config_var("PY_CORE_CFLAGS"): |
39 | 16 | raise unittest.SkipTest("Unwinding without frame pointer is unreliable") |
40 | 17 |
|
41 | | -if check_sanitizer(address=True, memory=True, ub=True): |
| 18 | +if support.check_sanitizer(address=True, memory=True, ub=True): |
42 | 19 | raise unittest.SkipTest("Perf unwinding doesn't work with sanitizers") |
43 | 20 |
|
| 21 | +def check_perf_command(): |
| 22 | + try: |
| 23 | + cmd = ["perf", "--help"] |
| 24 | + stdout = subprocess.check_output( |
| 25 | + cmd, universal_newlines=True |
| 26 | + ) |
| 27 | + except (subprocess.SubprocessError, OSError): |
| 28 | + raise unittest.SkipTest("Couldn't find perf on the path") |
| 29 | + |
| 30 | + # perf version does not return a version number on Fedora. Use presence |
| 31 | + # of "perf.data" in help as indicator that it's perf from Linux tools. |
| 32 | + if "perf.data" not in stdout: |
| 33 | + raise unittest.SkipTest( |
| 34 | + "perf command does not look like Linux tool perf" |
| 35 | + ) |
| 36 | + |
| 37 | +check_perf_command() |
| 38 | + |
44 | 39 |
|
45 | 40 | def run_perf(cwd, *args, **env_vars): |
46 | 41 | if env_vars: |
|
0 commit comments