brintos

brintos / linux-shallow public Read only

0
0
Text · 3.0 KiB · 5f14d0c Raw
83 lines · bash
1#!/bin/sh2# Check branch stack sampling3 4# SPDX-License-Identifier: GPL-2.05# German Gomez <german.gomez@arm.com>, 20226 7shelldir=$(dirname "$0")8# shellcheck source=lib/perf_has_symbol.sh9. "${shelldir}"/lib/perf_has_symbol.sh10 11# skip the test if the hardware doesn't support branch stack sampling12# and if the architecture doesn't support filter types: any,save_type,u13if ! perf record -o- --no-buildid --branch-filter any,save_type,u -- true > /dev/null 2>&1 ; then14	echo "skip: system doesn't support filter types: any,save_type,u"15	exit 216fi17 18skip_test_missing_symbol brstack_bench19 20TMPDIR=$(mktemp -d /tmp/__perf_test.program.XXXXX)21TESTPROG="perf test -w brstack"22 23cleanup() {24	rm -rf $TMPDIR25}26 27trap cleanup EXIT TERM INT28 29test_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>&133	perf script -i $TMPDIR/perf.data --fields brstacksym | xargs -n1 > $TMPDIR/perf.script34 35	# example of branch entries:36	# 	brstack_foo+0x14/brstack_bar+0x40/P/-/-/0/CALL37 38	set -x39	grep -E -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/IND_CALL/.*$"	$TMPDIR/perf.script40	grep -E -m1 "^brstack_foo\+[^ ]*/brstack_bar\+[^ ]*/CALL/.*$"	$TMPDIR/perf.script41	grep -E -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/CALL/.*$"	$TMPDIR/perf.script42	grep -E -m1 "^brstack_bench\+[^ ]*/brstack_bar\+[^ ]*/CALL/.*$"	$TMPDIR/perf.script43	grep -E -m1 "^brstack_bar\+[^ ]*/brstack_foo\+[^ ]*/RET/.*$"		$TMPDIR/perf.script44	grep -E -m1 "^brstack_foo\+[^ ]*/brstack_bench\+[^ ]*/RET/.*$"	$TMPDIR/perf.script45	grep -E -m1 "^brstack_bench\+[^ ]*/brstack_bench\+[^ ]*/COND/.*$"	$TMPDIR/perf.script46	grep -E -m1 "^brstack\+[^ ]*/brstack\+[^ ]*/UNCOND/.*$"		$TMPDIR/perf.script47	set +x48 49	# some branch types are still not being tested:50	# IND COND_CALL COND_RET SYSCALL SYSRET IRQ SERROR NO_TX51}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 filter55test_filter() {56	test_filter_filter=$157	test_filter_expect=$258 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>&162	perf script -i $TMPDIR/perf.data --fields brstack | xargs -n1 > $TMPDIR/perf.script63 64	# fail if we find any branch type that doesn't match any of the expected ones65	# also consider UNKNOWN branch types (-)66	if grep -E -vm1 "^[^ ]*/($test_filter_expect|-|( *))/.*$" $TMPDIR/perf.script; then67		return 168	fi69}70 71set -e72 73test_user_branches74 75test_filter "any_call"	"CALL|IND_CALL|COND_CALL|SYSCALL|IRQ"76test_filter "call"	"CALL|SYSCALL"77test_filter "cond"	"COND"78test_filter "any_ret"	"RET|COND_RET|SYSRET|ERET"79 80test_filter "call,cond"		"CALL|SYSCALL|COND"81test_filter "any_call,cond"		"CALL|IND_CALL|COND_CALL|IRQ|SYSCALL|COND"82test_filter "cond,any_call,any_ret"	"COND|CALL|IND_CALL|COND_CALL|SYSCALL|IRQ|RET|COND_RET|SYSRET|ERET"83