drm/rockchip: Don't change hdmi reference clock rate
[drm/drm-misc.git] / tools / perf / tests / shell / record.sh
blob0fc7a909ae9b54ace94180d68a1ce0aed24ca445
1 #!/bin/bash
2 # perf record tests (exclusive)
3 # SPDX-License-Identifier: GPL-2.0
5 set -e
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
14 testsym="test_loop"
16 skip_test_missing_symbol ${testsym}
18 err=0
19 perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
20 script_output=$(mktemp /tmp/__perf_test.perf.data.XXXXX.script)
21 testprog="perf test -w thloop"
22 cpu_pmu_dir="/sys/bus/event_source/devices/cpu*"
23 br_cntr_file="/caps/branch_counter_nr"
24 br_cntr_output="branch stack counters"
25 br_cntr_script_output="br_cntr: A"
27 default_fd_limit=$(ulimit -Sn)
28 # With option --threads=cpu the number of open file descriptors should be
29 # equal to sum of: nmb_cpus * nmb_events (2+dummy),
30 # nmb_threads for perf.data.n (equal to nmb_cpus) and
31 # 2*nmb_cpus of pipes = 4*nmb_cpus (each pipe has 2 ends)
32 # All together it needs 8*nmb_cpus file descriptors plus some are also used
33 # outside of testing, thus raising the limit to 16*nmb_cpus
34 min_fd_limit=$(($(getconf _NPROCESSORS_ONLN) * 16))
36 cleanup() {
37 rm -rf "${perfdata}"
38 rm -rf "${perfdata}".old
40 trap - EXIT TERM INT
43 trap_cleanup() {
44 cleanup
45 exit 1
47 trap trap_cleanup EXIT TERM INT
49 test_per_thread() {
50 echo "Basic --per-thread mode test"
51 if ! perf record -o /dev/null --quiet ${testprog} 2> /dev/null
52 then
53 echo "Per-thread record [Skipped event not supported]"
54 return
56 if ! perf record --per-thread -o "${perfdata}" ${testprog} 2> /dev/null
57 then
58 echo "Per-thread record [Failed record]"
59 err=1
60 return
62 if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"
63 then
64 echo "Per-thread record [Failed missing output]"
65 err=1
66 return
69 # run the test program in background (for 30 seconds)
70 ${testprog} 30 &
71 TESTPID=$!
73 rm -f "${perfdata}"
75 wait_for_threads ${TESTPID} 2
76 perf record -p "${TESTPID}" --per-thread -o "${perfdata}" sleep 1 2> /dev/null
77 kill ${TESTPID}
79 if [ ! -e "${perfdata}" ]
80 then
81 echo "Per-thread record [Failed record -p]"
82 err=1
83 return
85 if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"
86 then
87 echo "Per-thread record [Failed -p missing output]"
88 err=1
89 return
92 echo "Basic --per-thread mode test [Success]"
95 test_register_capture() {
96 echo "Register capture test"
97 if ! perf list pmu | grep -q 'br_inst_retired.near_call'
98 then
99 echo "Register capture test [Skipped missing event]"
100 return
102 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'
103 then
104 echo "Register capture test [Skipped missing registers]"
105 return
107 if ! perf record -o - --intr-regs=di,r8,dx,cx -e br_inst_retired.near_call \
108 -c 1000 --per-thread ${testprog} 2> /dev/null \
109 | perf script -F ip,sym,iregs -i - 2> /dev/null \
110 | grep -q "DI:"
111 then
112 echo "Register capture test [Failed missing output]"
113 err=1
114 return
116 echo "Register capture test [Success]"
119 test_system_wide() {
120 echo "Basic --system-wide mode test"
121 if ! perf record -aB --synth=no -o "${perfdata}" ${testprog} 2> /dev/null
122 then
123 echo "System-wide record [Skipped not supported]"
124 return
126 if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"
127 then
128 echo "System-wide record [Failed missing output]"
129 err=1
130 return
132 if ! perf record -aB --synth=no -e cpu-clock,cs --threads=cpu \
133 -o "${perfdata}" ${testprog} 2> /dev/null
134 then
135 echo "System-wide record [Failed record --threads option]"
136 err=1
137 return
139 if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"
140 then
141 echo "System-wide record [Failed --threads missing output]"
142 err=1
143 return
145 echo "Basic --system-wide mode test [Success]"
148 test_workload() {
149 echo "Basic target workload test"
150 if ! perf record -o "${perfdata}" ${testprog} 2> /dev/null
151 then
152 echo "Workload record [Failed record]"
153 err=1
154 return
156 if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"
157 then
158 echo "Workload record [Failed missing output]"
159 err=1
160 return
162 if ! perf record -e cpu-clock,cs --threads=package \
163 -o "${perfdata}" ${testprog} 2> /dev/null
164 then
165 echo "Workload record [Failed record --threads option]"
166 err=1
167 return
169 if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"
170 then
171 echo "Workload record [Failed --threads missing output]"
172 err=1
173 return
175 echo "Basic target workload test [Success]"
178 test_branch_counter() {
179 echo "Branch counter test"
180 # Check if the branch counter feature is supported
181 for dir in $cpu_pmu_dir
183 if [ ! -e "$dir$br_cntr_file" ]
184 then
185 echo "branch counter feature not supported on all core PMUs ($dir) [Skipped]"
186 return
188 done
189 if ! perf record -o "${perfdata}" -e "{branches:p,instructions}" -j any,counter ${testprog} 2> /dev/null
190 then
191 echo "Branch counter record test [Failed record]"
192 err=1
193 return
195 if ! perf report -i "${perfdata}" -D -q | grep -q "$br_cntr_output"
196 then
197 echo "Branch counter report test [Failed missing output]"
198 err=1
199 return
201 if ! perf script -i "${perfdata}" -F +brstackinsn,+brcntr | grep -q "$br_cntr_script_output"
202 then
203 echo " Branch counter script test [Failed missing output]"
204 err=1
205 return
207 echo "Branch counter test [Success]"
210 test_cgroup() {
211 echo "Cgroup sampling test"
212 if ! perf record -aB --synth=cgroup --all-cgroups -o "${perfdata}" ${testprog} 2> /dev/null
213 then
214 echo "Cgroup sampling [Skipped not supported]"
215 return
217 if ! perf report -i "${perfdata}" -D | grep -q "CGROUP"
218 then
219 echo "Cgroup sampling [Failed missing output]"
220 err=1
221 return
223 if ! perf script -i "${perfdata}" -F cgroup | grep -q -v "unknown"
224 then
225 echo "Cgroup sampling [Failed cannot resolve cgroup names]"
226 err=1
227 return
229 echo "Cgroup sampling test [Success]"
232 test_leader_sampling() {
233 echo "Basic leader sampling test"
234 if ! perf record -o "${perfdata}" -e "{instructions,instructions}:Su" -- \
235 perf test -w brstack 2> /dev/null
236 then
237 echo "Leader sampling [Failed record]"
238 err=1
239 return
241 index=0
242 perf script -i "${perfdata}" > $script_output
243 while IFS= read -r line
245 # Check if the two instruction counts are equal in each record
246 instructions=$(echo $line | awk '{for(i=1;i<=NF;i++) if($i=="instructions:") print $(i-1)}')
247 if [ $(($index%2)) -ne 0 ] && [ ${instructions}x != ${prev_instructions}x ]
248 then
249 echo "Leader sampling [Failed inconsistent instructions count]"
250 err=1
251 return
253 index=$(($index+1))
254 prev_instructions=$instructions
255 done < $script_output
256 echo "Basic leader sampling test [Success]"
259 test_topdown_leader_sampling() {
260 echo "Topdown leader sampling test"
261 if ! perf stat -e "{slots,topdown-retiring}" true 2> /dev/null
262 then
263 echo "Topdown leader sampling [Skipped event parsing failed]"
264 return
266 if ! perf record -o "${perfdata}" -e "{instructions,slots,topdown-retiring}:S" true 2> /dev/null
267 then
268 echo "Topdown leader sampling [Failed topdown events not reordered correctly]"
269 err=1
270 return
272 echo "Topdown leader sampling test [Success]"
275 test_precise_max() {
276 echo "precise_max attribute test"
277 if ! perf stat -e "cycles,instructions" true 2> /dev/null
278 then
279 echo "precise_max attribute [Skipped no hardware events]"
280 return
282 # Just to make sure it doesn't fail
283 if ! perf record -o "${perfdata}" -e "cycles:P" true 2> /dev/null
284 then
285 echo "precise_max attribute [Failed cycles:P event]"
286 err=1
287 return
289 # On AMD, cycles and instructions events are treated differently
290 if ! perf record -o "${perfdata}" -e "instructions:P" true 2> /dev/null
291 then
292 echo "precise_max attribute [Failed instructions:P event]"
293 err=1
294 return
296 echo "precise_max attribute test [Success]"
299 # raise the limit of file descriptors to minimum
300 if [[ $default_fd_limit -lt $min_fd_limit ]]; then
301 ulimit -Sn $min_fd_limit
304 test_per_thread
305 test_register_capture
306 test_system_wide
307 test_workload
308 test_branch_counter
309 test_cgroup
310 test_leader_sampling
311 test_topdown_leader_sampling
312 test_precise_max
314 # restore the default value
315 ulimit -Sn $default_fd_limit
317 cleanup
318 exit $err