* [PATCH v1 01/17] perf tests top: Pin the ring buffer size
2026-11-24 18:45 [PATCH v1 00/17] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
@ 2026-11-24 18:45 ` Arnaldo Carvalho de Melo
2026-11-24 18:45 ` [PATCH v1 02/17] perf tests sched: Exercise the sched views and options Arnaldo Carvalho de Melo
` (15 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-11-24 18:45 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, linux-kernel, linux-perf-users,
Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
perf top sizes its default ring buffer from kernel.perf_event_mlock_kb, so
a test host tuned with a large value makes the default mapping huge and
perf top fails with ENOMEM.
Pass -m 128, the upstream default of 516 KiB, so the test behaves the same
whatever the host setting is.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/shell/top.sh | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/tools/perf/tests/shell/top.sh b/tools/perf/tests/shell/top.sh
index 3d52677ccb5fd309..4808d79275178b40 100755
--- a/tools/perf/tests/shell/top.sh
+++ b/tools/perf/tests/shell/top.sh
@@ -19,6 +19,9 @@ trap_cleanup() {
}
trap trap_cleanup EXIT TERM INT
+# perf top sizes its default ring buffer from kernel.perf_event_mlock_kb,
+# which a test host may have tuned large, pin it to the upstream default
+# of 128 pages (516 KiB) so the test does not depend on the host setting.
test_basic_perf_top() {
echo "Basic perf top test"
@@ -36,7 +39,7 @@ test_basic_perf_top() {
# Use -e cpu-clock to ensure we get samples
# Use sleep to keep stdin open but silent, preventing EOF loop or interactive spam
retval=0
- sleep 10 | timeout 5s perf top --stdio -d 1 -e cpu-clock \
+ sleep 10 | timeout 5s perf top --stdio -d 1 -m 128 -e cpu-clock \
-p $PID > "${log_file}" 2>&1 || retval=$?
if [ "${retval:-0}" -ne 124 ] && [ "${retval:-0}" -ne 0 ]; then
echo "Basic perf top test [Failed: perf top failed to start or run (ret=$retval)]"
@@ -83,7 +86,7 @@ test_hybrid_merge_perf_top() {
# environments can seamlessly fall back to cpu-clock while real
# hybrid hardware will naturally cover the merge logic.
retval=0
- sleep 10 | timeout 5s perf top \
+ sleep 10 | timeout 5s perf top -m 128 \
--stdio --hybrid-merge -d 1 -p $PID > "${log_file}" 2>&1 || retval=$?
if [ "${retval:-0}" -ne 124 ] && [ "${retval:-0}" -ne 0 ]; then
echo "Perf top hybrid merge test [Failed: run err=$retval]"
--
2.56.0
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v1 02/17] perf tests sched: Exercise the sched views and options
2026-11-24 18:45 [PATCH v1 00/17] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
2026-11-24 18:45 ` [PATCH v1 01/17] perf tests top: Pin the ring buffer size Arnaldo Carvalho de Melo
@ 2026-11-24 18:45 ` Arnaldo Carvalho de Melo
2026-11-24 18:45 ` [PATCH v1 03/17] perf tests help: Add a basic perf help test Arnaldo Carvalho de Melo
` (14 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-11-24 18:45 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, linux-kernel, linux-perf-users,
Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
The test pipes the map, latency and timehist output to grep, which
stops reading at the first match, so the command is killed by
SIGPIPE before it produces the rest of its output. It also passes
--no-inherit, a no-op since perf sched record always records CPU
wide and inherit is cleared for CPU wide targets.
Capture the output first, drop --no-inherit and add the map,
latency and timehist options along with schedstat record, report and
diff coverage.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/shell/sched.sh | 154 +++++++++++++++++++++++---------
1 file changed, 111 insertions(+), 43 deletions(-)
diff --git a/tools/perf/tests/shell/sched.sh b/tools/perf/tests/shell/sched.sh
index 113df962a51c878f..e1aa8570b21f4ad9 100755
--- a/tools/perf/tests/shell/sched.sh
+++ b/tools/perf/tests/shell/sched.sh
@@ -11,12 +11,17 @@ fi
err=0
perfdata=$(mktemp /tmp/__perf_test_sched.perf.data.XXXXX)
+statsdata=$(mktemp /tmp/__perf_test_sched.stats.XXXXX)
+schedout=$(mktemp /tmp/__perf_test_sched.out.XXXXX)
PID1=0
PID2=0
cleanup() {
rm -f "${perfdata}"
rm -f "${perfdata}".old
+ rm -f "${statsdata}"
+ rm -f "${statsdata}".old
+ rm -f "${schedout}"
trap - EXIT TERM INT
}
@@ -56,90 +61,153 @@ cleanup_noploops() {
kill "$PID1" "$PID2" || true
}
+run_sched() {
+ local desc="$1" expect="$2"
+
+ shift 2
+ echo "Sched ${desc}"
+ if ! perf sched "$@" > "${schedout}" 2>&1
+ then
+ echo "Sched ${desc} [Failed: perf sched failed]"
+ cat "${schedout}"
+ err=1
+ return
+ fi
+ if [ -n "${expect}" ] && ! grep -q "${expect}" "${schedout}"
+ then
+ echo "Sched ${desc} [Failed: missing '${expect}']"
+ cat "${schedout}"
+ err=1
+ return
+ fi
+ echo "Sched ${desc} [Success]"
+}
+
test_sched_record() {
echo "Sched record"
start_noploops
- perf sched record --no-inherit -o "${perfdata}" sleep 1
+ if ! perf sched record -o "${perfdata}" sleep 1
+ then
+ echo "Sched record [Failed: perf sched record failed]"
+ err=1
+ fi
cleanup_noploops
}
test_sched_latency() {
- echo "Sched latency"
-
- if ! perf sched latency -i "${perfdata}" | grep -q perf-noploop
- then
- echo "Sched latency [Failed missing output]"
- err=1
- fi
+ run_sched "latency" "perf-noploop" latency -i "${perfdata}"
}
test_sched_latency_histogram() {
- echo "Sched latency histogram"
+ run_sched "latency histogram" "Latency Distribution Histogram" \
+ latency -H -i "${perfdata}"
+ run_sched "latency linear histogram" "Latency Distribution Histogram" \
+ latency --histogram --hist-mode linear -i "${perfdata}"
+}
- if ! perf sched latency -H -i "${perfdata}" | grep -q "Latency Distribution Histogram"
- then
- echo "Sched latency histogram [Failed missing log histogram]"
- err=1
- fi
+test_sched_latency_options() {
+ run_sched "latency sort" "perf-noploop" latency -s max -i "${perfdata}"
+ run_sched "latency per pid" "perf-noploop" latency -p -i "${perfdata}"
+ run_sched "latency cpu filter" "" latency -C 0 -i "${perfdata}"
+ run_sched "latency time filter" "perf-noploop" latency --time 0, -i "${perfdata}"
+}
- if ! perf sched latency --histogram --hist-mode linear -i "${perfdata}" | grep -q "Latency Distribution Histogram"
- then
- echo "Sched latency histogram [Failed missing linear histogram]"
- err=1
- fi
+test_sched_script() {
+ run_sched "script" "perf-noploop" script -i "${perfdata}"
}
-test_sched_latency_time() {
- echo "Sched latency time filter"
+test_sched_map() {
+ run_sched "map" "perf-noploop" map -i "${perfdata}"
+}
- if ! perf sched latency --time 0, -i "${perfdata}" | grep -q perf-noploop
- then
- echo "Sched latency time filter [Failed missing output]"
- err=1
- fi
+test_sched_map_options() {
+ run_sched "map compact" "" map --compact -i "${perfdata}"
+ run_sched "map color" "" map --color-pids "${PID1}" --color-cpus 0 \
+ --cpus 0 -i "${perfdata}"
+ run_sched "map task name" "" map --task-name perf-noploop -i "${perfdata}"
+ run_sched "map fuzzy name" "" map --task-name noploop --fuzzy-name \
+ -i "${perfdata}"
}
-test_sched_script() {
- echo "Sched script"
+test_sched_timehist() {
+ run_sched "timehist" "perf-noploop" timehist -i "${perfdata}"
+}
+
+test_sched_timehist_options() {
+ run_sched "timehist summary" "Runtime summary" timehist --summary -i "${perfdata}"
+ run_sched "timehist wakeups" "awakened:" timehist -w -i "${perfdata}"
+ run_sched "timehist migrations" "migrated:" timehist -M -i "${perfdata}"
+ run_sched "timehist idle" "Idle-time summary" timehist -I --summary -i "${perfdata}"
+ run_sched "timehist state" "sch delay" \
+ timehist --state --show-prio -V -P -i "${perfdata}"
+ run_sched "timehist call graph" "" timehist -g --max-stack 3 -i "${perfdata}"
+ run_sched "timehist pid filter" "" timehist -p "${PID1}" -i "${perfdata}"
+ run_sched "timehist prio filter" "" timehist --show-prio --prio 0 -i "${perfdata}"
+ run_sched "timehist with summary" "perf-noploop" timehist -S -i "${perfdata}"
+}
+
+test_sched_stats_live() {
+ echo "Sched stats live"
- if ! perf sched script -i "${perfdata}" | grep -q perf-noploop
+ ret=0
+ timeout -s INT -k 5 3 perf sched stats > "${schedout}" 2>&1 || ret=$?
+ if [ "${ret}" != 0 ] && [ "${ret}" != 124 ]
then
- echo "Sched script [Failed missing output]"
+ echo "Sched stats live [Failed: perf sched stats failed]"
+ cat "${schedout}"
err=1
+ return
fi
-}
-test_sched_map() {
- echo "Sched map"
-
- if ! perf sched map -i "${perfdata}" | grep -q perf-noploop
+ if ! grep -q "Description" "${schedout}"
then
- echo "Sched map [Failed missing output]"
+ echo "Sched stats live [Failed missing output]"
err=1
+ return
fi
+ echo "Sched stats live [Success]"
}
-test_sched_timehist() {
- echo "Sched timehist"
-
- if ! perf sched timehist -i "${perfdata}" | grep -q perf-noploop
+test_sched_stats_record() {
+ if ! perf sched stats record -o "${statsdata}" sleep 1
+ then
+ echo "Sched stats record [Failed: perf sched stats record failed]"
+ err=1
+ return
+ fi
+ if [ ! -s "${statsdata}" ]
then
- echo "Sched timehist [Failed missing output]"
+ echo "Sched stats record [Failed: no data file]"
err=1
+ return
fi
+ echo "Sched stats record [Success]"
+}
+
+test_sched_stats_report() {
+ run_sched "stats report" "Description" stats report -i "${statsdata}" -C 0 -v
+}
+
+test_sched_stats_diff() {
+ run_sched "stats diff" "" stats diff "${statsdata}" "${statsdata}"
}
test_sched_record
test_sched_latency
test_sched_latency_histogram
-test_sched_latency_time
+test_sched_latency_options
test_sched_script
test_sched_map
+test_sched_map_options
test_sched_timehist
+test_sched_timehist_options
+test_sched_stats_live
+test_sched_stats_record
+test_sched_stats_report
+test_sched_stats_diff
cleanup
exit $err
-
--
2.56.0
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v1 03/17] perf tests help: Add a basic perf help test
2026-11-24 18:45 [PATCH v1 00/17] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
2026-11-24 18:45 ` [PATCH v1 01/17] perf tests top: Pin the ring buffer size Arnaldo Carvalho de Melo
2026-11-24 18:45 ` [PATCH v1 02/17] perf tests sched: Exercise the sched views and options Arnaldo Carvalho de Melo
@ 2026-11-24 18:45 ` Arnaldo Carvalho de Melo
2026-11-24 18:45 ` [PATCH v1 04/17] perf tests config: Exercise the config file and list options Arnaldo Carvalho de Melo
` (13 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-11-24 18:45 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, linux-kernel, linux-perf-users,
Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
perf help and its -a option were not exercised by the suite. Check the
common command list and the command directory listing.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/shell/help.sh | 80 ++++++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
create mode 100755 tools/perf/tests/shell/help.sh
diff --git a/tools/perf/tests/shell/help.sh b/tools/perf/tests/shell/help.sh
new file mode 100755
index 0000000000000000..b7279a97a5615193
--- /dev/null
+++ b/tools/perf/tests/shell/help.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+# perf help tests
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+err=0
+out=$(mktemp /tmp/__perf_test_help.out.XXXXX)
+exec_path=
+
+cleanup() {
+ rm -f "${out}"
+ [ -z "${exec_path}" ] || rm -rf "${exec_path}"
+
+ trap - EXIT TERM INT
+}
+
+trap_cleanup() {
+ echo "Unexpected signal in ${FUNCNAME[1]}"
+ cleanup
+ exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
+test_help_commands() {
+ echo "perf help commands test"
+ if ! perf help > "${out}" 2>&1; then
+ echo "perf help commands test [Failed: perf help failed]"
+ cat "${out}"
+ err=1
+ return
+ fi
+ if ! grep -q "The most commonly used perf commands are" "${out}"; then
+ echo "perf help commands test [Failed missing command list]"
+ cat "${out}"
+ err=1
+ return
+ fi
+ if ! grep -q "See 'perf help COMMAND'" "${out}"; then
+ echo "perf help commands test [Failed missing help hint]"
+ err=1
+ return
+ fi
+ echo "perf help commands test [Success]"
+}
+
+test_help_all() {
+ echo "perf help -a test"
+ # "available perf commands in" is printed only when the exec path holds
+ # perf-* commands, which a build tree does not have. Give help -a a
+ # temporary exec path with a dummy command to look for.
+ exec_path=$(mktemp -d /tmp/__perf_test_help_exec.XXXXXX)
+ printf '#!/bin/sh\n' > "${exec_path}/perf-dummy"
+ chmod +x "${exec_path}/perf-dummy"
+ if ! PERF_EXEC_PATH="${exec_path}" perf help -a > "${out}" 2>&1; then
+ echo "perf help -a test [Failed: perf help -a failed]"
+ cat "${out}"
+ err=1
+ return
+ fi
+ if ! grep -q "available perf commands in" "${out}"; then
+ echo "perf help -a test [Failed missing command directory]"
+ cat "${out}"
+ err=1
+ return
+ fi
+ if ! grep -q " dummy" "${out}"; then
+ echo "perf help -a test [Failed missing command from exec path]"
+ cat "${out}"
+ err=1
+ return
+ fi
+ echo "perf help -a test [Success]"
+}
+
+test_help_commands
+test_help_all
+
+cleanup
+exit $err
--
2.56.0
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v1 04/17] perf tests config: Exercise the config file and list options
2026-11-24 18:45 [PATCH v1 00/17] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
` (2 preceding siblings ...)
2026-11-24 18:45 ` [PATCH v1 03/17] perf tests help: Add a basic perf help test Arnaldo Carvalho de Melo
@ 2026-11-24 18:45 ` Arnaldo Carvalho de Melo
2026-11-24 18:45 ` [PATCH v1 05/17] perf tests script: Exercise the list, fields and dump options Arnaldo Carvalho de Melo
` (12 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-11-24 18:45 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, linux-kernel, linux-perf-users,
Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Set, read back, update and list two variables under a private HOME,
and check the --user/--system conflict and the invalid key errors.
perf test exports PERF_CONFIG=/dev/null to the shell tests, unset it
so perf config uses the private file.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/shell/config.sh | 134 +++++++++++++++++++++++++++++++
1 file changed, 134 insertions(+)
create mode 100755 tools/perf/tests/shell/config.sh
diff --git a/tools/perf/tests/shell/config.sh b/tools/perf/tests/shell/config.sh
new file mode 100755
index 0000000000000000..fc035bbec2e2ea18
--- /dev/null
+++ b/tools/perf/tests/shell/config.sh
@@ -0,0 +1,134 @@
+#!/bin/bash
+# perf config tests
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+err=0
+tmpdir=$(mktemp -d /tmp/__perf_test_config.XXXXXX)
+out="${tmpdir}/out"
+
+# perf test exports PERF_CONFIG=/dev/null to the shell tests, use a
+# private HOME instead so the file written here is the one being read.
+unset PERF_CONFIG
+export HOME="${tmpdir}"
+
+cleanup() {
+ rm -rf "${tmpdir}"
+
+ trap - EXIT TERM INT
+}
+
+trap_cleanup() {
+ echo "Unexpected signal in ${FUNCNAME[1]}"
+ cleanup
+ exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
+test_config_empty() {
+ echo "Empty config test"
+ if ! perf config --user --list > "${out}" 2>&1; then
+ echo "Empty config [Failed: perf config --user --list failed]"
+ cat "${out}"
+ err=1
+ return
+ fi
+ if [ -s "${out}" ]; then
+ echo "Empty config [Failed: unexpected output]"
+ cat "${out}"
+ err=1
+ return
+ fi
+ echo "Empty config [Success]"
+}
+
+test_config_set_get() {
+ echo "Config set and get test"
+ if ! perf config report.show-nr-samples=true call-graph.print-limit=5; then
+ echo "Config set [Failed: perf config failed]"
+ err=1
+ return
+ fi
+ if [ ! -s "${HOME}/.perfconfig" ]; then
+ echo "Config set [Failed: no config file]"
+ err=1
+ return
+ fi
+
+ if ! perf config --user report.show-nr-samples | grep -qx "report.show-nr-samples=true"; then
+ echo "Config get [Failed: wrong report.show-nr-samples]"
+ err=1
+ return
+ fi
+ if ! perf config --user call-graph.print-limit | grep -qx "call-graph.print-limit=5"; then
+ echo "Config get [Failed: wrong call-graph.print-limit]"
+ err=1
+ return
+ fi
+
+ if ! perf config --user --list > "${out}" 2>&1 ||
+ ! grep -qx "report.show-nr-samples=true" "${out}" ||
+ ! grep -qx "call-graph.print-limit=5" "${out}"; then
+ echo "Config list [Failed: missing variables]"
+ cat "${out}"
+ err=1
+ return
+ fi
+ if ! perf config --list > "${out}" 2>&1 ||
+ ! grep -qx "report.show-nr-samples=true" "${out}"; then
+ echo "Config list [Failed: missing user variable in the merged view]"
+ cat "${out}"
+ err=1
+ return
+ fi
+
+ if ! perf config report.show-nr-samples=false; then
+ echo "Config update [Failed: perf config failed]"
+ err=1
+ return
+ fi
+ if ! perf config report.show-nr-samples | grep -qx "report.show-nr-samples=false"; then
+ echo "Config update [Failed: value not updated]"
+ err=1
+ return
+ fi
+ echo "Config set and get test [Success]"
+}
+
+test_config_errors() {
+ echo "Config error test"
+ if perf config --user --system --list > "${out}" 2>&1; then
+ echo "Config error [Failed: --user --system succeeded]"
+ cat "${out}"
+ err=1
+ return
+ fi
+ if ! grep -q "only one config file at a time" "${out}"; then
+ echo "Config error [Failed: missing file option error]"
+ cat "${out}"
+ err=1
+ return
+ fi
+
+ if perf config nosection > "${out}" 2>&1; then
+ echo "Config error [Failed: invalid variable succeeded]"
+ cat "${out}"
+ err=1
+ return
+ fi
+ if ! grep -q "does not contain a section name" "${out}"; then
+ echo "Config error [Failed: missing invalid variable error]"
+ cat "${out}"
+ err=1
+ return
+ fi
+ echo "Config error test [Success]"
+}
+
+test_config_empty
+test_config_set_get
+test_config_errors
+
+cleanup
+exit $err
--
2.56.0
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v1 05/17] perf tests script: Exercise the list, fields and dump options
2026-11-24 18:45 [PATCH v1 00/17] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
` (3 preceding siblings ...)
2026-11-24 18:45 ` [PATCH v1 04/17] perf tests config: Exercise the config file and list options Arnaldo Carvalho de Melo
@ 2026-11-24 18:45 ` Arnaldo Carvalho de Melo
2026-11-24 18:45 ` [PATCH v1 06/17] perf tests sort: Exercise the report and diff sort keys Arnaldo Carvalho de Melo
` (11 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-11-24 18:45 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, linux-kernel, linux-perf-users,
Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
The script test only runs the parallel-perf script. Cover the script
list, a wide -F field set and the +field/-field syntax, per-event dumps,
the data file header, the task and mmap event display and the reltime,
deltatime, show-info, latency, ns and raw dump options.
The list is read from the scripts dir in the perf exec path, which in a
build tree points at a prefix that was never installed, so point
PERF_EXEC_PATH at the source tree when it is unset. A missing python3
or parallel-perf.py is a skip only when nothing failed above, otherwise
the exit status hides the failure behind an exit 2, which perf test
reports as skipped.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/shell/script.sh | 131 ++++++++++++++++++++++++++++++-
1 file changed, 129 insertions(+), 2 deletions(-)
diff --git a/tools/perf/tests/shell/script.sh b/tools/perf/tests/shell/script.sh
index af687c7cfe44c2c6..a74d45d51ae47cb1 100755
--- a/tools/perf/tests/shell/script.sh
+++ b/tools/perf/tests/shell/script.sh
@@ -4,6 +4,22 @@
set -e
+shelldir=$(dirname "$0")
+# shellcheck source=lib/perf_has_symbol.sh
+. "${shelldir}"/lib/perf_has_symbol.sh
+
+# perf script -l reads the scripts directory from the perf exec path,
+# which in a build tree points at a prefix that is not installed
+if [ -z "${PERF_EXEC_PATH}" ] && [ -d "${shelldir}"/../../python ]; then
+ PERF_EXEC_PATH=$(cd "${shelldir}"/../.. && pwd)
+ export PERF_EXEC_PATH
+fi
+
+testprog="perf test -w thloop"
+testsym="test_loop"
+
+skip_test_missing_symbol "${testsym}"
+
temp_dir=$(mktemp -d /tmp/perf-test-script.XXXXXXXXXX)
err=0
@@ -27,18 +43,123 @@ trap_cleanup()
trap trap_cleanup EXIT TERM INT
+script_data="${temp_dir}/script-perf.data"
+
+test_script_list()
+{
+ echo "perf script list test"
+ if ! perf script -l | grep -q "List of available scripts"
+ then
+ echo "perf script list test [Failed missing list header]"
+ err=1
+ return
+ fi
+ if ! perf script -l | grep -q "export-to-sqlite"
+ then
+ echo "perf script list test [Failed missing export-to-sqlite]"
+ err=1
+ fi
+}
+
+test_script_fields()
+{
+ echo "perf script fields test"
+ perf record -o "${script_data}" -e cpu-clock --sample-cpu ${testprog}
+ if ! perf script -i "${script_data}" -F comm,tid,pid,time,cpu,event,ip,sym,dso,dsoff,symoff,period,machine_pid,vcpu,ipc,insn,insnlen,disasm,misc,metric,synth,callindent,flags | grep -q "${testsym}"
+ then
+ echo "perf script fields test [Failed missing ${testsym}]"
+ err=1
+ return
+ fi
+ if ! perf script -i "${script_data}" -F +cpu | grep -q "${testsym}"
+ then
+ echo "perf script fields test [Failed to add the cpu field]"
+ err=1
+ fi
+ if ! perf script -i "${script_data}" -F -comm | grep -q "${testsym}"
+ then
+ echo "perf script fields test [Failed to remove the comm field]"
+ err=1
+ fi
+}
+
+test_script_per_event_dump()
+{
+ echo "perf script per-event dump test"
+ if ! perf script -i "${script_data}" --per-event-dump > /dev/null
+ then
+ echo "perf script per-event dump test [Failed to write the dumps]"
+ err=1
+ return
+ fi
+ if ! grep -q "${testsym}" "${script_data}".*.dump
+ then
+ echo "perf script per-event dump test [Failed missing ${testsym}]"
+ err=1
+ fi
+}
+
+test_script_header()
+{
+ echo "perf script header test"
+ if ! perf script -i "${script_data}" --header | grep -q "captured on"
+ then
+ echo "perf script header test [Failed missing the header]"
+ err=1
+ return
+ fi
+ if ! perf script -i "${script_data}" --header-only | grep -q "captured on"
+ then
+ echo "perf script header test [Failed missing the header only output]"
+ err=1
+ fi
+}
+
+test_script_events()
+{
+ echo "perf script events test"
+ if ! perf script -i "${script_data}" --show-task-events --show-mmap-events | grep -q "PERF_RECORD_"
+ then
+ echo "perf script events test [Failed missing the events]"
+ err=1
+ fi
+}
+
+test_script_misc()
+{
+ echo "perf script misc options test"
+ for opt in --reltime --deltatime -I -L --ns
+ do
+ if ! perf script -i "${script_data}" ${opt} | grep -q "${testsym}"
+ then
+ echo "perf script misc options test [Failed ${opt}]"
+ err=1
+ fi
+ done
+ if ! perf script -i "${script_data}" -D | grep -q "PERF_RECORD_SAMPLE"
+ then
+ echo "perf script misc options test [Failed --dump-raw-trace]"
+ err=1
+ fi
+}
+
test_parallel_perf()
{
echo "parallel-perf test"
if ! python3 --version >/dev/null 2>&1 ; then
echo "SKIP: no python3"
- err=2
+ # Don't turn a failure in the tests above into a skip
+ if [ ${err} -eq 0 ]; then
+ err=2
+ fi
return
fi
pp=$(dirname "$0")/../../python/parallel-perf.py
if [ ! -f "${pp}" ] ; then
echo "SKIP: parallel-perf.py script not found "
- err=2
+ if [ ${err} -eq 0 ]; then
+ err=2
+ fi
return
fi
perf_data="${temp_dir}/pp-perf.data"
@@ -50,6 +171,12 @@ test_parallel_perf()
echo "parallel-perf test [Success]"
}
+test_script_list
+test_script_fields
+test_script_per_event_dump
+test_script_header
+test_script_events
+test_script_misc
test_parallel_perf
cleanup
--
2.56.0
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v1 06/17] perf tests sort: Exercise the report and diff sort keys
2026-11-24 18:45 [PATCH v1 00/17] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
` (4 preceding siblings ...)
2026-11-24 18:45 ` [PATCH v1 05/17] perf tests script: Exercise the list, fields and dump options Arnaldo Carvalho de Melo
@ 2026-11-24 18:45 ` Arnaldo Carvalho de Melo
2026-11-24 18:45 ` [PATCH v1 07/17] perf tests diff: Exercise the output options Arnaldo Carvalho de Melo
` (10 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-11-24 18:45 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, linux-kernel, linux-perf-users,
Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
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@redhat.com>
---
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
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v1 07/17] perf tests diff: Exercise the output options
2026-11-24 18:45 [PATCH v1 00/17] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
` (5 preceding siblings ...)
2026-11-24 18:45 ` [PATCH v1 06/17] perf tests sort: Exercise the report and diff sort keys Arnaldo Carvalho de Melo
@ 2026-11-24 18:45 ` Arnaldo Carvalho de Melo
2026-11-24 18:45 ` [PATCH v1 08/17] perf tests annotate: Exercise the output and filter options Arnaldo Carvalho de Melo
` (9 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-11-24 18:45 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, linux-kernel, linux-perf-users,
Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
The diff test only diffs files recorded with the same workload. Add
the compute formulas, each checked by the column it prints, the
formula, period, field separator, sort and raw trace dump options, and
the time window, checked with a window that leaves nothing.
As delta-abs is the default compute, a plain diff prints its column as
well: the default header is pinned before the option runs, and the
delta-abs run then only checks that the option is accepted and that
the column is not dropped.
Record the third file with the noploop workload: with it the
baseline-only and order options can be checked on a second file whose
entries have no match in the baseline. The --percentage and --verbose
options only change the numbers when entries are filtered in the TUI
and the debug output, they run here as a check that the table is still
printed.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/shell/diff.sh | 191 +++++++++++++++++++++++++++++++--
1 file changed, 184 insertions(+), 7 deletions(-)
diff --git a/tools/perf/tests/shell/diff.sh b/tools/perf/tests/shell/diff.sh
index 88f37b8ef8936be4..d2fbc8a8c2c3680a 100755
--- a/tools/perf/tests/shell/diff.sh
+++ b/tools/perf/tests/shell/diff.sh
@@ -8,14 +8,18 @@ err=0
perfdata1=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
perfdata2=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
perfdata3=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
+diffout=$(mktemp /tmp/__perf_test.perf.diff.out.XXXXX)
testprog="perf test -w thloop"
+testprog2="perf test -w noploop"
shelldir=$(dirname "$0")
. "${shelldir}"/lib/perf_has_symbol.sh
testsym="test_loop"
+testsym2="noploop"
skip_test_missing_symbol ${testsym}
+skip_test_missing_symbol ${testsym2}
cleanup() {
rm -rf "${perfdata1}"
@@ -24,6 +28,7 @@ cleanup() {
rm -rf "${perfdata2}".old
rm -rf "${perfdata3}"
rm -rf "${perfdata3}".old
+ rm -f "${diffout}"
trap - EXIT TERM INT
}
@@ -36,13 +41,15 @@ trap trap_cleanup EXIT TERM INT
make_data() {
file="$1"
- if ! perf record -o "${file}" ${testprog} 2> /dev/null
+ prog="$2"
+ sym="$3"
+ if ! perf record -o "${file}" ${prog} 2> /dev/null
then
echo "Workload record [Failed record]" >&2
echo 1
return
fi
- if ! perf report -i "${file}" -q | grep -q "${testsym}"
+ if ! perf report -i "${file}" -q | grep -q "${sym}"
then
echo "Workload record [Failed missing output]" >&2
echo 1
@@ -53,12 +60,12 @@ make_data() {
test_two_files() {
echo "Basic two file diff test"
- err=$(make_data "${perfdata1}")
+ err=$(make_data "${perfdata1}" "${testprog}" "${testsym}")
if [ "$err" != 0 ]
then
return
fi
- err=$(make_data "${perfdata2}")
+ err=$(make_data "${perfdata2}" "${testprog}" "${testsym}")
if [ "$err" != 0 ]
then
return
@@ -75,17 +82,20 @@ test_two_files() {
test_three_files() {
echo "Basic three file diff test"
- err=$(make_data "${perfdata1}")
+ err=$(make_data "${perfdata1}" "${testprog}" "${testsym}")
if [ "$err" != 0 ]
then
return
fi
- err=$(make_data "${perfdata2}")
+ err=$(make_data "${perfdata2}" "${testprog}" "${testsym}")
if [ "$err" != 0 ]
then
return
fi
- err=$(make_data "${perfdata3}")
+ # The third file is recorded with another workload, so that the
+ # baseline-only and order option checks below can tell which entries
+ # are shown and in what order.
+ err=$(make_data "${perfdata3}" "${testprog2}" "${testsym2}")
if [ $err != 0 ]
then
return
@@ -100,8 +110,175 @@ test_three_files() {
echo "Basic three file diff test [Success]"
}
+test_options() {
+ echo "Diff options test"
+
+ # delta-abs is the default compute, so a plain diff prints the same
+ # header: pin it here, the option run below then only checks that
+ # --compute delta-abs is accepted and still prints its column
+ if ! perf diff "${perfdata1}" "${perfdata2}" | \
+ grep -qE 'Baseline[[:space:]]+Delta Abs[[:space:]]+Shared Object'
+ then
+ echo "Diff options test [Failed: default compute is not delta-abs]"
+ err=1
+ return
+ fi
+
+ # Every compute formula prints a column of its own
+ for compute in delta delta-abs ratio wdiff:1,2
+ do
+ case "${compute}" in
+ delta) expect='Delta[[:space:]]+Shared Object' ;;
+ delta-abs) expect='Delta Abs' ;;
+ ratio) expect='Ratio' ;;
+ wdiff:1,2) expect='Weighted diff' ;;
+ esac
+ if ! perf diff --compute "${compute}" "${perfdata1}" "${perfdata2}" | \
+ grep -qE "${expect}"
+ then
+ echo "Diff options test [Failed: --compute ${compute}]"
+ err=1
+ return
+ fi
+ done
+
+ if ! perf diff -F "${perfdata1}" "${perfdata2}" | grep -q "Formula"
+ then
+ echo "Diff options test [Failed: --formula]"
+ err=1
+ return
+ fi
+
+ if ! perf diff -p "${perfdata1}" "${perfdata2}" | grep -q "Base period"
+ then
+ echo "Diff options test [Failed: --period]"
+ err=1
+ return
+ fi
+
+ # -b keeps the entries matched in the baseline: with two files of
+ # the same workload the loop entry stays
+ if ! perf diff -b "${perfdata1}" "${perfdata2}" | grep -q "${testsym}"
+ then
+ echo "Diff options test [Failed: --baseline-only drops common entries]"
+ err=1
+ return
+ fi
+
+ # The noploop workload is only in the third file
+ if ! perf diff "${perfdata1}" "${perfdata3}" > "${diffout}" 2> /dev/null
+ then
+ echo "Diff options test [Failed: diff of different workloads]"
+ err=1
+ return
+ fi
+ if ! grep -q "${testsym2}" "${diffout}"
+ then
+ echo "Diff options test [Failed: ${testsym2} missing from the diff]"
+ err=1
+ return
+ fi
+
+ # and with a second file recorded with another workload its entries
+ # have no match in the baseline and disappear
+ if ! perf diff -b "${perfdata1}" "${perfdata3}" > "${diffout}" 2> /dev/null
+ then
+ echo "Diff options test [Failed: --baseline-only]"
+ err=1
+ return
+ fi
+ if grep -q "${testsym2}" "${diffout}"
+ then
+ echo "Diff options test [Failed: --baseline-only shows non-baseline entries]"
+ err=1
+ return
+ fi
+
+ if ! perf diff -t, "${perfdata1}" "${perfdata2}" | grep -q "Baseline,"
+ then
+ echo "Diff options test [Failed: --field-separator]"
+ err=1
+ return
+ fi
+
+ # -o 0 puts the entry with the biggest baseline first, the loop in
+ # the first file, while the default starts with the loop in the
+ # second file
+ if ! perf diff -o 0 "${perfdata1}" "${perfdata3}" > "${diffout}" 2> /dev/null
+ then
+ echo "Diff options test [Failed: --order]"
+ err=1
+ return
+ fi
+ if ! grep -v '^#' "${diffout}" | grep -v '^[[:space:]]*$' | head -1 | \
+ grep -q "${testsym}"
+ then
+ echo "Diff options test [Failed: --order 0 does not sort by the baseline]"
+ err=1
+ return
+ fi
+
+ # A window starting at the beginning of the data shows it all, a
+ # window starting after the last sample shows nothing
+ if ! perf diff --time 0, "${perfdata1}" "${perfdata2}" | grep -q "${testsym}"
+ then
+ echo "Diff options test [Failed: --time]"
+ err=1
+ return
+ fi
+ if perf diff --time 9000000000000000000, "${perfdata1}" "${perfdata2}" | \
+ grep -q "${testsym}"
+ then
+ echo "Diff options test [Failed: --time shows samples outside the window]"
+ err=1
+ return
+ fi
+
+ # --percentage only shows up when entries are filtered in the TUI
+ # and --verbose only adds debug output, check the table is printed
+ if ! perf diff --percentage relative "${perfdata1}" "${perfdata2}" | grep -q "${testsym}"
+ then
+ echo "Diff options test [Failed: --percentage relative]"
+ err=1
+ return
+ fi
+
+ if ! perf diff --percentage absolute "${perfdata1}" "${perfdata2}" | grep -q "${testsym}"
+ then
+ echo "Diff options test [Failed: --percentage absolute]"
+ err=1
+ return
+ fi
+
+ if ! perf diff -s comm "${perfdata1}" "${perfdata2}" | grep -q "Command"
+ then
+ echo "Diff options test [Failed: --sort comm]"
+ err=1
+ return
+ fi
+
+ if ! perf diff -v "${perfdata1}" "${perfdata2}" 2> /dev/null | \
+ grep -q "${testsym}"
+ then
+ echo "Diff options test [Failed: --verbose]"
+ err=1
+ return
+ fi
+
+ if ! perf diff --dump-raw-trace "${perfdata1}" "${perfdata2}" 2>&1 | \
+ grep -q "PERF_RECORD_SAMPLE"
+ then
+ echo "Diff options test [Failed: --dump-raw-trace]"
+ err=1
+ return
+ fi
+
+ echo "Diff options test [Success]"
+}
+
test_two_files
test_three_files
+test_options
cleanup
exit $err
--
2.56.0
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v1 08/17] perf tests annotate: Exercise the output and filter options
2026-11-24 18:45 [PATCH v1 00/17] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
` (6 preceding siblings ...)
2026-11-24 18:45 ` [PATCH v1 07/17] perf tests diff: Exercise the output options Arnaldo Carvalho de Melo
@ 2026-11-24 18:45 ` Arnaldo Carvalho de Melo
2026-11-24 18:45 ` [PATCH v1 09/17] perf tests report: Exercise the output and format options Arnaldo Carvalho de Melo
` (8 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-11-24 18:45 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, linux-kernel, linux-perf-users,
Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
The annotate test covers the stdio and pipe modes. Add the --stdio2
output, --print-line, --asm-raw with --show-total-period,
--show-nr-samples, --percent-type and the DSO filter, the last one
checked by also annotating through a DSO that is not in the data.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/shell/annotate.sh | 64 ++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/tools/perf/tests/shell/annotate.sh b/tools/perf/tests/shell/annotate.sh
index 26411edf5cb4ece1..d799414690402fc0 100755
--- a/tools/perf/tests/shell/annotate.sh
+++ b/tools/perf/tests/shell/annotate.sh
@@ -105,8 +105,72 @@ test_basic() {
echo "${mode} annotate test [Success]"
}
+test_options() {
+ echo "Options annotate test"
+ perf record -o "${perfdata}" ${testprog} 2> /dev/null
+
+ # --stdio2 prints each instruction with the symbol header
+ if ! perf annotate -i "${perfdata}" --stdio2 -s "${testsym}" 2> /dev/null | grep -q "${testsym}()"
+ then
+ echo "Options annotate [Failed: missing --stdio2 output]"
+ err=1
+ return
+ fi
+
+ # -l/--print-line prints a summary of the annotated file with source lines
+ if ! perf annotate -i "${perfdata}" --stdio --print-line -s "${testsym}" 2> /dev/null | grep -q "Sorted summary for file"
+ then
+ echo "Options annotate [Failed: missing --print-line output]"
+ err=1
+ return
+ fi
+
+ # --show-total-period adds a period column; --asm-raw is the default
+ if ! perf annotate -i "${perfdata}" --stdio --asm-raw --show-total-period -s "${testsym}" 2> /dev/null | grep -q "Period"
+ then
+ echo "Options annotate [Failed: missing --show-total-period output]"
+ err=1
+ return
+ fi
+
+ # --show-nr-samples adds a samples column
+ if ! perf annotate -i "${perfdata}" --stdio -n -s "${testsym}" 2> /dev/null | grep -q "Samples"
+ then
+ echo "Options annotate [Failed: missing --show-nr-samples output]"
+ err=1
+ return
+ fi
+
+ # --percent-type selects the percentage type shown in the header
+ if ! perf annotate -i "${perfdata}" --stdio --percent-type global-period -s "${testsym}" 2> /dev/null | grep -q "percent: global period"
+ then
+ echo "Options annotate [Failed: missing --percent-type output]"
+ err=1
+ return
+ fi
+
+ # -d limits the annotation to the given DSO: perf has the symbol, a
+ # DSO absent from the data produces no annotation
+ if ! perf annotate -i "${perfdata}" --stdio -s "${testsym}" -d perf 2> /dev/null | grep -q "Disassembly of"
+ then
+ echo "Options annotate [Failed: missing -d output]"
+ err=1
+ return
+ fi
+
+ if perf annotate -i "${perfdata}" --stdio -s "${testsym}" -d nonexistent-dso 2> /dev/null | grep -q "Disassembly of"
+ then
+ echo "Options annotate [Failed: -d did not filter the DSO]"
+ err=1
+ return
+ fi
+
+ echo "Options annotate test [Success]"
+}
+
test_basic Basic
test_basic Pipe
+test_options
cleanup
exit $err
--
2.56.0
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v1 09/17] perf tests report: Exercise the output and format options
2026-11-24 18:45 [PATCH v1 00/17] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
` (7 preceding siblings ...)
2026-11-24 18:45 ` [PATCH v1 08/17] perf tests annotate: Exercise the output and filter options Arnaldo Carvalho de Melo
@ 2026-11-24 18:45 ` Arnaldo Carvalho de Melo
2026-11-24 18:45 ` [PATCH v1 10/17] perf tests record: Exercise more record options Arnaldo Carvalho de Melo
` (7 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-11-24 18:45 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, linux-kernel, linux-perf-users,
Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Cover the Samples column -n adds, the field list, the field separator
and the fixed column widths, each checked in the header it prints, and
--no-children, checked against a file recorded with call graphs, where
the Children column it removes is visible. --disable-order is checked
by the rejection it triggers together with a latency field. The
options that change nothing in this output, -U, --percentage, --inline
and --full-source-path, run as a check that perf takes them and still
prints the table.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/shell/report_options.sh | 122 +++++++++++++++++++++++
1 file changed, 122 insertions(+)
create mode 100755 tools/perf/tests/shell/report_options.sh
diff --git a/tools/perf/tests/shell/report_options.sh b/tools/perf/tests/shell/report_options.sh
new file mode 100755
index 0000000000000000..7e2bdaca656ce5b2
--- /dev/null
+++ b/tools/perf/tests/shell/report_options.sh
@@ -0,0 +1,122 @@
+#!/bin/bash
+# perf report option 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"
+
+skip_test_missing_symbol "${testsym}"
+
+perfdata=$(mktemp /tmp/__perf_test_report_opts.perf.data.XXXXX)
+cgdata=$(mktemp /tmp/__perf_test_report_opts.cg.data.XXXXX)
+perfout=$(mktemp /tmp/__perf_test_report_opts.perf.out.XXXXX)
+err=0
+
+cleanup() {
+ rm -f "${perfdata}" "${perfdata}".old
+ rm -f "${cgdata}" "${cgdata}".old
+ rm -f "${perfout}"
+
+ trap - EXIT TERM INT
+}
+
+trap_cleanup() {
+ echo "Unexpected signal in ${FUNCNAME[1]}"
+ cleanup
+ exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
+check_report() {
+ local desc="$1" expect="$2"
+
+ shift 2
+ echo "Report ${desc}"
+ if ! perf report -i "${perfdata}" --stdio "$@" > "${perfout}" 2>&1
+ then
+ echo "Report ${desc} [Failed: perf report failed]"
+ err=1
+ return
+ fi
+ if ! grep -qE "${expect}" "${perfout}"
+ then
+ echo "Report ${desc} [Failed: missing '${expect}']"
+ cat "${perfout}"
+ err=1
+ return
+ fi
+ echo "Report ${desc} [Success]"
+}
+
+# The call graph data, for --no-children: 'absent', when set, must not
+# be found in the output
+check_cg_report() {
+ local desc="$1" expect="$2" absent="$3"
+
+ shift 3
+ echo "Report ${desc}"
+ if ! perf report -i "${cgdata}" --stdio "$@" > "${perfout}" 2>&1
+ then
+ echo "Report ${desc} [Failed: perf report failed]"
+ err=1
+ return
+ fi
+ if [ -n "${absent}" ] && grep -qE "${absent}" "${perfout}"
+ then
+ echo "Report ${desc} [Failed: still has '${absent}']"
+ err=1
+ return
+ fi
+ if ! grep -qE "${expect}" "${perfout}"
+ then
+ echo "Report ${desc} [Failed: missing '${expect}']"
+ cat "${perfout}"
+ err=1
+ return
+ fi
+ echo "Report ${desc} [Success]"
+}
+
+perf record -q -e cpu-clock --sample-cpu -o "${perfdata}" ${testprog}
+
+# -n adds a Samples column, -t, joins the header fields with commas,
+# -w pads them to the given width. -U, --percentage, --inline and
+# --full-source-path change nothing in this output: every entry
+# resolves to a symbol, nothing is filtered and no source lines are
+# printed, so they run to check that perf takes them and still prints
+# the table.
+check_report "nr samples" "Overhead[[:space:]]+Samples" -n
+check_report "hide unresolved" "^# Overhead" -U
+check_report "fields" "^ *perf " -F comm,dso,symbol,period
+check_report "percentage" "^# Overhead" --percentage absolute
+check_report "field separator" "^# Overhead," -t,
+check_report "inline" "^# Overhead" --inline
+check_report "full source path" "^# Overhead" --full-source-path
+check_report "column widths" "^# {2,}Overhead" -w 20,20,20,20,20,20
+
+# --disable-order is rejected together with a latency field, which
+# tells that the option reached the event ordering code
+echo "Report disable order"
+if ! perf report -i "${perfdata}" --stdio -F latency --disable-order 2>&1 | \
+ grep -q "incompatible with --disable-order"
+then
+ echo "Report disable order [Failed: missing the rejection]"
+ err=1
+else
+ echo "Report disable order [Success]"
+fi
+
+# Recording call graphs adds a Children column, --no-children must
+# remove it while keeping the entries
+perf record -q --call-graph fp -e cpu-clock --sample-cpu -o "${cgdata}" ${testprog}
+check_cg_report "children column" "Children" ""
+check_cg_report "no children" "${testsym}" "Children" --no-children
+
+cleanup
+exit $err
--
2.56.0
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v1 10/17] perf tests record: Exercise more record options
2026-11-24 18:45 [PATCH v1 00/17] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
` (8 preceding siblings ...)
2026-11-24 18:45 ` [PATCH v1 09/17] perf tests report: Exercise the output and format options Arnaldo Carvalho de Melo
@ 2026-11-24 18:45 ` Arnaldo Carvalho de Melo
2026-11-24 18:45 ` [PATCH v1 11/17] perf tests trace: Exercise the tracing options Arnaldo Carvalho de Melo
` (6 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-11-24 18:45 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, linux-kernel, linux-perf-users,
Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Add the dry-run, no samples, buildid, synthesis, sampling, buffering,
aio, affinity, delay, overwrite, callchain, mmap pages and clockid
variants.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/shell/record_options.sh | 173 +++++++++++++++++++++++
1 file changed, 173 insertions(+)
create mode 100755 tools/perf/tests/shell/record_options.sh
diff --git a/tools/perf/tests/shell/record_options.sh b/tools/perf/tests/shell/record_options.sh
new file mode 100755
index 0000000000000000..b2bf51b5dc44c189
--- /dev/null
+++ b/tools/perf/tests/shell/record_options.sh
@@ -0,0 +1,173 @@
+#!/bin/bash
+# perf record option tests
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+temp_dir=$(mktemp -d /tmp/__perf_test_record_opts.XXXXXX)
+err=0
+
+cleanup() {
+ rm -rf "${temp_dir}"
+
+ trap - EXIT TERM INT
+}
+
+trap_cleanup() {
+ echo "Unexpected signal in ${FUNCNAME[1]}"
+ cleanup
+ exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
+test_record() {
+ local desc="$1" out="$2"
+
+ shift 2
+ echo "Record ${desc}"
+ if ! perf record -q -e cpu-clock -c 1 "$@" -o "${temp_dir}/${out}" -- sleep 0.1
+ then
+ echo "Record ${desc} [Failed: perf record failed]"
+ err=1
+ return
+ fi
+ if ! perf report -i "${temp_dir}/${out}" -q 2> /dev/null | grep -q sleep
+ then
+ echo "Record ${desc} [Failed: no samples]"
+ err=1
+ return
+ fi
+ echo "Record ${desc} [Success]"
+}
+
+test_timestamp_filename() {
+ echo "Record timestamp filename"
+ if ! perf record -q -e cpu-clock -c 1 --timestamp-filename \
+ -o "${temp_dir}/tsfn" -- sleep 0.1
+ then
+ echo "Record timestamp filename [Failed: perf record failed]"
+ err=1
+ return
+ fi
+ if ! ls "${temp_dir}/tsfn".* > /dev/null 2>&1
+ then
+ echo "Record timestamp filename [Failed: no timestamped file]"
+ err=1
+ return
+ fi
+ echo "Record timestamp filename [Success]"
+}
+
+test_switch_output() {
+ echo "Record switch output"
+ if ! perf record -q -e cpu-clock -c 1 --switch-output=size=64K \
+ -o "${temp_dir}/sw" -- sleep 0.2
+ then
+ echo "Record switch output [Failed: perf record failed]"
+ err=1
+ return
+ fi
+ if ! ls "${temp_dir}/sw".* > /dev/null 2>&1
+ then
+ echo "Record switch output [Failed: no switched files]"
+ err=1
+ return
+ fi
+ echo "Record switch output [Success]"
+}
+
+test_clockid() {
+ echo "Record clockid"
+ if ! perf record -q -e cpu-clock -c 1 -k CLOCK_MONOTONIC \
+ -o "${temp_dir}/clock" -- sleep 0.1
+ then
+ echo "Record clockid [Failed: perf record failed]"
+ err=1
+ return
+ fi
+ if ! perf script -i "${temp_dir}/clock" -F tod 2> /dev/null | \
+ grep -qE '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
+ then
+ echo "Record clockid [Failed: no wall clock timestamps]"
+ err=1
+ return
+ fi
+ echo "Record clockid [Success]"
+}
+
+test_record_option() {
+ local desc="$1"
+
+ shift 1
+ echo "Record option ${desc}"
+ rm -f "${temp_dir}/${desc}.data"
+ if ! perf record -q -e cpu-clock -c 1 "$@" -o "${temp_dir}/${desc}.data" -- sleep 0.1
+ then
+ echo "Record option ${desc} [Failed: perf record failed]"
+ err=1
+ return
+ fi
+ if [ ! -s "${temp_dir}/${desc}.data" ]
+ then
+ echo "Record option ${desc} [Failed: no data recorded]"
+ err=1
+ return
+ fi
+ echo "Record option ${desc} [Success]"
+}
+
+test_dry_run() {
+ echo "Record option dry run"
+ if ! perf record -q -e cpu-clock -c 1 --dry-run \
+ -o "${temp_dir}/dry-run.data" -- sleep 0.1
+ then
+ echo "Record option dry run [Failed: perf record failed]"
+ err=1
+ return
+ fi
+ if [ -e "${temp_dir}/dry-run.data" ]
+ then
+ echo "Record option dry run [Failed: recorded data]"
+ err=1
+ return
+ fi
+ echo "Record option dry run [Success]"
+}
+
+test_record "aio" "aio" --aio=2
+test_record "threads core" "threads-core" --threads=core
+test_record "threads package" "threads-package" --threads=package
+test_record "threads numa" "threads-numa" --threads=numa
+test_record "affinity" "affinity" --affinity=cpu
+test_record "mmap flush" "mmap-flush" --mmap-flush=1
+test_record "max size" "max-size" --max-size=1M
+test_record "timestamp boundary" "ts-boundary" --timestamp-boundary
+test_record "user callchains" "callchains" --user-callchains --call-graph fp
+test_timestamp_filename
+test_switch_output
+test_clockid
+test_dry_run
+test_record_option no-samples -n
+test_record_option buildid-all --buildid-all
+test_record_option buildid-mmap --buildid-mmap
+test_record_option synth-no --synth no
+test_record_option synth-task --synth task
+test_record_option synth-mmap --synth mmap
+test_record_option sample-cpu --sample-cpu
+test_record_option weight -W
+test_record_option raw-samples -R
+test_record_option no-buffering --no-buffering
+test_record_option no-bpf-event --no-bpf-event
+test_record_option proc-map-timeout --proc-map-timeout 100
+test_record_option num-thread-synthesize --num-thread-synthesize 1
+test_record_option aio-one --aio=1
+test_record_option affinity-node --affinity=node
+test_record_option delay -D 10
+test_record_option tail-synthesize --tail-synthesize
+test_record_option overwrite --overwrite
+test_record_option data -d
+test_record_option mmap-pages -m 4,8
+test_record_option clockid-monotonic-raw -k CLOCK_MONOTONIC_RAW
+
+cleanup
+exit $err
--
2.56.0
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v1 11/17] perf tests trace: Exercise the tracing options
2026-11-24 18:45 [PATCH v1 00/17] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
` (9 preceding siblings ...)
2026-11-24 18:45 ` [PATCH v1 10/17] perf tests record: Exercise more record options Arnaldo Carvalho de Melo
@ 2026-11-24 18:45 ` Arnaldo Carvalho de Melo
2026-11-24 18:45 ` [PATCH v1 12/17] perf tests timechart: Exercise the report options Arnaldo Carvalho de Melo
` (5 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-11-24 18:45 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, linux-kernel, linux-perf-users,
Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Cover page faults, scheduler stats, syscall and failure summaries,
event limits, callchains, target filters and the remaining tracing
options. Like the summary test it needs root.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/shell/trace_options.sh | 97 +++++++++++++++++++++++++
1 file changed, 97 insertions(+)
create mode 100755 tools/perf/tests/shell/trace_options.sh
diff --git a/tools/perf/tests/shell/trace_options.sh b/tools/perf/tests/shell/trace_options.sh
new file mode 100755
index 0000000000000000..3f686a293bb9d557
--- /dev/null
+++ b/tools/perf/tests/shell/trace_options.sh
@@ -0,0 +1,97 @@
+#!/bin/bash
+# perf trace option tests
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+. "$(dirname $0)"/lib/probe.sh
+
+skip_if_no_perf_trace || exit 2
+
+# The syscall tracepoints need root to open.
+if [ "$(id -u)" != 0 ]; then
+ echo "[Skip] No root permission"
+ exit 2
+fi
+
+err=0
+out=$(mktemp /tmp/__perf_test_trace_opts.out.XXXXX)
+
+cleanup() {
+ rm -f "${out}"
+
+ trap - EXIT TERM INT
+}
+
+trap_cleanup() {
+ echo "Unexpected signal in ${FUNCNAME[1]}"
+ cleanup
+ exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
+run_trace() {
+ local desc="$1" expect="$2"
+
+ shift 2
+ echo "Trace ${desc}"
+ if ! perf trace "$@" > "${out}" 2>&1; then
+ echo "Trace ${desc} [Failed: perf trace failed]"
+ cat "${out}"
+ err=1
+ return
+ fi
+ if [ -n "${expect}" ] && ! grep -qE "${expect}" "${out}"; then
+ echo "Trace ${desc} [Failed: missing '${expect}']"
+ cat "${out}"
+ err=1
+ return
+ fi
+ echo "Trace ${desc} [Success]"
+}
+
+# Page faults are software events, not syscalls, and exercise the
+# separate page fault printing path.
+run_trace "pagefaults" "fault \[" -F all -- perf test -w noploop 1
+run_trace "minor pagefaults" "fault \[" -F min -- perf test -w noploop 1
+run_trace "major pagefaults" "" -F maj -- sleep 0.1
+
+# sched_stat_runtime feeds the "sched" summary counters.
+run_trace "sched" "" --sched -s -- sleep 0.1
+
+run_trace "syscalls" "" --syscalls -- true
+run_trace "events" "openat" -e openat -e read -e write -- cat /dev/null
+run_trace "failure" "" --failure -- false
+run_trace "errno summary" "" --errno-summary -s -- cat /dev/null
+run_trace "summary" "" -S --summary-mode=total -- cat /dev/null
+run_trace "summary thread" "" -s --summary-mode=thread -- cat /dev/null
+run_trace "duration filter" "" --duration 0.01 -- cat /dev/null
+run_trace "max events" "" --max-events 5 -e write -- seq 1 100
+run_trace "sort events" "" --sort-events -e write -- echo hello
+run_trace "call graph" "" --call-graph fp --max-stack 5 --min-stack 1 \
+ -e write -- echo hello
+run_trace "kernel syscall graph" "" --kernel-syscall-graph \
+ --call-graph fp -e write -- echo hello
+run_trace "libtraceevent print" "" --libtraceevent_print \
+ -e kmem:kmalloc -- true
+run_trace "filter pids" "" --filter-pids 1 -- cat /dev/null
+run_trace "proc map timeout" "" --proc-map-timeout 100 -- cat /dev/null
+run_trace "mmap pages" "" -m 8 -- sleep 0.1
+run_trace "delay" "" -D 10 -- sleep 0.1
+run_trace "no inherit" "" --no-inherit -- sleep 0.1
+run_trace "uid" "" -u "$(id -un)" -- true
+run_trace "cpu" "" -C 0 -- sleep 0.1
+run_trace "pid" "" -p $$ -- sleep 0.1
+run_trace "tid" "" -t $$ -- sleep 0.1
+run_trace "verbose" "" -v -e write -- echo hello
+run_trace "bitmask list" "" --bitmask-list -e openat -- cat /dev/null
+run_trace "print sample" "" --print-sample -e write -- echo hello
+
+echo "Trace invalid pagefault type"
+if perf trace -F bogus -- true > "${out}" 2>&1; then
+ echo "Trace invalid pagefault type [Failed: accepted invalid value]"
+ err=1
+fi
+
+cleanup
+exit $err
--
2.56.0
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v1 12/17] perf tests timechart: Exercise the report options
2026-11-24 18:45 [PATCH v1 00/17] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
` (10 preceding siblings ...)
2026-11-24 18:45 ` [PATCH v1 11/17] perf tests trace: Exercise the tracing options Arnaldo Carvalho de Melo
@ 2026-11-24 18:45 ` Arnaldo Carvalho de Melo
2026-11-24 18:46 ` [PATCH v1 13/17] perf tests kmem: Add a basic perf kmem test Arnaldo Carvalho de Melo
` (4 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-11-24 18:45 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, linux-kernel, linux-perf-users,
Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Run the report with width, process count, topology, highlight,
process, power and tasks only, io and force options.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/shell/timechart.sh | 46 +++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/tools/perf/tests/shell/timechart.sh b/tools/perf/tests/shell/timechart.sh
index 40072b32171a9a1c..ec592e304cdedfd8 100755
--- a/tools/perf/tests/shell/timechart.sh
+++ b/tools/perf/tests/shell/timechart.sh
@@ -59,6 +59,33 @@ test_timechart() {
echo "perf timechart ${NAME} test [Success]"
}
+test_timechart_report_option() {
+ NAME=$1
+
+ shift 1
+ echo "perf timechart report ${NAME} test"
+
+ if ! perf timechart -i "${perfdata}" -o "${output}" "$@" > /dev/null 2>&1; then
+ echo "perf timechart report ${NAME} test [Failed: perf timechart command failed]"
+ err=1
+ return
+ fi
+
+ if [ ! -s "${output}" ]; then
+ echo "perf timechart report ${NAME} test [Failed: output file is empty or missing]"
+ err=1
+ return
+ fi
+
+ if ! grep -q "svg" "${output}"; then
+ echo "perf timechart report ${NAME} test [Failed: output doesn't look like SVG]"
+ err=1
+ return
+ fi
+
+ echo "perf timechart report ${NAME} test [Success]"
+}
+
if ! perf check feature -q libtraceevent ; then
echo "perf timechart is not supported. Skip."
cleanup
@@ -69,5 +96,24 @@ test_timechart "Basic" ""
test_timechart "IO-only" "-I"
test_timechart "Backtrace" "-g"
+if [ ! -s "${perfdata}" ]; then
+ echo "perf timechart report options [Skipped: no recorded data]"
+ cleanup
+ exit 0
+fi
+
+# Reuse the data recorded by the last test to exercise the report options.
+test_timechart_report_option "width" -w 1024
+test_timechart_report_option "proc-num" -n 4
+test_timechart_report_option "topology" -t
+test_timechart_report_option "highlight time" --highlight 1
+test_timechart_report_option "highlight name" --highlight true
+test_timechart_report_option "process" -p true
+test_timechart_report_option "power-only" -P
+test_timechart_report_option "tasks-only" -T
+test_timechart_report_option "io options" --io-min-time 1us \
+ --io-merge-dist 1us --io-skip-eagain
+test_timechart_report_option "force" -f
+
cleanup
exit $err
--
2.56.0
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v1 13/17] perf tests kmem: Add a basic perf kmem test
2026-11-24 18:45 [PATCH v1 00/17] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
` (11 preceding siblings ...)
2026-11-24 18:45 ` [PATCH v1 12/17] perf tests timechart: Exercise the report options Arnaldo Carvalho de Melo
@ 2026-11-24 18:46 ` Arnaldo Carvalho de Melo
2026-11-24 18:46 ` [PATCH v1 14/17] perf tests bench: Add smoke tests for perf bench Arnaldo Carvalho de Melo
` (3 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-11-24 18:46 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, linux-kernel, linux-perf-users,
Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Exercise the slab and page allocators, their sort, caller and
allocation views, the live page stats and the time filter.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/shell/kmem.sh | 215 +++++++++++++++++++++++++++++++++
1 file changed, 215 insertions(+)
create mode 100755 tools/perf/tests/shell/kmem.sh
diff --git a/tools/perf/tests/shell/kmem.sh b/tools/perf/tests/shell/kmem.sh
new file mode 100755
index 0000000000000000..c1eda5b2261f77ec
--- /dev/null
+++ b/tools/perf/tests/shell/kmem.sh
@@ -0,0 +1,215 @@
+#!/bin/bash
+# perf kmem tests
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+# Root permissions required for tracing events.
+if [ "$(id -u)" != 0 ]; then
+ echo "[Skip] No root permission"
+ exit 2
+fi
+
+if [ ! -e /sys/kernel/tracing/events/kmem/kmalloc ] &&
+ [ ! -e /sys/kernel/debug/tracing/events/kmem/kmalloc ]; then
+ echo "[Skip] No kmem tracepoints"
+ exit 2
+fi
+
+err=0
+slabdata=$(mktemp /tmp/__perf_test_kmem.slab.XXXXX)
+pagedata=$(mktemp /tmp/__perf_test_kmem.page.XXXXX)
+out=$(mktemp /tmp/__perf_test_kmem.out.XXXXX)
+
+cleanup() {
+ rm -f "${slabdata}" "${slabdata}".old
+ rm -f "${pagedata}" "${pagedata}".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
+
+fail() {
+ echo "$1 [Failed: $2]"
+ cat "${out}"
+ err=1
+}
+
+test_kmem_record() {
+ echo "Kmem record"
+ perf kmem record -o "${slabdata}" -- sleep 1
+ echo "Kmem record [Success]"
+}
+
+test_kmem_slab_stat() {
+ echo "Kmem slab stat"
+ if ! perf kmem -i "${slabdata}" stat > "${out}" 2>&1; then
+ fail "Kmem slab stat" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (SLAB allocator)" "${out}"; then
+ fail "Kmem slab stat" "missing summary"
+ return
+ fi
+ echo "Kmem slab stat [Success]"
+}
+
+test_kmem_slab_stat_options() {
+ echo "Kmem slab stat options"
+ if ! perf kmem -i "${slabdata}" --sort hit,bytes --line 5 stat > "${out}" 2>&1; then
+ fail "Kmem slab stat options" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (SLAB allocator)" "${out}"; then
+ fail "Kmem slab stat options" "missing summary"
+ return
+ fi
+ echo "Kmem slab stat options [Success]"
+}
+
+test_kmem_page_record() {
+ echo "Kmem page record"
+ perf kmem --page record -c 1000 -o "${pagedata}" -- sleep 1
+ echo "Kmem page record [Success]"
+}
+
+test_kmem_page_stat() {
+ echo "Kmem page stat"
+ if ! perf kmem --page -i "${pagedata}" stat > "${out}" 2>&1; then
+ fail "Kmem page stat" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (page allocator)" "${out}"; then
+ fail "Kmem page stat" "missing summary"
+ return
+ fi
+ echo "Kmem page stat [Success]"
+}
+
+test_kmem_page_stat_options() {
+ echo "Kmem page stat options"
+ if ! perf kmem --page -i "${pagedata}" --sort order,gfp --line 5 stat > "${out}" 2>&1; then
+ fail "Kmem page stat options" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (page allocator)" "${out}"; then
+ fail "Kmem page stat options" "missing summary"
+ return
+ fi
+ echo "Kmem page stat options [Success]"
+}
+
+test_kmem_slab_alloc() {
+ echo "Kmem slab alloc stats"
+ if ! perf kmem -i "${slabdata}" --alloc --sort bytes --line 5 stat > "${out}" 2>&1; then
+ fail "Kmem slab alloc stats" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (SLAB allocator)" "${out}"; then
+ fail "Kmem slab alloc stats" "missing summary"
+ return
+ fi
+ echo "Kmem slab alloc stats [Success]"
+}
+
+test_kmem_page_caller() {
+ echo "Kmem page caller stats"
+ if ! perf kmem --page -i "${pagedata}" --caller --sort bytes --line 5 stat > "${out}" 2>&1; then
+ fail "Kmem page caller stats" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (page allocator)" "${out}"; then
+ fail "Kmem page caller stats" "missing summary"
+ return
+ fi
+ echo "Kmem page caller stats [Success]"
+}
+
+test_kmem_page_caller_raw() {
+ echo "Kmem page caller raw ip stats"
+ if ! perf kmem --page -i "${pagedata}" --caller --raw-ip --sort callsite --line 5 stat > "${out}" 2>&1; then
+ fail "Kmem page caller raw ip stats" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (page allocator)" "${out}"; then
+ fail "Kmem page caller raw ip stats" "missing summary"
+ return
+ fi
+ echo "Kmem page caller raw ip stats [Success]"
+}
+
+test_kmem_page_alloc() {
+ echo "Kmem page alloc stats"
+ if ! perf kmem --page -i "${pagedata}" --alloc --sort bytes --line 5 stat > "${out}" 2>&1; then
+ fail "Kmem page alloc stats" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (page allocator)" "${out}"; then
+ fail "Kmem page alloc stats" "missing summary"
+ return
+ fi
+ echo "Kmem page alloc stats [Success]"
+}
+
+test_kmem_page_live() {
+ echo "Kmem page live stats"
+ if ! perf kmem --page --live -i "${pagedata}" --sort page --line 5 stat > "${out}" 2>&1; then
+ fail "Kmem page live stats" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (page allocator)" "${out}"; then
+ fail "Kmem page live stats" "missing summary"
+ return
+ fi
+ echo "Kmem page live stats [Success]"
+}
+
+test_kmem_slab_caller() {
+ echo "Kmem slab caller stats"
+ if ! perf kmem -i "${slabdata}" --caller --sort callsite --line 5 stat > "${out}" 2>&1; then
+ fail "Kmem slab caller stats" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (SLAB allocator)" "${out}"; then
+ fail "Kmem slab caller stats" "missing summary"
+ return
+ fi
+ echo "Kmem slab caller stats [Success]"
+}
+
+test_kmem_time_filter() {
+ echo "Kmem time filter"
+ if ! perf kmem -i "${slabdata}" --time 0, stat > "${out}" 2>&1; then
+ fail "Kmem time filter" "perf kmem stat failed"
+ return
+ fi
+ if ! grep -q "SUMMARY (SLAB allocator)" "${out}"; then
+ fail "Kmem time filter" "missing summary"
+ return
+ fi
+ echo "Kmem time filter [Success]"
+}
+
+test_kmem_record
+test_kmem_slab_stat
+test_kmem_slab_stat_options
+test_kmem_slab_alloc
+test_kmem_slab_caller
+test_kmem_time_filter
+test_kmem_page_record
+test_kmem_page_stat
+test_kmem_page_stat_options
+test_kmem_page_caller
+test_kmem_page_caller_raw
+test_kmem_page_alloc
+test_kmem_page_live
+
+cleanup
+exit $err
--
2.56.0
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v1 14/17] perf tests bench: Add smoke tests for perf bench
2026-11-24 18:45 [PATCH v1 00/17] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
` (12 preceding siblings ...)
2026-11-24 18:46 ` [PATCH v1 13/17] perf tests kmem: Add a basic perf kmem test Arnaldo Carvalho de Melo
@ 2026-11-24 18:46 ` Arnaldo Carvalho de Melo
2026-11-24 18:46 ` [PATCH v1 15/17] perf tests lock: Exercise perf lock report and info Arnaldo Carvalho de Melo
` (2 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-11-24 18:46 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, linux-kernel, linux-perf-users,
Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Run the numa, sched, futex, epoll, syscall, mem, internals, breakpoint
and uprobe benchmarks with small workloads, including the numa
convergence, perturbation and single node variants, and skip the ones
that need root or hardware that is not present.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/shell/bench.sh | 130 ++++++++++++++++++++++++++++++++
1 file changed, 130 insertions(+)
create mode 100755 tools/perf/tests/shell/bench.sh
diff --git a/tools/perf/tests/shell/bench.sh b/tools/perf/tests/shell/bench.sh
new file mode 100755
index 0000000000000000..7f5bca2c126a58aa
--- /dev/null
+++ b/tools/perf/tests/shell/bench.sh
@@ -0,0 +1,130 @@
+#!/bin/bash
+# perf bench tests
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+err=0
+out=$(mktemp /tmp/__perf_test_bench.out.XXXXX)
+
+cleanup() {
+ rm -f "${out}"
+
+ trap - EXIT TERM INT
+}
+
+trap_cleanup() {
+ echo "Unexpected signal in ${FUNCNAME[1]}"
+ cleanup
+ exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
+# Some benchmarks need root, others only report that the hardware is
+# not there, so treat the environment as a skip and a missing result
+# as a failure.
+bench_skip_reasons="No hardware support|perf_event_open: Permission denied"
+
+run_bench() {
+ local name="$1" expect="$2"
+
+ shift 2
+ echo "Bench ${name}"
+ if ! perf bench "$@" > "${out}" 2>&1; then
+ if grep -qE "${bench_skip_reasons}" "${out}"; then
+ echo "Bench ${name} [Skipped: not supported here]"
+ return
+ fi
+ echo "Bench ${name} [Failed: perf bench failed]"
+ cat "${out}"
+ err=1
+ return
+ fi
+ # A benchmark can also decline to run and exit 0, printing that
+ # the hardware is not there, as the breakpoint ones do; that is a
+ # skip, not a success
+ if grep -qE "${bench_skip_reasons}" "${out}"; then
+ echo "Bench ${name} [Skipped: not supported here]"
+ return
+ fi
+ if ! grep -qE "${expect}" "${out}"; then
+ echo "Bench ${name} [Failed missing '${expect}']"
+ cat "${out}"
+ err=1
+ return
+ fi
+ echo "Bench ${name} [Success]"
+}
+
+run_bench numa/mem "GB/sec" numa mem -p 2 -t 2 -P 2 -T 1 -s 1 -l 1
+run_bench numa/mem/options "GB/sec" numa mem -p 1 -t 1 -P 2 -s 1 -l 1 -c -d -r -z -B -R -W
+run_bench numa/mem/init "GB/sec" numa mem -p 1 -t 1 -P 2 -s 1 -l 1 -I -H 1 -S -u 1 -B -r -z -Z
+if taskset -c 0 true > /dev/null 2>&1; then
+ run_bench numa/mem/bind "GB/sec" numa mem -p 2 -t 2 -P 2 -T 1 -s 1 -l 1 -C 0,1 -M 0,0
+else
+ echo "Bench numa/mem/bind [Skipped: cpu 0 not available]"
+fi
+run_bench numa/mem/convergence "GB/sec" numa mem -p 1 -t 1 -P 512 -l 1 -s 1 -c -m
+run_bench numa/mem/perturb "GB/sec" numa mem -p 1 -t 1 -P 512 -l 1 -s 1 -x 1 -S -d -d
+run_bench numa/mem/zero "GB/sec" numa mem -p 1 -t 2 -T 64 -l 1 -s 1 -C 0 -M 0 -B -Z -H -1
+run_bench sched/messaging "Total time" sched messaging -g 1 -l 10
+run_bench sched/pipe "ops/sec" sched pipe -l 1000
+run_bench sched/seccomp-notify "ops/sec" sched seccomp-notify -l 10
+run_bench futex/hash "operations/sec" futex hash -t 2 -r 1 -s
+run_bench futex/wake "Wokeup" futex wake -t 2
+run_bench futex/wake-parallel "Avg per-thread latency" futex wake-parallel -t 2 -w 1
+run_bench futex/requeue "Requeued" futex requeue -t 2
+run_bench futex/lock-pi "operations/sec" futex lock-pi -t 2 -r 1
+run_bench epoll/wait "operations/sec" epoll wait -r 1 -t 2
+run_bench epoll/ctl "operations" epoll ctl -r 1 -t 2
+run_bench syscall/basic "ops/sec" syscall basic -l 100
+run_bench syscall/getpgid "ops/sec" syscall getpgid -l 100
+run_bench syscall/fork "ops/sec" syscall fork -l 10
+run_bench syscall/execve "ops/sec" syscall execve -l 10
+run_bench mem/memcpy "Copying" mem memcpy -s 4KB -l 1
+run_bench mem/memset "Copying" mem memset -s 4KB -l 1
+run_bench mem/mmap "Copying" mem mmap -s 4KB -l 1
+run_bench internals/synthesize "Average data synthesis took" internals synthesize -s -i 1
+run_bench internals/synthesize-mt "Average synthesis took" internals synthesize -t -m 1 -M 2 -I 1
+run_bench internals/kallsyms-parse "Average kallsyms__parse took" internals kallsyms-parse -i 1
+run_bench internals/inject-build-id "Average build-id injection took" internals inject-build-id -i 2 -m 2 -n 2
+run_bench internals/pmu-scan "Average PMU scanning took" internals pmu-scan -i 1
+run_bench breakpoint/thread "Created/joined" breakpoint thread -t 2 -b 2 -p 1
+run_bench breakpoint/enable "Enabled/disabled" breakpoint enable -p 1 -a 1
+run_bench uprobe/baseline "usecs/op" uprobe baseline -l 2
+
+if [ "$(id -u)" = 0 ]; then
+ run_bench internals/evlist-open-close "Number of events" internals evlist-open-close -i 2
+else
+ echo "Bench internals/evlist-open-close [Skipped: no root permission]"
+fi
+
+# The uprobe programs attach to usleep in libc, which needs BPF and,
+# on distributions using musl, is not available by that name.
+if perf version --build-options | grep -q 'bpf_skeletons: *\[ on' && [ "$(id -u)" = 0 ]; then
+ for mode in empty trace_printk empty_ret trace_printk_ret; do
+ echo "Bench uprobe/${mode}"
+ if ! perf bench uprobe "${mode}" -l 2 > "${out}" 2>&1; then
+ if grep -qE 'Failed to (attach bench uprobe|load and verify BPF skeleton)' "${out}"; then
+ echo "Bench uprobe/${mode} [Skipped: no uprobe support]"
+ continue
+ fi
+ echo "Bench uprobe/${mode} [Failed: perf bench failed]"
+ cat "${out}"
+ err=1
+ continue
+ fi
+ if ! grep -q "usecs/op" "${out}"; then
+ echo "Bench uprobe/${mode} [Failed missing result]"
+ cat "${out}"
+ err=1
+ continue
+ fi
+ echo "Bench uprobe/${mode} [Success]"
+ done
+else
+ echo "Bench uprobe [Skipped: needs root and BPF skeletons]"
+fi
+
+cleanup
+exit $err
--
2.56.0
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v1 15/17] perf tests lock: Exercise perf lock report and info
2026-11-24 18:45 [PATCH v1 00/17] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
` (13 preceding siblings ...)
2026-11-24 18:46 ` [PATCH v1 14/17] perf tests bench: Add smoke tests for perf bench Arnaldo Carvalho de Melo
@ 2026-11-24 18:46 ` Arnaldo Carvalho de Melo
2026-11-24 18:46 ` [PATCH v1 16/17] perf tests probe: Exercise the variable and line listing Arnaldo Carvalho de Melo
2026-11-24 18:46 ` [PATCH v1 17/17] perf tests report: Exercise the TUI browsers Arnaldo Carvalho de Melo
16 siblings, 0 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-11-24 18:46 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, linux-kernel, linux-perf-users,
Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
The lock contention test records and reads a perf.data file, but only
through perf lock contention. Walk the report sort keys, combine the
locks, and check the thread and lock lists of perf lock info on the
same file.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/shell/lock_contention.sh | 40 +++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/tools/perf/tests/shell/lock_contention.sh b/tools/perf/tests/shell/lock_contention.sh
index 5df9a0cd48a34f4f..a3056136e3767eec 100755
--- a/tools/perf/tests/shell/lock_contention.sh
+++ b/tools/perf/tests/shell/lock_contention.sh
@@ -65,6 +65,44 @@ test_record()
fi
}
+test_report()
+{
+ echo "Testing perf lock report"
+ # the output goes to the stderr and all keys are printed unless -F
+ # selects a subset, so walk the sort keys
+ for key in acquired contended avg_wait wait_total wait_max wait_min; do
+ perf lock report -i ${perfdata} -k ${key} -E 5 2> ${result}
+ if ! grep -q "Name" "${result}"; then
+ echo "[Fail] perf lock report --key ${key} has no output:" "$(cat "${result}")"
+ err=1
+ exit
+ fi
+ done
+
+ perf lock report -i ${perfdata} -c -v -E 5 2> ${result}
+ if ! grep -q "Name" "${result}"; then
+ echo "[Fail] perf lock report --combine-locks has no output:" "$(cat "${result}")"
+ err=1
+ exit
+ fi
+}
+
+test_info()
+{
+ echo "Testing perf lock info"
+ perf lock info -i ${perfdata} 2> ${result}
+ if ! grep -q "Thread ID" "${result}"; then
+ echo "[Fail] perf lock info has no thread list:" "$(cat "${result}")"
+ err=1
+ exit
+ fi
+ if ! grep -q "Address of instance" "${result}"; then
+ echo "[Fail] perf lock info has no lock list:" "$(cat "${result}")"
+ err=1
+ exit
+ fi
+}
+
test_bpf()
{
echo "Testing perf lock contention --use-bpf"
@@ -347,6 +385,8 @@ test_csv_output()
check
test_record
+test_report
+test_info
test_bpf
test_record_concurrent
test_aggr_task
--
2.56.0
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v1 16/17] perf tests probe: Exercise the variable and line listing
2026-11-24 18:45 [PATCH v1 00/17] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
` (14 preceding siblings ...)
2026-11-24 18:46 ` [PATCH v1 15/17] perf tests lock: Exercise perf lock report and info Arnaldo Carvalho de Melo
@ 2026-11-24 18:46 ` Arnaldo Carvalho de Melo
2026-11-24 18:46 ` [PATCH v1 17/17] perf tests report: Exercise the TUI browsers Arnaldo Carvalho de Melo
16 siblings, 0 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-11-24 18:46 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, linux-kernel, linux-perf-users,
Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Show the variables, source lines and probe-able functions of a kernel
function, and check the missing argument error.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/shell/probe_vars.sh | 80 ++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
create mode 100755 tools/perf/tests/shell/probe_vars.sh
diff --git a/tools/perf/tests/shell/probe_vars.sh b/tools/perf/tests/shell/probe_vars.sh
new file mode 100755
index 0000000000000000..1e9476635b1ebc75
--- /dev/null
+++ b/tools/perf/tests/shell/probe_vars.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+# perf probe variable and line listing tests
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+. "$(dirname $0)"/lib/probe.sh
+
+skip_if_no_perf_probe || exit 2
+
+err=0
+out=$(mktemp /tmp/__perf_test_probe_vars.out.XXXXX)
+
+cleanup() {
+ rm -f "${out}"
+
+ trap - EXIT TERM INT
+}
+
+trap_cleanup() {
+ echo "Unexpected signal in ${FUNCNAME[1]}"
+ cleanup
+ exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
+run_probe() {
+ local desc="$1" expect="$2"
+
+ shift 2
+ echo "Probe ${desc}"
+ if ! perf probe "$@" > "${out}" 2>&1; then
+ echo "Probe ${desc} [Failed: perf probe failed]"
+ cat "${out}"
+ err=1
+ return
+ fi
+ if [ -n "${expect}" ] && ! grep -q "${expect}" "${out}"; then
+ echo "Probe ${desc} [Failed: missing '${expect}']"
+ cat "${out}"
+ err=1
+ return
+ fi
+ echo "Probe ${desc} [Success]"
+}
+
+# The variable and line listings need debug info, skip when the kernel
+# was built without it.
+if ! perf probe -V schedule > "${out}" 2>&1; then
+ echo "Probe variable listing [Skipped: no debug info for schedule]"
+ cleanup
+ exit 2
+fi
+
+run_probe "vars" "Available variables at schedule" -V schedule
+run_probe "vars long option" "Available variables at schedule" --vars schedule
+run_probe "vars offset" "Available variables at schedule" -V schedule+0
+run_probe "line" "schedule" -L schedule
+run_probe "line long option" "schedule" --line schedule
+
+if [ "$(id -u)" = 0 ]; then
+ run_probe "funcs" "schedule" --funcs
+ run_probe "funcs filter" "schedule" --funcs "sched*"
+else
+ echo "Probe funcs [Skipped: needs root to read the kernel symbols]"
+fi
+
+echo "Probe missing add argument"
+if perf probe -a > "${out}" 2>&1; then
+ echo "Probe missing add argument [Failed: accepted no argument]"
+ err=1
+else
+ if ! grep -q "Usage:" "${out}"; then
+ echo "Probe missing add argument [Failed: missing usage]"
+ err=1
+ fi
+fi
+
+cleanup
+exit $err
--
2.56.0
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v1 17/17] perf tests report: Exercise the TUI browsers
2026-11-24 18:45 [PATCH v1 00/17] perf tests: Add coverage for the untested perf subcommands Arnaldo Carvalho de Melo
` (15 preceding siblings ...)
2026-11-24 18:46 ` [PATCH v1 16/17] perf tests probe: Exercise the variable and line listing Arnaldo Carvalho de Melo
@ 2026-11-24 18:46 ` Arnaldo Carvalho de Melo
16 siblings, 0 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-11-24 18:46 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Thomas Gleixner, James Clark, Jiri Olsa, Ian Rogers,
Adrian Hunter, Clark Williams, linux-kernel, linux-perf-users,
Arnaldo Carvalho de Melo
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Run report and annotate on a pty and press the help, zoom and source
keys, then check that the screens were drawn. Needs python and
libslang.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/shell/report_tui.sh | 112 +++++++++++++++++++++++++++
1 file changed, 112 insertions(+)
create mode 100755 tools/perf/tests/shell/report_tui.sh
diff --git a/tools/perf/tests/shell/report_tui.sh b/tools/perf/tests/shell/report_tui.sh
new file mode 100755
index 0000000000000000..bf5ff1c4c3f6ff7f
--- /dev/null
+++ b/tools/perf/tests/shell/report_tui.sh
@@ -0,0 +1,112 @@
+#!/bin/bash
+# perf report and annotate TUI tests
+# SPDX-License-Identifier: GPL-2.0
+
+set -e
+
+# shellcheck source=lib/setup_python.sh
+. "$(dirname "$0")/lib/setup_python.sh"
+
+if ! perf check feature -q libslang; then
+ echo "[Skip] No libslang support"
+ exit 2
+fi
+
+err=0
+tmpdir=$(mktemp -d /tmp/__perf_test_tui.XXXXXX)
+perfdata="${tmpdir}/perf.data"
+tui_keys="${tmpdir}/tui_keys.py"
+
+cleanup() {
+ rm -rf "${tmpdir}"
+
+ trap - EXIT TERM INT
+}
+
+trap_cleanup() {
+ echo "Unexpected signal in ${FUNCNAME[1]}"
+ cleanup
+ exit 1
+}
+trap trap_cleanup EXIT TERM INT
+
+# The TUI needs a terminal, so run it on a pty and feed it the keys a
+# user would press.
+cat > "${tui_keys}" <<'PY'
+import fcntl, os, pty, select, struct, sys, termios, time
+
+outfile = sys.argv[1]
+keys = sys.argv[2].encode()
+cmd = sys.argv[3:]
+
+pid, fd = pty.fork()
+if pid == 0:
+ os.environ["TERM"] = "xterm"
+ os.execvp(cmd[0], cmd)
+
+fcntl.ioctl(fd, termios.TIOCSWINSZ, struct.pack("HHHH", 40, 120, 0, 0))
+
+start = time.time()
+next_key = start + 1.5
+deadline = start + 20
+with open(outfile, "wb") as out:
+ while True:
+ now = time.time()
+ if now > deadline:
+ os.kill(pid, 9)
+ sys.exit(2)
+ if keys and now >= next_key:
+ os.write(fd, keys[:1])
+ keys = keys[1:]
+ next_key = now + 0.7
+ r, _, _ = select.select([fd], [], [], 0.1)
+ if r:
+ try:
+ chunk = os.read(fd, 65536)
+ except OSError:
+ break
+ if not chunk:
+ break
+ out.write(chunk)
+ out.flush()
+
+_, status = os.waitpid(pid, 0)
+sys.exit(os.waitstatus_to_exitcode(status))
+PY
+
+run_tui() {
+ local desc="$1" keys="$2" expect="$3"
+
+ shift 3
+ echo "TUI ${desc}"
+ if ! "${PYTHON}" "${tui_keys}" "${tmpdir}/${desc}.out" "${keys}" "$@"; then
+ echo "TUI ${desc} [Failed: TUI exited with an error]"
+ err=1
+ return
+ fi
+ if ! grep -qa "${expect}" "${tmpdir}/${desc}.out"; then
+ echo "TUI ${desc} [Failed: missing '${expect}']"
+ err=1
+ return
+ fi
+ echo "TUI ${desc} [Success]"
+}
+
+echo "TUI record"
+if ! perf record -q -o "${perfdata}" -- perf test -w noploop 1; then
+ echo "TUI record [Failed: perf record failed]"
+ cleanup
+ exit 1
+fi
+
+run_tui "report" "q" "Overhead" perf report --tui -i "${perfdata}"
+run_tui "report help" "?qq" "Help" perf report --tui -i "${perfdata}"
+run_tui "report dso zoom" "dq" "Overhead" perf report --tui -i "${perfdata}"
+run_tui "report thread zoom" "tq" "Overhead" perf report --tui -i "${perfdata}"
+run_tui "annotate" "q" "Percent" perf annotate --tui -i "${perfdata}"
+# noploop is built without debug info, so 's' opens the "no source code"
+# warning and the first 'q' only dismisses it; the second one quits.
+run_tui "annotate source" "sqq" "Percent" perf annotate --tui -i "${perfdata}"
+
+cleanup
+exit $err
--
2.56.0
^ permalink raw reply [flat|nested] 18+ messages in thread