xref: /openbmc/linux/tools/perf/tests/shell/record.sh (revision ecfb9f40)
1#!/bin/sh
2# perf record tests
3# SPDX-License-Identifier: GPL-2.0
4
5set -e
6
7shelldir=$(dirname "$0")
8. "${shelldir}"/lib/waiting.sh
9
10err=0
11perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
12testprog="perf test -w thloop"
13testsym="test_loop"
14
15cleanup() {
16  rm -rf "${perfdata}"
17  rm -rf "${perfdata}".old
18
19  trap - EXIT TERM INT
20}
21
22trap_cleanup() {
23  cleanup
24  exit 1
25}
26trap trap_cleanup EXIT TERM INT
27
28test_per_thread() {
29  echo "Basic --per-thread mode test"
30  if ! perf record -o /dev/null --quiet ${testprog} 2> /dev/null
31  then
32    echo "Per-thread record [Skipped event not supported]"
33    return
34  fi
35  if ! perf record --per-thread -o "${perfdata}" ${testprog} 2> /dev/null
36  then
37    echo "Per-thread record [Failed record]"
38    err=1
39    return
40  fi
41  if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"
42  then
43    echo "Per-thread record [Failed missing output]"
44    err=1
45    return
46  fi
47
48  # run the test program in background (for 30 seconds)
49  ${testprog} 30 &
50  TESTPID=$!
51
52  rm -f "${perfdata}"
53
54  wait_for_threads ${TESTPID} 2
55  perf record -p "${TESTPID}" --per-thread -o "${perfdata}" sleep 1 2> /dev/null
56  kill ${TESTPID}
57
58  if [ ! -e "${perfdata}" ]
59  then
60    echo "Per-thread record [Failed record -p]"
61    err=1
62    return
63  fi
64  if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"
65  then
66    echo "Per-thread record [Failed -p missing output]"
67    err=1
68    return
69  fi
70
71  echo "Basic --per-thread mode test [Success]"
72}
73
74test_register_capture() {
75  echo "Register capture test"
76  if ! perf list | grep -q 'br_inst_retired.near_call'
77  then
78    echo "Register capture test [Skipped missing event]"
79    return
80  fi
81  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'
82  then
83    echo "Register capture test [Skipped missing registers]"
84    return
85  fi
86  if ! perf record -o - --intr-regs=di,r8,dx,cx -e br_inst_retired.near_call \
87    -c 1000 --per-thread ${testprog} 2> /dev/null \
88    | perf script -F ip,sym,iregs -i - 2> /dev/null \
89    | grep -q "DI:"
90  then
91    echo "Register capture test [Failed missing output]"
92    err=1
93    return
94  fi
95  echo "Register capture test [Success]"
96}
97
98test_system_wide() {
99  echo "Basic --system-wide mode test"
100  if ! perf record -aB --synth=no -o "${perfdata}" ${testprog} 2> /dev/null
101  then
102    echo "System-wide record [Skipped not supported]"
103    return
104  fi
105  if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"
106  then
107    echo "System-wide record [Failed missing output]"
108    err=1
109    return
110  fi
111  if ! perf record -aB --synth=no -e cpu-clock,cs --threads=cpu \
112    -o "${perfdata}" ${testprog} 2> /dev/null
113  then
114    echo "System-wide record [Failed record --threads option]"
115    err=1
116    return
117  fi
118  if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"
119  then
120    echo "System-wide record [Failed --threads missing output]"
121    err=1
122    return
123  fi
124  echo "Basic --system-wide mode test [Success]"
125}
126
127test_workload() {
128  echo "Basic target workload test"
129  if ! perf record -o "${perfdata}" ${testprog} 2> /dev/null
130  then
131    echo "Workload record [Failed record]"
132    err=1
133    return
134  fi
135  if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"
136  then
137    echo "Workload record [Failed missing output]"
138    err=1
139    return
140  fi
141  if ! perf record -e cpu-clock,cs --threads=package \
142    -o "${perfdata}" ${testprog} 2> /dev/null
143  then
144    echo "Workload record [Failed record --threads option]"
145    err=1
146    return
147  fi
148  if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"
149  then
150    echo "Workload record [Failed --threads missing output]"
151    err=1
152    return
153  fi
154  echo "Basic target workload test [Success]"
155}
156
157test_per_thread
158test_register_capture
159test_system_wide
160test_workload
161
162cleanup
163exit $err
164