Commit 9575ecdd authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf test: Add perf record sample filtering test

  $ sudo ./perf test 'sample filter' -v
   94: perf record sample filtering (by BPF) tests                     :
  --- start ---
  test child forked, pid 3817527
  Checking BPF-filter privilege
  Basic bpf-filter test
  Basic bpf-filter test [Success]
  Failing bpf-filter test
  Error: task-clock event does not have PERF_SAMPLE_CPU
  Failing bpf-filter test [Success]
  Group bpf-filter test
  Error: task-clock event does not have PERF_SAMPLE_CPU
  Error: task-clock event does not have PERF_SAMPLE_CODE_PAGE_SIZE
  Group bpf-filter test [Success]
  test child finished with 0
  ---- end ----
  perf record sample filtering (by BPF) tests: Ok
Reviewed-by: default avatarIan Rogers <irogers@google.com>
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230811025822.3859771-2-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent dc7f01f1
#!/bin/sh
# perf record sample filtering (by BPF) tests
# SPDX-License-Identifier: GPL-2.0
set -e
err=0
perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
cleanup() {
rm -f "${perfdata}"
rm -f "${perfdata}".old
trap - EXIT TERM INT
}
trap_cleanup() {
cleanup
exit 1
}
trap trap_cleanup EXIT TERM INT
test_bpf_filter_priv() {
echo "Checking BPF-filter privilege"
if [ "$(id -u)" != 0 ]
then
echo "bpf-filter test [Skipped permission]"
err=2
return
fi
if ! perf record -e task-clock --filter 'period > 1' \
-o /dev/null --quiet true 2>&1
then
echo "bpf-filter test [Skipped missing BPF support]"
err=2
return
fi
}
test_bpf_filter_basic() {
echo "Basic bpf-filter test"
if ! perf record -e task-clock -c 10000 --filter 'ip < 0xffffffff00000000' \
-o "${perfdata}" true 2> /dev/null
then
echo "Basic bpf-filter test [Failed record]"
err=1
return
fi
if perf script -i "${perfdata}" -F ip | grep 'ffffffff[0-9a-f]*'
then
echo "Basic bpf-filter test [Failed invalid output]"
err=1
return
fi
echo "Basic bpf-filter test [Success]"
}
test_bpf_filter_fail() {
echo "Failing bpf-filter test"
# 'cpu' requires PERF_SAMPLE_CPU flag
if ! perf record -e task-clock --filter 'cpu > 0' \
-o /dev/null true 2>&1 | grep PERF_SAMPLE_CPU
then
echo "Failing bpf-filter test [Failed forbidden CPU]"
err=1
return
fi
if ! perf record --sample-cpu -e task-clock --filter 'cpu > 0' \
-o /dev/null true 2>/dev/null
then
echo "Failing bpf-filter test [Failed should succeed]"
err=1
return
fi
echo "Failing bpf-filter test [Success]"
}
test_bpf_filter_group() {
echo "Group bpf-filter test"
if ! perf record -e task-clock --filter 'period > 1000 || ip > 0' \
-o /dev/null true 2>/dev/null
then
echo "Group bpf-filter test [Failed should succeed]"
err=1
return
fi
if ! perf record -e task-clock --filter 'cpu > 0 || ip > 0' \
-o /dev/null true 2>&1 | grep PERF_SAMPLE_CPU
then
echo "Group bpf-filter test [Failed forbidden CPU]"
err=1
return
fi
if ! perf record -e task-clock --filter 'period > 0 || code_pgsz > 4096' \
-o /dev/null true 2>&1 | grep PERF_SAMPLE_CODE_PAGE_SIZE
then
echo "Group bpf-filter test [Failed forbidden CODE_PAGE_SIZE]"
err=1
return
fi
echo "Group bpf-filter test [Success]"
}
test_bpf_filter_priv
if [ $err = 0 ]; then
test_bpf_filter_basic
fi
if [ $err = 0 ]; then
test_bpf_filter_fail
fi
if [ $err = 0 ]; then
test_bpf_filter_group
fi
cleanup
exit $err
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment