linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/2] perf test: Add an 'import perf' test shell script
@ 2025-09-03 18:42 Ian Rogers
  2025-09-03 18:42 ` [PATCH v1 2/2] perf test: Remove C python_use test Ian Rogers
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Ian Rogers @ 2025-09-03 18:42 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
	Ian Rogers, Adrian Hunter, Kan Liang, James Clark, Collin Funk,
	Ravi Bangoria, linux-kernel, linux-perf-users

The 'import perf' test needs to set up a path to the python module as
well as to know the python command to invoke. These are hard coded at
build time to be build a directory and the python used in the build,
which is less than desirable. Avoid the hard coded values by reusing
the existing shell script python setup and determine a potential built
python module via the path of the perf executable.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/tests/shell/python-use.sh | 36 ++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100755 tools/perf/tests/shell/python-use.sh

diff --git a/tools/perf/tests/shell/python-use.sh b/tools/perf/tests/shell/python-use.sh
new file mode 100755
index 000000000000..fd2ee5390060
--- /dev/null
+++ b/tools/perf/tests/shell/python-use.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+# 'import perf' in python
+# SPDX-License-Identifier: GPL-2.0
+# Just test if we can load the python binding.
+set -e
+
+shelldir=$(dirname "$0")
+# shellcheck source=lib/setup_python.sh
+. "${shelldir}"/lib/setup_python.sh
+
+MODULE_DIR=$(dirname "$(which perf)")/python
+
+if [ -d "$MODULE_DIR" ]
+then
+    CMD=$(cat <<EOF
+import sys
+sys.path.insert(0, '$MODULE_DIR')
+import perf
+print('success!')
+EOF
+    )
+else
+    CMD=$(cat <<EOF
+import perf
+print('success!')
+EOF
+    )
+fi
+
+echo -e "Testing 'import perf' with:\n$CMD"
+
+if ! echo "$CMD" | $PYTHON | grep -q "success!"
+then
+  exit 1
+fi
+exit 0
-- 
2.51.0.338.gd7d06c2dae-goog


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-10-01 18:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-03 18:42 [PATCH v1 1/2] perf test: Add an 'import perf' test shell script Ian Rogers
2025-09-03 18:42 ` [PATCH v1 2/2] perf test: Remove C python_use test Ian Rogers
2025-09-30 20:02 ` [PATCH v1 1/2] perf test: Add an 'import perf' test shell script Ian Rogers
2025-10-01 13:42   ` Arnaldo Carvalho de Melo
2025-10-01 13:44     ` Arnaldo Carvalho de Melo
2025-10-01 14:55     ` Ian Rogers
2025-10-01 18:23       ` Arnaldo Carvalho de Melo
2025-10-01 18:29         ` Ian Rogers
2025-09-30 23:10 ` Collin Funk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).