From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>
Cc: Athira Rajeev <atrajeev@linux.ibm.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Leo Yan <leo.yan@linux.dev>, Dmitry Vyukov <dvyukov@google.com>,
"Steinar H . Gunderson" <sesse@google.com>,
Stephen Brennan <stephen.s.brennan@oracle.com>,
Thomas Falcon <thomas.falcon@intel.com>,
linux-perf-users@vger.kernel.org, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v4 19/19] perf test: Add inject --sample-buildids and record --buildid-offset shell tests
Date: Tue, 24 Nov 2026 16:51:08 -0800 [thread overview]
Message-ID: <20261125005108.1020003-20-irogers@google.com> (raw)
In-Reply-To: <20261125005108.1020003-1-irogers@google.com>
Add shell tests verifying perf inject --sample-buildids (with basic
samples, callchains, pipe mode, and kernel samples) and perf record
--buildid-offset across per-thread, system-wide, workload, and callgraph
modes.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/tests/shell/inject_bid_offset.sh | 179 ++++++++++++++++++++
tools/perf/tests/shell/record.sh | 74 ++++++++
2 files changed, 253 insertions(+)
create mode 100755 tools/perf/tests/shell/inject_bid_offset.sh
diff --git a/tools/perf/tests/shell/inject_bid_offset.sh b/tools/perf/tests/shell/inject_bid_offset.sh
new file mode 100755
index 000000000000..9be2e3323558
--- /dev/null
+++ b/tools/perf/tests/shell/inject_bid_offset.sh
@@ -0,0 +1,179 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# perf inject --sample-buildids test
+
+set -e
+set -o pipefail
+
+shelldir=$(dirname "$0")
+# shellcheck source=lib/perf_has_symbol.sh
+. "${shelldir}"/lib/perf_has_symbol.sh
+
+sym="noploop"
+
+skip_test_missing_symbol ${sym}
+
+temp_dir=$(mktemp -d /tmp/perf-test-bid-offset.XXXXXXXXXX)
+
+prog="perf test -w noploop"
+[ "$(uname -m)" = "s390x" ] && prog="$prog 3"
+err=0
+
+cleanup() {
+ local exit_code=${1:-$?}
+ trap - EXIT TERM INT
+ if [ "${exit_code}" -ne 0 ] || [ "${err}" -ne 0 ]; then
+ echo "Test failed! Preserving temp directory: ${temp_dir}"
+ exit 1
+ fi
+ if [[ "${temp_dir}" =~ ^/tmp/perf-test-bid-offset\. ]]; then
+ rm -rf "${temp_dir}"
+ fi
+ exit 0
+}
+
+trap_cleanup() {
+ local exit_code=$?
+ echo "Unexpected signal in ${FUNCNAME[1]}"
+ cleanup ${exit_code}
+}
+trap trap_cleanup EXIT TERM INT
+
+compare_script() {
+ local orig=$1
+ local bid=$2
+ local msg=$3
+
+ perf script -F -ip -i "${orig}" > "${temp_dir}/script_orig.txt"
+ perf script -F -ip -i "${bid}" > "${temp_dir}/script_bid.txt"
+
+ if [ ! -s "${temp_dir}/script_orig.txt" ]; then
+ echo "${msg} [Failed - empty perf script output]"
+ err=1
+ elif ! diff -q "${temp_dir}/script_orig.txt" "${temp_dir}/script_bid.txt"; then
+ echo "${msg} [Failed - perf script output differs]"
+ err=1
+ else
+ echo "${msg} [Success]"
+ fi
+}
+
+compare_report() {
+ local orig=$1
+ local bid=$2
+ local msg=$3
+
+ perf report -i "${orig}" --stdio | grep -v '^#' > "${temp_dir}/report_orig.txt"
+ perf report -i "${bid}" --stdio | grep -v '^#' > "${temp_dir}/report_bid.txt"
+
+ if ! diff -q "${temp_dir}/report_orig.txt" "${temp_dir}/report_bid.txt"; then
+ echo "${msg} [Failed - perf report output differs]"
+ err=1
+ else
+ echo "${msg} [Success]"
+ fi
+}
+
+test_basic() {
+ echo "Test basic build id offset injection"
+ local data="${temp_dir}/perf.data.basic"
+ local data2="${temp_dir}/perf.data2.basic"
+
+ perf record -e task-clock:u -o "${data}" ${prog} >/dev/null 2>&1
+ perf inject --sample-buildids -i "${data}" -o "${data2}" >/dev/null 2>&1
+
+ compare_script "${data}" "${data2}" "Basic injection"
+}
+
+test_callchain() {
+ echo "Test Callchain build id offset injection"
+ local data="${temp_dir}/perf.data.callchain"
+ local data2="${temp_dir}/perf.data2.callchain"
+
+ perf record --call-graph fp -e task-clock:u -o "${data}" ${prog} >/dev/null 2>&1
+ perf inject --sample-buildids -i "${data}" -o "${data2}" >/dev/null 2>&1
+
+ compare_script "${data}" "${data2}" "Callchain injection"
+}
+
+test_pipe() {
+ echo "Test pipe mode build id offset injection"
+ local data="${temp_dir}/perf.data.pipe"
+ local data2="${temp_dir}/perf.data2.pipe"
+
+ perf record -e task-clock:u -o - ${prog} 2>/dev/null | tee "${data}" | \
+ perf inject --sample-buildids -o "${data2}" >/dev/null 2>&1
+
+ compare_script "${data}" "${data2}" "Pipe mode injection"
+}
+
+test_report() {
+ echo "Test perf report consistency"
+ local data="${temp_dir}/perf.data.report"
+ local data2="${temp_dir}/perf.data2.report"
+
+ perf record -e task-clock:u -o "${data}" ${prog} >/dev/null 2>&1
+ perf inject --sample-buildids -i "${data}" -o "${data2}" >/dev/null 2>&1
+
+ compare_report "${data}" "${data2}" "Report consistency"
+}
+
+test_pipe_report() {
+ echo "Test pipe mode perf report consistency"
+ local data="${temp_dir}/perf.data.pipe_report"
+ local data2="${temp_dir}/perf.data2.pipe_report"
+
+ perf record -e task-clock:u -o - ${prog} 2>/dev/null | tee "${data}" | \
+ perf inject --sample-buildids -o "${data2}" >/dev/null 2>&1
+
+ compare_report "${data}" "${data2}" "Pipe Report consistency"
+}
+
+test_kernel() {
+ echo "Test kernel build id offset injection"
+ local data="${temp_dir}/perf.data.kernel"
+ local data2="${temp_dir}/perf.data2.kernel"
+ local kprog="dd if=/dev/urandom of=/dev/null bs=1M count=50"
+
+ # Not all systems allow kernel profiling, so we check if it succeeds first
+ if ! perf record -e task-clock:k -o "${data}" ${kprog} >/dev/null 2>&1; then
+ echo "Kernel injection [Skipped - permissions or support missing]"
+ return
+ fi
+ perf inject --sample-buildids -i "${data}" -o "${data2}" >/dev/null 2>&1
+
+ compare_script "${data}" "${data2}" "Kernel injection"
+}
+
+test_record_buildid_offset() {
+ echo "Test perf record --buildid-offset consistency"
+ local data="${temp_dir}/perf.data.record_orig"
+ local data2="${temp_dir}/perf.data2.record_bid"
+
+ perf record -e task-clock:u -o "${data}" ${prog} >/dev/null 2>&1
+ # We must have the binaries in .build-id cache, which the first record does natively.
+ # Now record with --buildid-offset.
+ if ! perf record --buildid-offset -e task-clock:u -o "${data2}" \
+ ${prog} >/dev/null 2>&1; then
+ echo "Record --buildid-offset consistency [Skipped - not supported by kernel]"
+ return
+ fi
+
+ # Verify symbolization resolves the workload symbol
+ if ! perf report -i "${data2}" --stdio | grep -q "${sym}"; then
+ echo "Record --buildid-offset consistency [Failed - missing ${sym} in perf report]"
+ err=1
+ else
+ echo "Record --buildid-offset consistency [Success]"
+ fi
+}
+
+test_basic
+test_callchain
+test_pipe
+test_report
+test_pipe_report
+test_kernel
+test_record_buildid_offset
+
+cleanup ${err}
diff --git a/tools/perf/tests/shell/record.sh b/tools/perf/tests/shell/record.sh
index e4789e2bcf43..80cee3eedcc3 100755
--- a/tools/perf/tests/shell/record.sh
+++ b/tools/perf/tests/shell/record.sh
@@ -740,6 +740,79 @@ test_ratio_to_prev() {
echo "Basic ratio-to-prev record test [Success]"
}
+check_buildid_offset() {
+ perf report --header -D -i "${perfdata}" 2>/dev/null | grep -q "BUILD_ID_OFFSET"
+}
+
+test_buildid_offset() {
+ echo "buildid-offset test"
+ local ret=0
+ perf_record_with_retry "${perfdata}" "check_buildid_offset" "perf test -w thloop" \
+ --buildid-offset || ret=$?
+ if [ $ret -eq 2 ]; then
+ echo "buildid-offset test [Skipped not supported]"
+ return
+ elif [ $ret -eq 1 ]; then
+ echo "buildid-offset test [Failed missing output]"
+ err=1
+ return
+ fi
+
+ # Expand test coverage
+ ret=0
+ perf_record_with_retry "${perfdata}" "check_per_thread" "perf test -w thloop" \
+ --buildid-offset --per-thread || ret=$?
+ if [ $ret -ne 0 ]; then
+ echo "buildid-offset test [Failed per-thread]"
+ err=1
+ return
+ fi
+
+ ret=0
+ perf_record_with_retry "${perfdata}" "check_system_wide" "perf test -w thloop" \
+ --buildid-offset -aB --synth=no || ret=$?
+ if [ $ret -eq 2 ]; then
+ echo "buildid-offset system-wide [Skipped not supported]"
+ elif [ $ret -ne 0 ]; then
+ echo "buildid-offset test [Failed system-wide]"
+ err=1
+ return
+ fi
+
+ ret=0
+ perf_record_with_retry "${perfdata}" "check_workload" "perf test -w thloop" \
+ --buildid-offset || ret=$?
+ if [ $ret -ne 0 ]; then
+ echo "buildid-offset test [Failed workload]"
+ err=1
+ return
+ fi
+
+ case $(uname -m)
+ in s390x)
+ cmd_flags="--call-graph dwarf -e cpu-clock";;
+ *)
+ cmd_flags="-g";;
+ esac
+
+ if ! perf record --buildid-offset -o "${perfdata}" $cmd_flags \
+ perf test -w brstack > /dev/null 2>&1
+ then
+ echo "buildid-offset test [Failed callgraph record]"
+ err=1
+ return
+ fi
+
+ if ! perf report -i "${perfdata}" 2>&1 | grep -q "${testsym2}"
+ then
+ echo "buildid-offset test [Failed callgraph missing symbol]"
+ err=1
+ return
+ fi
+
+ echo "buildid-offset test [Success]"
+}
+
# raise the limit of file descriptors to minimum
if [[ $default_fd_limit -lt $min_fd_limit ]]; then
ulimit -Sn $min_fd_limit
@@ -760,6 +833,7 @@ test_precise_max
test_callgraph
test_acr_sampling
test_ratio_to_prev
+test_buildid_offset
# restore the default value
ulimit -Sn $default_fd_limit
--
2.56.1.831.g720f3f5937-goog
next prev parent reply other threads:[~2026-11-25 0:52 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 0:50 [PATCH v4 00/19] perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support Ian Rogers
2026-11-25 0:50 ` [PATCH v4 01/19] perf/core: Protect per-CPU callchain buffer across bpf_overflow_handler() Ian Rogers
2026-11-25 0:50 ` [PATCH v4 02/19] perf/uapi: Factor perf_build_id out into its own top-level struct Ian Rogers
2026-11-25 13:17 ` Peter Zijlstra
2026-11-30 19:34 ` Ian Rogers
2026-11-25 0:50 ` [PATCH v4 03/19] perf/uapi: Add BUILD_ID_OFFSET sample types to UAPI Ian Rogers
2026-11-25 13:25 ` Peter Zijlstra
2026-11-25 21:45 ` Namhyung Kim
2026-11-30 19:38 ` Ian Rogers
2026-12-01 8:14 ` Peter Zijlstra
2026-12-01 17:10 ` Ian Rogers
2026-12-01 8:10 ` Peter Zijlstra
2026-11-25 0:50 ` [PATCH v4 04/19] bpf: Export stack_map_get_build_id_offset() for perf events Ian Rogers
2026-11-25 0:50 ` [PATCH v4 05/19] perf/core: Implement BUILD_ID_OFFSET and CALLCHAIN_BUILD_ID_OFFSET sample types Ian Rogers
2026-11-25 1:19 ` sashiko-bot
2026-11-25 0:50 ` [PATCH v4 06/19] perf/core: Support deferred unwinding for BUILD_ID_OFFSET " Ian Rogers
2026-11-25 0:50 ` [PATCH v4 07/19] perf inject: Set ordered_events and ordering_requires_timestamps for --aslr Ian Rogers
2026-11-25 0:50 ` [PATCH v4 08/19] perf session: Avoid double byte-swapping re-parsed deferred samples Ian Rogers
2026-11-25 1:12 ` sashiko-bot
2026-11-25 0:50 ` [PATCH v4 09/19] perf inject: Fix PERF_SAMPLE_READ layout and bounds checks in aslr_tool__process_sample() Ian Rogers
2026-11-25 0:50 ` [PATCH v4 10/19] tools headers UAPI: Sync linux/perf_event.h for struct perf_build_id Ian Rogers
2026-11-25 0:51 ` [PATCH v4 11/19] tools headers UAPI: Sync linux/perf_event.h for BUILD_ID_OFFSET Ian Rogers
2026-11-25 0:51 ` [PATCH v4 12/19] perf: Refactor thread map and symbol APIs to take perf_sample Ian Rogers
2026-11-25 0:51 ` [PATCH v4 13/19] perf maps: Add dsos__find_by_build_id() and maps__find_by_build_id() Ian Rogers
2026-11-25 0:51 ` [PATCH v4 14/19] perf evsel: Parse, synthesize, and dump BUILD_ID_OFFSET sample types Ian Rogers
2026-11-25 0:51 ` [PATCH v4 15/19] perf symbol: Resolve symbols and callchains using build ID and offset Ian Rogers
2026-11-25 0:51 ` [PATCH v4 16/19] perf inject: Add --sample-buildids to convert samples to build ID + offset Ian Rogers
2026-11-25 1:18 ` sashiko-bot
2026-11-25 0:51 ` [PATCH v4 17/19] perf record: Add --buildid-offset option Ian Rogers
2026-11-25 1:19 ` sashiko-bot
2026-11-25 0:51 ` [PATCH v4 18/19] perf test: Add BUILD_ID_OFFSET C unit tests Ian Rogers
2026-11-25 0:51 ` Ian Rogers [this message]
2026-11-25 1:19 ` [PATCH v4 00/19] perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support sashiko-bot
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=20261125005108.1020003-20-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=atrajeev@linux.ibm.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dvyukov@google.com \
--cc=eddyz87@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=leo.yan@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=martin.lau@linux.dev \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=sesse@google.com \
--cc=song@kernel.org \
--cc=stephen.s.brennan@oracle.com \
--cc=thomas.falcon@intel.com \
--cc=yonghong.song@linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.