[PATCH 3/5] perf test java symbol: Extract LIBJVMTI detection

Ilya Leoshkevich
2025-11-05T19:16:41Z

Extract LIBJVMTI into lib/setup_libjvmti.sh for reuse by future tests.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
tools/perf/tests/shell/lib/setup_libjvmti.sh | 18 ++++++++++++++++++
tools/perf/tests/shell/test_java_symbol.sh | 17 ++---------------
2 files changed, 20 insertions(+), 15 deletions(-)
create mode 100644 tools/perf/tests/shell/lib/setup_libjvmti.sh

diff --git a/tools/perf/tests/shell/lib/setup_libjvmti.sh b/tools/perf/tests/shell/lib/setup_libjvmti.sh
new file mode 100644
index 0000000000000..fab4a44f8ecb2
--- /dev/null
+++ b/tools/perf/tests/shell/lib/setup_libjvmti.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+if [ -e "$PWD/tools/perf/libperf-jvmti.so" ]; then
+ LIBJVMTI=$PWD/tools/perf/libperf-jvmti.so
+elif [ -e "$PWD/libperf-jvmti.so" ]; then
+ LIBJVMTI=$PWD/libperf-jvmti.so
+elif [ -e "$PREFIX/lib64/libperf-jvmti.so" ]; then
+ LIBJVMTI=$PREFIX/lib64/libperf-jvmti.so
+elif [ -e "$PREFIX/lib/libperf-jvmti.so" ]; then
+ LIBJVMTI=$PREFIX/lib/libperf-jvmti.so
+elif [ -e "/usr/lib/linux-tools-$(uname -a | awk '{ print $3 }' | sed -r 's/-generic//')/libperf-jvmti.so" ]; then
+ LIBJVMTI=/usr/lib/linux-tools-$(uname -a | awk '{ print $3 }' | sed -r 's/-generic//')/libperf-jvmti.so
+else
+ echo "Fail to find libperf-jvmti.so"
+ # JVMTI is a build option, skip the test if fail to find lib
+ exit 2
+fi
diff --git a/tools/perf/tests/shell/test_java_symbol.sh b/tools/perf/tests/shell/test_java_symbol.sh
index b1d7cd43af01a..f36c9321568c5 100755
--- a/tools/perf/tests/shell/test_java_symbol.sh
+++ b/tools/perf/tests/shell/test_java_symbol.sh
@@ -26,21 +26,8 @@ cleanup_files() {

trap cleanup_files exit term int

-if [ -e "$PWD/tools/perf/libperf-jvmti.so" ]; then
- LIBJVMTI=$PWD/tools/perf/libperf-jvmti.so
-elif [ -e "$PWD/libperf-jvmti.so" ]; then
- LIBJVMTI=$PWD/libperf-jvmti.so
-elif [ -e "$PREFIX/lib64/libperf-jvmti.so" ]; then
- LIBJVMTI=$PREFIX/lib64/libperf-jvmti.so
-elif [ -e "$PREFIX/lib/libperf-jvmti.so" ]; then
- LIBJVMTI=$PREFIX/lib/libperf-jvmti.so
-elif [ -e "/usr/lib/linux-tools-$(uname -a | awk '{ print $3 }' | sed -r 's/-generic//')/libperf-jvmti.so" ]; then
- LIBJVMTI=/usr/lib/linux-tools-$(uname -a | awk '{ print $3 }' | sed -r 's/-generic//')/libperf-jvmti.so
-else
- echo "Fail to find libperf-jvmti.so"
- # JVMTI is a build option, skip the test if fail to find lib
- exit 2
-fi
+# shellcheck source=lib/setup_libjvmti.sh
+. "$(dirname "$0")/lib/setup_libjvmti.sh"

cat <<EOF | perf record -k 1 -o "$PERF_DATA" jshell -s -J"-agentpath:$LIBJVMTI"
int fib(int x) {
--
2.51.1