~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/tests/shell/test_brstack.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/sh
  2 # Check branch stack sampling
  3 
  4 # SPDX-License-Identifier: GPL-2.0
  5 # German Gomez <german.gomez@arm.com>, 2022
  6 
  7 shelldir=$(dirname "$0")
  8 # shellcheck source=lib/perf_has_symbol.sh
  9 . "${shelldir}"/lib/perf_has_symbol.sh
 10 
 11 # skip the test if the hardware doesn't support branch stack sampling
 12 # and if the architecture doesn't support filter types: any,save_type,u
 13 if ! perf record -o- --no-buildid --branch-filter any,save_type,u -- true > /dev/null 2>&1 ; then
 14         echo "skip: system doesn't support filter types: any,save_type,u"
 15         exit 2
 16 fi
 17 
 18 skip_test_missing_symbol brstack_bench
 19 
 20 TMPDIR=$(mktemp -d /tmp/__perf_test.program.XXXXX)
 21 TESTPROG="perf test -w brstack"
 22 
 23 cleanup() {
 24         rm -rf $TMPDIR
 25 }
 26 
 27 trap cleanup EXIT TERM INT
 28 
 29 test_user_branches() {
 30         echo "Testing user branch stack sampling"
 31 
 32         perf record -o $TMPDIR/perf.data --branch-filter any,save_type,u -- ${TESTPROG} > /dev/null 2>&1
 33         perf script -i $TMPDIR/perf.data --fields brstacksym | xargs -n1 > $TMPDIR/perf.script
 34 
 35         # example of branch entries:
 36         #       brstack_foo+0x14/brstack_bar+0x40/P/-/-/0/CALL
 37 
 38         set -x
 39         grep -E -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/IND_CALL/.*$"     $TMPDIR/perf.script
 40         grep -E -m1 "^brstack_foo\+[^ ]*/brstack_bar\+[^ ]*/CALL/.*$"   $TMPDIR/perf.script
 41         grep -E -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/CALL/.*$" $TMPDIR/perf.script
 42         grep -E -m1 "^brstack_bench\+[^ ]*/brstack_bar\+[^ ]*/CALL/.*$" $TMPDIR/perf.script
 43         grep -E -m1 "^brstack_bar\+[^ ]*/brstack_foo\+[^ ]*/RET/.*$"            $TMPDIR/perf.script
 44         grep -E -m1 "^brstack_foo\+[^ ]*/brstack_bench\+[^ ]*/RET/.*$"  $TMPDIR/perf.script
 45         grep -E -m1 "^brstack_bench\+[^ ]*/brstack_bench\+[^ ]*/COND/.*$"       $TMPDIR/perf.script
 46         grep -E -m1 "^brstack\+[^ ]*/brstack\+[^ ]*/UNCOND/.*$"         $TMPDIR/perf.script
 47         set +x
 48 
 49         # some branch types are still not being tested:
 50         # IND COND_CALL COND_RET SYSCALL SYSRET IRQ SERROR NO_TX
 51 }
 52 
 53 # first argument <arg0> is the argument passed to "--branch-stack <arg0>,save_type,u"
 54 # second argument are the expected branch types for the given filter
 55 test_filter() {
 56         test_filter_filter=$1
 57         test_filter_expect=$2
 58 
 59         echo "Testing branch stack filtering permutation ($test_filter_filter,$test_filter_expect)"
 60 
 61         perf record -o $TMPDIR/perf.data --branch-filter $test_filter_filter,save_type,u -- ${TESTPROG} > /dev/null 2>&1
 62         perf script -i $TMPDIR/perf.data --fields brstack | xargs -n1 > $TMPDIR/perf.script
 63 
 64         # fail if we find any branch type that doesn't match any of the expected ones
 65         # also consider UNKNOWN branch types (-)
 66         if grep -E -vm1 "^[^ ]*/($test_filter_expect|-|( *))/.*$" $TMPDIR/perf.script; then
 67                 return 1
 68         fi
 69 }
 70 
 71 set -e
 72 
 73 test_user_branches
 74 
 75 test_filter "any_call"  "CALL|IND_CALL|COND_CALL|SYSCALL|IRQ"
 76 test_filter "call"      "CALL|SYSCALL"
 77 test_filter "cond"      "COND"
 78 test_filter "any_ret"   "RET|COND_RET|SYSRET|ERET"
 79 
 80 test_filter "call,cond"         "CALL|SYSCALL|COND"
 81 test_filter "any_call,cond"             "CALL|IND_CALL|COND_CALL|IRQ|SYSCALL|COND"
 82 test_filter "cond,any_call,any_ret"     "COND|CALL|IND_CALL|COND_CALL|SYSCALL|IRQ|RET|COND_RET|SYSRET|ERET"

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php