From: Ian Rogers <irogers@google.com>
To: irogers@google.com, acme@kernel.org, namhyung@kernel.org
Cc: 9erthalion6@gmail.com, adrian.hunter@intel.com,
alexandre.chartre@oracle.com, blakejones@google.com,
bpf@vger.kernel.org, costa.shul@redhat.com, dsterba@suse.com,
james.clark@linaro.org, jolsa@kernel.org, leo.yan@arm.com,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
mark@klomp.org, mingo@redhat.com, mjeanson@efficios.com,
nathan@kernel.org, peterz@infradead.org, rong.bao@csmantle.top,
serhei@serhei.io, terrelln@fb.com, tglozar@redhat.com,
tianyou.li@intel.com, yuzhuo@google.com, zecheng@google.com
Subject: [PATCH v3 7/7] perf test: Add BPF JIT annotation test coverage for all disassemblers
Date: Tue, 9 Jun 2026 11:21:08 -0700 [thread overview]
Message-ID: <20260609182108.975586-8-irogers@google.com> (raw)
In-Reply-To: <20260609182108.975586-1-irogers@google.com>
Expand the annotate.sh shell test to verify BPF JIT disassembly.
If the test is run with sufficient privileges (root/CAP_BPF) and
captures system BPF programs, it will extract a JITted BPF program
symbol from the perf report and run perf annotate on it.
This validates the temporary ELF generation and disassembles it using
each of the supported disassembler backends (objdump, llvm, capstone,
and libasm).
Assisted-by: Antigravity:Google Gemini 3.5-flash
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/tests/shell/annotate.sh | 93 ++++++++++++++++++++++++++++++
1 file changed, 93 insertions(+)
diff --git a/tools/perf/tests/shell/annotate.sh b/tools/perf/tests/shell/annotate.sh
index eae6a46a247b..ae03580fa023 100755
--- a/tools/perf/tests/shell/annotate.sh
+++ b/tools/perf/tests/shell/annotate.sh
@@ -18,6 +18,7 @@ skip_test_missing_symbol ${testsym}
err=0
perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
perfout=$(mktemp /tmp/__perf_test.perf.out.XXXXX)
+bpftmp=""
testprog="perf test -w noploop"
# disassembly format: "percent : offset: instruction (operands ...)"
disasm_regex="[0-9]*\.[0-9]* *: *\w*: *\w*"
@@ -25,6 +26,9 @@ disasm_regex="[0-9]*\.[0-9]* *: *\w*: *\w*"
cleanup() {
rm -rf "${perfdata}" "${perfout}"
rm -rf "${perfdata}".old
+ if [ -n "${bpftmp}" ]; then
+ rm -rf "${bpftmp}"
+ fi
trap - EXIT TERM INT
}
@@ -169,5 +173,94 @@ then
test_disassembler "libasm" "libasm"
fi
+test_bpf_disassembler() {
+ disassembler=$1
+ feature=$2
+ bpf_perfdata_file=$3
+
+ if [ -n "${feature}" ]
+ then
+ if ! perf check feature "${feature}" > /dev/null 2>&1
+ then
+ echo "Skip BPF JIT test for ${disassembler} (feature ${feature} not supported)"
+ return 0
+ fi
+ fi
+
+ echo "Test BPF JIT annotate with disassembler: ${disassembler}"
+
+ if ! perf annotate --no-demangle -i "${bpf_perfdata_file}" --stdio "${bpf_sym}" \
+ --disassembler "${disassembler}" 2> /dev/null > "${perfout}"
+ then
+ echo "BPF JIT annotate with ${disassembler} [Failed: perf annotate error]"
+ err=1
+ return 0
+ fi
+
+ if ! grep -q "${disasm_regex}" "${perfout}"
+ then
+ echo "BPF JIT annotate with ${disassembler} [Failed: missing disasm output]"
+ err=1
+ return 0
+ fi
+
+ echo "BPF JIT annotate with ${disassembler} [Success]"
+ return 0
+}
+
+test_bpf() {
+ echo "Test annotate with BPF JIT output"
+
+ if ! perf check -q feature libbpf-strings ; then
+ echo "BPF annotation test [Skipped - libbpf-strings not supported]"
+ return 0
+ fi
+
+ bpftmp=$(mktemp -d /tmp/__perf_test.bpf.XXXXXX)
+ bpf_perfdata="${bpftmp}/perf.data"
+
+ if ! perf record -a -e cycles -F 4000 -o "${bpf_perfdata}" -- sleep 1 2> /dev/null
+ then
+ echo "BPF annotation test [Skipped - perf record -a failed, probably no privileges]"
+ rm -rf "${bpftmp}"
+ bpftmp=""
+ return 0
+ fi
+
+ bpf_symbols=$(perf report --stdio -i "${bpf_perfdata}" 2>/dev/null | \
+ grep -E -o 'bpf_prog_[0-9a-f]{16}_[0-9A-Za-z_]*' | sort -u)
+
+ bpf_sym=""
+ for sym in ${bpf_symbols}
+ do
+ # Check if we can annotate it (meaning JIT code is available)
+ if perf annotate -i "${bpf_perfdata}" --stdio "${sym}" > /dev/null 2>&1
+ then
+ bpf_sym="${sym}"
+ break
+ fi
+ done
+
+ if [ -z "${bpf_sym}" ]; then
+ echo "BPF annotation test [Skipped - no JITted BPF symbols with code found (race?)]"
+ rm -rf "${bpftmp}"
+ bpftmp=""
+ return 0
+ fi
+
+ test_bpf_disassembler "objdump" "" "${bpf_perfdata}"
+ test_bpf_disassembler "llvm" "libLLVM" "${bpf_perfdata}"
+ test_bpf_disassembler "capstone" "libcapstone" "${bpf_perfdata}"
+ test_bpf_disassembler "libasm" "libasm" "${bpf_perfdata}"
+
+ rm -rf "${bpftmp}"
+ bpftmp=""
+}
+
+if [ "${err}" -eq 0 ]
+then
+ test_bpf
+fi
+
cleanup
exit $err
--
2.54.0.1099.g489fc7bff1-goog
prev parent reply other threads:[~2026-06-09 18:21 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 7:07 [PATCH v2 0/7] perf annotate: Add elfutils libasm disassembler support Ian Rogers
2026-06-09 7:07 ` [PATCH v2 1/7] tools build: Add feature check for elfutils libasm Ian Rogers
2026-06-09 7:21 ` sashiko-bot
2026-06-09 7:07 ` [PATCH v2 2/7] perf build: Add build support and capability " Ian Rogers
2026-06-09 7:19 ` sashiko-bot
2026-06-09 7:07 ` [PATCH v2 3/7] perf annotate: Implement elfutils libasm disassembler backend Ian Rogers
2026-06-09 7:07 ` [PATCH v2 4/7] perf annotate: Add --disassembler command-line option Ian Rogers
2026-06-09 7:07 ` [PATCH v2 5/7] perf test: Enhance annotate test coverage and isolate config Ian Rogers
2026-06-09 7:15 ` sashiko-bot
2026-06-09 7:07 ` [PATCH v2 6/7] perf annotate: Support BPF JIT disassembly via genelf Ian Rogers
2026-06-09 7:22 ` sashiko-bot
2026-06-09 7:07 ` [PATCH v2 7/7] perf test: Add BPF JIT annotation test coverage for all disassemblers Ian Rogers
2026-06-09 7:18 ` sashiko-bot
2026-06-09 18:21 ` [PATCH v3 0/7] perf annotate: Add elfutils libasm disassembler and BPF JIT disassembly support Ian Rogers
2026-06-09 18:21 ` [PATCH v3 1/7] tools build: Add feature check for elfutils libasm Ian Rogers
2026-06-09 18:46 ` sashiko-bot
2026-06-09 18:21 ` [PATCH v3 2/7] perf build: Add build support and capability " Ian Rogers
2026-06-09 18:21 ` [PATCH v3 3/7] perf annotate: Implement elfutils libasm disassembler backend Ian Rogers
2026-06-09 18:52 ` sashiko-bot
2026-06-09 18:21 ` [PATCH v3 4/7] perf annotate: Add --disassembler command-line option Ian Rogers
2026-06-09 18:21 ` [PATCH v3 5/7] perf test: Enhance annotate test coverage and isolate config Ian Rogers
2026-06-09 18:46 ` sashiko-bot
2026-06-09 18:21 ` [PATCH v3 6/7] perf annotate: Support BPF JIT disassembly via genelf Ian Rogers
2026-06-09 18:49 ` sashiko-bot
2026-06-09 18:21 ` Ian Rogers [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260609182108.975586-8-irogers@google.com \
--to=irogers@google.com \
--cc=9erthalion6@gmail.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexandre.chartre@oracle.com \
--cc=blakejones@google.com \
--cc=bpf@vger.kernel.org \
--cc=costa.shul@redhat.com \
--cc=dsterba@suse.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=leo.yan@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark@klomp.org \
--cc=mingo@redhat.com \
--cc=mjeanson@efficios.com \
--cc=namhyung@kernel.org \
--cc=nathan@kernel.org \
--cc=peterz@infradead.org \
--cc=rong.bao@csmantle.top \
--cc=serhei@serhei.io \
--cc=terrelln@fb.com \
--cc=tglozar@redhat.com \
--cc=tianyou.li@intel.com \
--cc=yuzhuo@google.com \
--cc=zecheng@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox