[PATCH 3/4] perf test: Skip perf trace tests when running as non-root

Namhyung Kim posted 4 patches 11 months, 2 weeks ago
[PATCH 3/4] perf test: Skip perf trace tests when running as non-root
Posted by Namhyung Kim 11 months, 2 weeks ago
perf trace requires root because it needs to use tracepoints and BPF.
Skip those test when it's not run as root.

Before:
  $ perf test trace
   15: Parse sched tracepoints fields                                  : Skip (permissions)
   80: perf ftrace tests                                               : Skip
  105: perf trace enum augmentation tests                              : FAILED!
  106: perf trace BTF general tests                                    : FAILED!
  107: perf trace exit race                                            : FAILED!
  118: probe libc's inet_pton & backtrace it with ping                 : Skip
  125: Check Arm CoreSight trace data recording and synthesized samples: Skip
  127: Check Arm SPE trace data recording and synthesized samples      : Skip
  132: Check open filename arg using perf trace + vfs_getname          : FAILED!

After:
  $ perf test trace
   15: Parse sched tracepoints fields                                  : Skip (permissions)
   80: perf ftrace tests                                               : Skip
  105: perf trace enum augmentation tests                              : Skip
  106: perf trace BTF general tests                                    : Skip
  107: perf trace exit race                                            : Skip
  118: probe libc's inet_pton & backtrace it with ping                 : Skip
  125: Check Arm CoreSight trace data recording and synthesized samples: Skip
  127: Check Arm SPE trace data recording and synthesized samples      : Skip
  132: Check open filename arg using perf trace + vfs_getname          : Skip

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/tests/shell/trace+probe_vfs_getname.sh | 1 +
 tools/perf/tests/shell/trace_btf_enum.sh          | 1 +
 tools/perf/tests/shell/trace_btf_general.sh       | 1 +
 tools/perf/tests/shell/trace_exit_race.sh         | 1 +
 4 files changed, 4 insertions(+)

diff --git a/tools/perf/tests/shell/trace+probe_vfs_getname.sh b/tools/perf/tests/shell/trace+probe_vfs_getname.sh
index 708a13f006353611..cd64408043ccc89f 100755
--- a/tools/perf/tests/shell/trace+probe_vfs_getname.sh
+++ b/tools/perf/tests/shell/trace+probe_vfs_getname.sh
@@ -15,6 +15,7 @@
 
 skip_if_no_perf_probe || exit 2
 skip_if_no_perf_trace || exit 2
+[ "$(id -u)" == 0 ] || exit 2
 
 . "$(dirname $0)"/lib/probe_vfs_getname.sh
 
diff --git a/tools/perf/tests/shell/trace_btf_enum.sh b/tools/perf/tests/shell/trace_btf_enum.sh
index 8d1e6bbeac906843..02da49af1f4ec71f 100755
--- a/tools/perf/tests/shell/trace_btf_enum.sh
+++ b/tools/perf/tests/shell/trace_btf_enum.sh
@@ -13,6 +13,7 @@ TESTPROG="perf test -w landlock"
 # shellcheck source=lib/probe.sh
 . "$(dirname $0)"/lib/probe.sh
 skip_if_no_perf_trace || exit 2
+[ "$(id -u)" == 0 ] || exit 2
 
 check_vmlinux() {
   echo "Checking if vmlinux exists"
diff --git a/tools/perf/tests/shell/trace_btf_general.sh b/tools/perf/tests/shell/trace_btf_general.sh
index e9ee727f3433eaba..a89dc4a6cfd1b1a5 100755
--- a/tools/perf/tests/shell/trace_btf_general.sh
+++ b/tools/perf/tests/shell/trace_btf_general.sh
@@ -76,6 +76,7 @@ trace_config() {
 
 skip_if_no_perf_trace || exit 2
 check_vmlinux || exit 2
+[ "$(id -u)" == 0 ] || exit 2
 
 trace_config
 
diff --git a/tools/perf/tests/shell/trace_exit_race.sh b/tools/perf/tests/shell/trace_exit_race.sh
index fbb0adc33a889516..7187ebc16c96b5ee 100755
--- a/tools/perf/tests/shell/trace_exit_race.sh
+++ b/tools/perf/tests/shell/trace_exit_race.sh
@@ -10,6 +10,7 @@
 . "$(dirname $0)"/lib/probe.sh
 
 skip_if_no_perf_trace || exit 2
+[ "$(id -u)" == 0 ] || exit 2
 
 if [ "$1" = "-v" ]; then
 	verbose="1"
-- 
2.48.1.711.g2feabab25a-goog
Re: [PATCH 3/4] perf test: Skip perf trace tests when running as non-root
Posted by Arnaldo Carvalho de Melo 11 months, 1 week ago
On Fri, Feb 28, 2025 at 08:02:51PM -0800, Namhyung Kim wrote:
> +++ b/tools/perf/tests/shell/trace+probe_vfs_getname.sh
> @@ -15,6 +15,7 @@
>  
>  skip_if_no_perf_probe || exit 2
>  skip_if_no_perf_trace || exit 2
> +[ "$(id -u)" == 0 ] || exit 2

Same issue as with the previous patch.

- Arnaldo