2 # Check branch stack sampling
4 # SPDX-License-Identifier: GPL-2.0
7 # skip the test if the hardware doesn't support branch stack sampling
8 # and if the architecture doesn't support filter types: any,save_type,u
9 if ! perf record -o- --no-buildid --branch-filter any,save_type,u -- true > /dev/null 2>&1 ; then
10 echo "skip: system doesn't support filter types: any,save_type,u"
14 TMPDIR=$(mktemp -d /tmp/__perf_test.program.XXXXX)
15 TESTPROG="perf test -w brstack"
21 trap cleanup EXIT TERM INT
23 test_user_branches() {
24 echo "Testing user branch stack sampling"
26 perf record -o $TMPDIR/perf.data --branch-filter any,save_type,u -- ${TESTPROG} > /dev/null 2>&1
27 perf script -i $TMPDIR/perf.data --fields brstacksym | xargs -n1 > $TMPDIR/perf.script
29 # example of branch entries:
30 # brstack_foo+0x14/brstack_bar+0x40/P/-/-/0/CALL
33 grep -E -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/IND_CALL/.*$" $TMPDIR/perf.script
34 grep -E -m1 "^brstack_foo\+[^ ]*/brstack_bar\+[^ ]*/CALL/.*$" $TMPDIR/perf.script
35 grep -E -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/CALL/.*$" $TMPDIR/perf.script
36 grep -E -m1 "^brstack_bench\+[^ ]*/brstack_bar\+[^ ]*/CALL/.*$" $TMPDIR/perf.script
37 grep -E -m1 "^brstack_bar\+[^ ]*/brstack_foo\+[^ ]*/RET/.*$" $TMPDIR/perf.script
38 grep -E -m1 "^brstack_foo\+[^ ]*/brstack_bench\+[^ ]*/RET/.*$" $TMPDIR/perf.script
39 grep -E -m1 "^brstack_bench\+[^ ]*/brstack_bench\+[^ ]*/COND/.*$" $TMPDIR/perf.script
40 grep -E -m1 "^brstack\+[^ ]*/brstack\+[^ ]*/UNCOND/.*$" $TMPDIR/perf.script
43 # some branch types are still not being tested:
44 # IND COND_CALL COND_RET SYSCALL SYSRET IRQ SERROR NO_TX
47 # first argument <arg0> is the argument passed to "--branch-stack <arg0>,save_type,u"
48 # second argument are the expected branch types for the given filter
53 echo "Testing branch stack filtering permutation ($test_filter_filter,$test_filter_expect)"
55 perf record -o $TMPDIR/perf.data --branch-filter $test_filter_filter,save_type,u -- ${TESTPROG} > /dev/null 2>&1
56 perf script -i $TMPDIR/perf.data --fields brstack | xargs -n1 > $TMPDIR/perf.script
58 # fail if we find any branch type that doesn't match any of the expected ones
59 # also consider UNKNOWN branch types (-)
60 if grep -E -vm1 "^[^ ]*/($test_filter_expect|-|( *))/.*$" $TMPDIR/perf.script; then
69 test_filter "any_call" "CALL|IND_CALL|COND_CALL|SYSCALL|IRQ"
70 test_filter "call" "CALL|SYSCALL"
71 test_filter "cond" "COND"
72 test_filter "any_ret" "RET|COND_RET|SYSRET|ERET"
74 test_filter "call,cond" "CALL|SYSCALL|COND"
75 test_filter "any_call,cond" "CALL|IND_CALL|COND_CALL|IRQ|SYSCALL|COND"
76 test_filter "cond,any_call,any_ret" "COND|CALL|IND_CALL|COND_CALL|SYSCALL|IRQ|RET|COND_RET|SYSRET|ERET"