brintos

brintos / linux-shallow public Read only

0
0
Text · 6.2 KiB · 048078e Raw
248 lines · bash
1#!/bin/bash2# perf record tests3# SPDX-License-Identifier: GPL-2.04 5set -e6 7shelldir=$(dirname "$0")8# shellcheck source=lib/waiting.sh9. "${shelldir}"/lib/waiting.sh10 11# shellcheck source=lib/perf_has_symbol.sh12. "${shelldir}"/lib/perf_has_symbol.sh13 14testsym="test_loop"15 16skip_test_missing_symbol ${testsym}17 18err=019perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)20testprog="perf test -w thloop"21cpu_pmu_dir="/sys/bus/event_source/devices/cpu*"22br_cntr_file="/caps/branch_counter_nr"23br_cntr_output="branch stack counters"24br_cntr_script_output="br_cntr: A"25 26default_fd_limit=$(ulimit -Sn)27# With option --threads=cpu the number of open file descriptors should be28# equal to sum of:    nmb_cpus * nmb_events (2+dummy),29#                     nmb_threads for perf.data.n (equal to nmb_cpus) and30#                     2*nmb_cpus of pipes = 4*nmb_cpus (each pipe has 2 ends)31# All together it needs 8*nmb_cpus file descriptors plus some are also used32# outside of testing, thus raising the limit to 16*nmb_cpus33min_fd_limit=$(($(getconf _NPROCESSORS_ONLN) * 16))34 35cleanup() {36  rm -rf "${perfdata}"37  rm -rf "${perfdata}".old38 39  trap - EXIT TERM INT40}41 42trap_cleanup() {43  cleanup44  exit 145}46trap trap_cleanup EXIT TERM INT47 48test_per_thread() {49  echo "Basic --per-thread mode test"50  if ! perf record -o /dev/null --quiet ${testprog} 2> /dev/null51  then52    echo "Per-thread record [Skipped event not supported]"53    return54  fi55  if ! perf record --per-thread -o "${perfdata}" ${testprog} 2> /dev/null56  then57    echo "Per-thread record [Failed record]"58    err=159    return60  fi61  if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"62  then63    echo "Per-thread record [Failed missing output]"64    err=165    return66  fi67 68  # run the test program in background (for 30 seconds)69  ${testprog} 30 &70  TESTPID=$!71 72  rm -f "${perfdata}"73 74  wait_for_threads ${TESTPID} 275  perf record -p "${TESTPID}" --per-thread -o "${perfdata}" sleep 1 2> /dev/null76  kill ${TESTPID}77 78  if [ ! -e "${perfdata}" ]79  then80    echo "Per-thread record [Failed record -p]"81    err=182    return83  fi84  if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"85  then86    echo "Per-thread record [Failed -p missing output]"87    err=188    return89  fi90 91  echo "Basic --per-thread mode test [Success]"92}93 94test_register_capture() {95  echo "Register capture test"96  if ! perf list | grep -q 'br_inst_retired.near_call'97  then98    echo "Register capture test [Skipped missing event]"99    return100  fi101  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'102  then103    echo "Register capture test [Skipped missing registers]"104    return105  fi106  if ! perf record -o - --intr-regs=di,r8,dx,cx -e br_inst_retired.near_call \107    -c 1000 --per-thread ${testprog} 2> /dev/null \108    | perf script -F ip,sym,iregs -i - 2> /dev/null \109    | grep -q "DI:"110  then111    echo "Register capture test [Failed missing output]"112    err=1113    return114  fi115  echo "Register capture test [Success]"116}117 118test_system_wide() {119  echo "Basic --system-wide mode test"120  if ! perf record -aB --synth=no -o "${perfdata}" ${testprog} 2> /dev/null121  then122    echo "System-wide record [Skipped not supported]"123    return124  fi125  if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"126  then127    echo "System-wide record [Failed missing output]"128    err=1129    return130  fi131  if ! perf record -aB --synth=no -e cpu-clock,cs --threads=cpu \132    -o "${perfdata}" ${testprog} 2> /dev/null133  then134    echo "System-wide record [Failed record --threads option]"135    err=1136    return137  fi138  if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"139  then140    echo "System-wide record [Failed --threads missing output]"141    err=1142    return143  fi144  echo "Basic --system-wide mode test [Success]"145}146 147test_workload() {148  echo "Basic target workload test"149  if ! perf record -o "${perfdata}" ${testprog} 2> /dev/null150  then151    echo "Workload record [Failed record]"152    err=1153    return154  fi155  if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"156  then157    echo "Workload record [Failed missing output]"158    err=1159    return160  fi161  if ! perf record -e cpu-clock,cs --threads=package \162    -o "${perfdata}" ${testprog} 2> /dev/null163  then164    echo "Workload record [Failed record --threads option]"165    err=1166    return167  fi168  if ! perf report -i "${perfdata}" -q | grep -q "${testsym}"169  then170    echo "Workload record [Failed --threads missing output]"171    err=1172    return173  fi174  echo "Basic target workload test [Success]"175}176 177test_branch_counter() {178  echo "Branch counter test"179  # Check if the branch counter feature is supported180  for dir in $cpu_pmu_dir181  do182    if [ ! -e "$dir$br_cntr_file" ]183    then184      echo "branch counter feature not supported on all core PMUs ($dir) [Skipped]"185      return186    fi187  done188  if ! perf record -o "${perfdata}" -e "{branches:p,instructions}" -j any,counter ${testprog} 2> /dev/null189  then190    echo "Branch counter record test [Failed record]"191    err=1192    return193  fi194  if ! perf report -i "${perfdata}" -D -q | grep -q "$br_cntr_output"195  then196    echo "Branch counter report test [Failed missing output]"197    err=1198    return199  fi200  if ! perf script -i "${perfdata}" -F +brstackinsn,+brcntr | grep -q "$br_cntr_script_output"201  then202    echo " Branch counter script test [Failed missing output]"203    err=1204    return205  fi206  echo "Branch counter test [Success]"207}208 209test_cgroup() {210  echo "Cgroup sampling test"211  if ! perf record -aB --synth=cgroup --all-cgroups -o "${perfdata}" ${testprog} 2> /dev/null212  then213    echo "Cgroup sampling [Skipped not supported]"214    return215  fi216  if ! perf report -i "${perfdata}" -D | grep -q "CGROUP"217  then218    echo "Cgroup sampling [Failed missing output]"219    err=1220    return221  fi222  if ! perf script -i "${perfdata}" -F cgroup | grep -q -v "unknown"223  then224    echo "Cgroup sampling [Failed cannot resolve cgroup names]"225    err=1226    return227  fi228  echo "Cgroup sampling test [Success]"229}230 231# raise the limit of file descriptors to minimum232if [[ $default_fd_limit -lt $min_fd_limit ]]; then233       ulimit -Sn $min_fd_limit234fi235 236test_per_thread237test_register_capture238test_system_wide239test_workload240test_branch_counter241test_cgroup242 243# restore the default value244ulimit -Sn $default_fd_limit245 246cleanup247exit $err248