Re: [PATCH v7 52/59] perf test: Migrate Intel PT virtual LBR test to use Python API

sashiko-bot
2026-04-25T23:14:52Z

Sashiko AI review found 2 potential issue(s):
- [Medium] The test fails instead of gracefully skipping when perf is compiled without Python support.
- [Medium] Hardcoded module path in `perf_brstack_max.py` breaks out-of-tree builds and installed test executions.
--

commit 80b4743807670a643e81f4cb7853f698004da24d
Author: Ian Rogers <irogers@google.com>

perf test: Migrate Intel PT virtual LBR test to use Python API

This commit migrates the Intel PT virtual LBR test from using an inline
ad-hoc python script to a dedicated Python script that utilizes the new
brstack iterator API in the perf Python module.

> diff --git a/tools/perf/tests/shell/lib/perf_brstack_max.py b/tools/perf/tests/shell/lib/perf_brstack_max.py
> new file mode 100644
> index 000000000000..bd1cdb463f28
> --- /dev/null
> +++ b/tools/perf/tests/shell/lib/perf_brstack_max.py
> @@ -0,0 +1,43 @@
> +#!/usr/bin/python
> +# SPDX-License-Identifier: GPL-2.0
> +# Determine the maximum size of branch stacks in a perf.data file.
> +
> +import argparse
> +import sys
> +
> +import os
> +
> +script_dir = os.path.dirname(os.path.abspath(__file__))
> +python_dir = os.path.abspath(os.path.join(script_dir, "../../../python"))
> +sys.path.insert(0, python_dir)
> +
> +import perf

Will this hardcoded path cause the test to fail in out-of-tree builds or
installed environments?

In out-of-tree builds (like make O=/tmp/build), the compiled perf.so
extension resides in the build directory, not the source tree. Similarly,
when running perf test from an installed location, this relative path
won't point to the correct system installation path.

In both cases, import perf will fail and cause the test to crash.

[ ... ]

> diff --git a/tools/perf/tests/shell/test_intel_pt.sh b/tools/perf/tests/shell/test_intel_pt.sh
> index 8ee761f03c38..d711ecdf5be0 100755
> --- a/tools/perf/tests/shell/test_intel_pt.sh
> +++ b/tools/perf/tests/shell/test_intel_pt.sh

[ ... ]

> @@ -539,34 +538,20 @@ test_kernel_trace()
> test_virtual_lbr()
> {
> echo "--- Test virtual LBR ---"
> - # Check if python script is supported
> - libpython=$(perf version --build-options | grep python | grep -cv OFF)
> - if [ "${libpython}" != "1" ] ; then
> - echo "SKIP: python scripting is not supported"
> + # shellcheck source=lib/setup_python.sh
> + . "$(dirname "$0")"/lib/setup_python.sh
> +
> + if [ -z "$PYTHON" ] ; then
> + echo "SKIP: Python not found"
> return 2
> fi

Can this change cause the test to fail instead of gracefully skipping when
perf is compiled without Python support?

The setup_python.sh script only checks if a Python interpreter exists on
the host, not whether perf was actually compiled with the Python extension.
If perf is compiled with NO_LIBPYTHON=1 or without the required headers,
setup_python.sh will still succeed, but perf_brstack_max.py will crash on
import perf with a ModuleNotFoundError.

Since the Python crash output goes to stderr, the test reads an empty
stdout, assigns times_val=0, and fails instead of skipping.

--
Sashiko AI review · https://sashiko.dev/#/patchset/20260425224951.174663-1-irogers@google.com?part=52