[PATCH v1 06/17] perf tests sort: Exercise the report and diff sort keys
From: Arnaldo Carvalho de Melo
Date: Tue Nov 24 2026 - 13:46:47 EST
From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Record a workload and report it sorted by the common keys, then diff
the file against itself with the same keys, checking that the workload
symbol still shows up.
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/tests/shell/sort.sh | 72 ++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
create mode 100755 tools/perf/tests/shell/sort.sh
diff --git a/tools/perf/tests/shell/sort.sh b/tools/perf/tests/shell/sort.sh
new file mode 100755
index 0000000000000000..19f42ded2b895317
--- /dev/null
+++ b/tools/perf/tests/shell/sort.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+# perf report and diff sort key tests
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+shelldir=$(dirname "$0")
+# shellcheck source=lib/perf_has_symbol.sh
+. "${shelldir}"/lib/perf_has_symbol.sh
+
+testprog="perf test -w thloop"
+testsym="test_loop"
+sort_keys="pid,comm,dso,symbol,cpu,srcline,period,time,socket,weight,transaction,type,srcfile,cgroup"
+
+skip_test_missing_symbol "${testsym}"
+
+perfdata=$(mktemp /tmp/__perf_test_sort.perf.data.XXXXX)
+out=$(mktemp /tmp/__perf_test_sort.out.XXXXX)
+err=0
+
+cleanup() {
+ rm -f "${perfdata}" "${perfdata}".old
+ rm -f "${out}"
+
+ trap - EXIT TERM INT
+}
+
+trap_cleanup() {
+ echo "Unexpected signal in ${FUNCNAME[1]}"
+ cleanup
+ exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
+test_report_sort() {
+ echo "perf report sort keys test"
+ perf record -o "${perfdata}" --sample-cpu ${testprog}
+ if ! perf report -i "${perfdata}" --stdio -q -s "${sort_keys}" > "${out}" 2>&1; then
+ echo "perf report sort keys test [Failed: perf report failed]"
+ cat "${out}"
+ err=1
+ return
+ fi
+ if ! grep -q "${testsym}" "${out}"; then
+ echo "perf report sort keys test [Failed missing ${testsym}]"
+ err=1
+ return
+ fi
+ echo "perf report sort keys test [Success]"
+}
+
+test_diff_sort() {
+ echo "perf diff sort keys test"
+ if ! perf diff -s "${sort_keys}" "${perfdata}" "${perfdata}" > "${out}" 2>&1; then
+ echo "perf diff sort keys test [Failed: perf diff failed]"
+ cat "${out}"
+ err=1
+ return
+ fi
+ if ! grep -q "${testsym}" "${out}"; then
+ echo "perf diff sort keys test [Failed missing ${testsym}]"
+ err=1
+ return
+ fi
+ echo "perf diff sort keys test [Success]"
+}
+
+test_report_sort
+test_diff_sort
+
+cleanup
+exit $err
--
2.56.0