brintos

brintos / linux-shallow public Read only

0
0
Text · 4.5 KiB · 3f1e677 Raw
157 lines · bash
1#!/bin/sh2# perf stat tests3# SPDX-License-Identifier: GPL-2.04 5set -e6 7err=08test_default_stat() {9  echo "Basic stat command test"10  if ! perf stat true 2>&1 | grep -E -q "Performance counter stats for 'true':"11  then12    echo "Basic stat command test [Failed]"13    err=114    return15  fi16  echo "Basic stat command test [Success]"17}18 19test_stat_record_report() {20  echo "stat record and report test"21  if ! perf stat record -o - true | perf stat report -i - 2>&1 | \22    grep -E -q "Performance counter stats for 'pipe':"23  then24    echo "stat record and report test [Failed]"25    err=126    return27  fi28  echo "stat record and report test [Success]"29}30 31test_stat_record_script() {32  echo "stat record and script test"33  if ! perf stat record -o - true | perf script -i - 2>&1 | \34    grep -E -q "CPU[[:space:]]+THREAD[[:space:]]+VAL[[:space:]]+ENA[[:space:]]+RUN[[:space:]]+TIME[[:space:]]+EVENT"35  then36    echo "stat record and script test [Failed]"37    err=138    return39  fi40  echo "stat record and script test [Success]"41}42 43test_stat_repeat_weak_groups() {44  echo "stat repeat weak groups test"45  if ! perf stat -e '{cycles,cycles,cycles,cycles,cycles,cycles,cycles,cycles,cycles,cycles}' \46     true 2>&1 | grep -q 'seconds time elapsed'47  then48    echo "stat repeat weak groups test [Skipped event parsing failed]"49    return50  fi51  if ! perf stat -r2 -e '{cycles,cycles,cycles,cycles,cycles,cycles,cycles,cycles,cycles,cycles}:W' \52    true > /dev/null 2>&153  then54    echo "stat repeat weak groups test [Failed]"55    err=156    return57  fi58  echo "stat repeat weak groups test [Success]"59}60 61test_topdown_groups() {62  # Topdown events must be grouped with the slots event first. Test that63  # parse-events reorders this.64  echo "Topdown event group test"65  if ! perf stat -e '{slots,topdown-retiring}' true > /dev/null 2>&166  then67    echo "Topdown event group test [Skipped event parsing failed]"68    return69  fi70  if perf stat -e '{slots,topdown-retiring}' true 2>&1 | grep -E -q "<not supported>"71  then72    echo "Topdown event group test [Failed events not supported]"73    err=174    return75  fi76  if perf stat -e '{topdown-retiring,slots}' true 2>&1 | grep -E -q "<not supported>"77  then78    echo "Topdown event group test [Failed slots not reordered first]"79    err=180    return81  fi82  echo "Topdown event group test [Success]"83}84 85test_topdown_weak_groups() {86  # Weak groups break if the perf_event_open of multiple grouped events87  # fails. Breaking a topdown group causes the events to fail. Test a very large88  # grouping to see that the topdown events aren't broken out.89  echo "Topdown weak groups test"90  ok_grouping="{slots,topdown-bad-spec,topdown-be-bound,topdown-fe-bound,topdown-retiring},branch-instructions,branch-misses,bus-cycles,cache-misses,cache-references,cpu-cycles,instructions,mem-loads,mem-stores,ref-cycles,cache-misses,cache-references"91  if ! perf stat --no-merge -e "$ok_grouping" true > /dev/null 2>&192  then93    echo "Topdown weak groups test [Skipped event parsing failed]"94    return95  fi96  group_needs_break="{slots,topdown-bad-spec,topdown-be-bound,topdown-fe-bound,topdown-retiring,branch-instructions,branch-misses,bus-cycles,cache-misses,cache-references,cpu-cycles,instructions,mem-loads,mem-stores,ref-cycles,cache-misses,cache-references}:W"97  if perf stat --no-merge -e "$group_needs_break" true 2>&1 | grep -E -q "<not supported>"98  then99    echo "Topdown weak groups test [Failed events not supported]"100    err=1101    return102  fi103  echo "Topdown weak groups test [Success]"104}105 106test_cputype() {107  # Test --cputype argument.108  echo "cputype test"109 110  # Bogus PMU should fail.111  if perf stat --cputype="123" -e instructions true > /dev/null 2>&1112  then113    echo "cputype test [Bogus PMU didn't fail]"114    err=1115    return116  fi117 118  # Find a known PMU for cputype.119  pmu=""120  for i in cpu cpu_atom armv8_pmuv3_0121  do122    if test -d "/sys/devices/$i"123    then124      pmu="$i"125      break126    fi127    if perf stat -e "$i/instructions/" true > /dev/null 2>&1128    then129      pmu="$i"130      break131    fi132  done133  if test "x$pmu" = "x"134  then135    echo "cputype test [Skipped known PMU not found]"136    return137  fi138 139  # Test running with cputype produces output.140  if ! perf stat --cputype="$pmu" -e instructions true 2>&1 | grep -E -q "instructions"141  then142    echo "cputype test [Failed count missed with given filter]"143    err=1144    return145  fi146  echo "cputype test [Success]"147}148 149test_default_stat150test_stat_record_report151test_stat_record_script152test_stat_repeat_weak_groups153test_topdown_groups154test_topdown_weak_groups155test_cputype156exit $err157