3 # SPDX-License-Identifier: GPL-2.0
7 shelldir=$(dirname "$0")
8 # shellcheck source=lib/waiting.sh
9 . "${shelldir}"/lib/waiting.sh
11 # shellcheck source=lib/perf_has_symbol.sh
12 . "${shelldir}"/lib/perf_has_symbol.sh
16 skip_test_missing_symbol ${testsym}
19 perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
20 testprog="perf test -w thloop"
21 cpu_pmu_dir="/sys/bus/event_source/devices/cpu*"
22 br_cntr_file="/caps/branch_counter_nr"
23 br_cntr_output="branch stack counters"
27 rm -rf "${perfdata}".old
36 trap trap_cleanup EXIT TERM INT
39 echo "Basic --per-thread mode test"
40 if ! perf record -o /dev/null --quiet ${testprog} 2> /dev/null
42 echo "Per-thread record [Skipped event not supported]"
45 if ! perf record --per-thread -o "${perfdata}" ${testprog} 2> /dev/null
47 echo "Per-thread record [Failed record]"
51 if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"
53 echo "Per-thread record [Failed missing output]"
58 # run the test program in background (for 30 seconds)
64 wait_for_threads ${TESTPID} 2
65 perf record -p "${TESTPID}" --per-thread -o "${perfdata}" sleep 1 2> /dev/null
68 if [ ! -e "${perfdata}" ]
70 echo "Per-thread record [Failed record -p]"
74 if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"
76 echo "Per-thread record [Failed -p missing output]"
81 echo "Basic --per-thread mode test [Success]"
84 test_register_capture() {
85 echo "Register capture test"
86 if ! perf list | grep -q 'br_inst_retired.near_call'
88 echo "Register capture test [Skipped missing event]"
91 if ! perf record --intr-regs=\? 2>&1 | grep -q 'available registers: AX BX CX DX SI DI BP SP IP FLAGS CS SS R8 R9 R10 R11 R12 R13 R14 R15'
93 echo "Register capture test [Skipped missing registers]"
96 if ! perf record -o - --intr-regs=di,r8,dx,cx -e br_inst_retired.near_call \
97 -c 1000 --per-thread ${testprog} 2> /dev/null \
98 | perf script -F ip,sym,iregs -i - 2> /dev/null \
101 echo "Register capture test [Failed missing output]"
105 echo "Register capture test [Success]"
109 echo "Basic --system-wide mode test"
110 if ! perf record -aB --synth=no -o "${perfdata}" ${testprog} 2> /dev/null
112 echo "System-wide record [Skipped not supported]"
115 if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"
117 echo "System-wide record [Failed missing output]"
121 if ! perf record -aB --synth=no -e cpu-clock,cs --threads=cpu \
122 -o "${perfdata}" ${testprog} 2> /dev/null
124 echo "System-wide record [Failed record --threads option]"
128 if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"
130 echo "System-wide record [Failed --threads missing output]"
134 echo "Basic --system-wide mode test [Success]"
138 echo "Basic target workload test"
139 if ! perf record -o "${perfdata}" ${testprog} 2> /dev/null
141 echo "Workload record [Failed record]"
145 if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"
147 echo "Workload record [Failed missing output]"
151 if ! perf record -e cpu-clock,cs --threads=package \
152 -o "${perfdata}" ${testprog} 2> /dev/null
154 echo "Workload record [Failed record --threads option]"
158 if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"
160 echo "Workload record [Failed --threads missing output]"
164 echo "Basic target workload test [Success]"
167 test_branch_counter() {
168 echo "Basic branch counter test"
169 # Check if the branch counter feature is supported
170 for dir in $cpu_pmu_dir
172 if [ ! -e "$dir$br_cntr_file" ]
174 echo "branch counter feature not supported on all core PMUs ($dir) [Skipped]"
178 if ! perf record -o "${perfdata}" -j any,counter ${testprog} 2> /dev/null
180 echo "Basic branch counter test [Failed record]"
184 if ! perf report -i "${perfdata}" -D -q | grep -q "$br_cntr_output"
186 echo "Basic branch record test [Failed missing output]"
190 echo "Basic branch counter test [Success]"
194 test_register_capture