1 #!/bin/sh 2 # perf stat tests 3 # SPDX-License-Identifier: GPL-2.0 4 5 set -e 6 7 err=0 8 test_default_stat() { 9 echo "Basic stat command test" 10 if ! perf stat true 2>&1 | grep -E -q "Perfo 11 then 12 echo "Basic stat command test [Failed]" 13 err=1 14 return 15 fi 16 echo "Basic stat command test [Success]" 17 } 18 19 test_stat_record_report() { 20 echo "stat record and report test" 21 if ! perf stat record -o - true | perf stat 22 grep -E -q "Performance counter stats for 23 then 24 echo "stat record and report test [Failed] 25 err=1 26 return 27 fi 28 echo "stat record and report test [Success]" 29 } 30 31 test_stat_record_script() { 32 echo "stat record and script test" 33 if ! perf stat record -o - true | perf scrip 34 grep -E -q "CPU[[:space:]]+THREAD[[:space: 35 then 36 echo "stat record and script test [Failed] 37 err=1 38 return 39 fi 40 echo "stat record and script test [Success]" 41 } 42 43 test_stat_repeat_weak_groups() { 44 echo "stat repeat weak groups test" 45 if ! perf stat -e '{cycles,cycles,cycles,cyc 46 true 2>&1 | grep -q 'seconds time elapsed 47 then 48 echo "stat repeat weak groups test [Skippe 49 return 50 fi 51 if ! perf stat -r2 -e '{cycles,cycles,cycles 52 true > /dev/null 2>&1 53 then 54 echo "stat repeat weak groups test [Failed 55 err=1 56 return 57 fi 58 echo "stat repeat weak groups test [Success] 59 } 60 61 test_topdown_groups() { 62 # Topdown events must be grouped with the sl 63 # parse-events reorders this. 64 echo "Topdown event group test" 65 if ! perf stat -e '{slots,topdown-retiring}' 66 then 67 echo "Topdown event group test [Skipped ev 68 return 69 fi 70 if perf stat -e '{slots,topdown-retiring}' t 71 then 72 echo "Topdown event group test [Failed eve 73 err=1 74 return 75 fi 76 if perf stat -e '{topdown-retiring,slots}' t 77 then 78 echo "Topdown event group test [Failed slo 79 err=1 80 return 81 fi 82 echo "Topdown event group test [Success]" 83 } 84 85 test_topdown_weak_groups() { 86 # Weak groups break if the perf_event_open o 87 # fails. Breaking a topdown group causes the 88 # grouping to see that the topdown events ar 89 echo "Topdown weak groups test" 90 ok_grouping="{slots,topdown-bad-spec,topdown 91 if ! perf stat --no-merge -e "$ok_grouping" 92 then 93 echo "Topdown weak groups test [Skipped ev 94 return 95 fi 96 group_needs_break="{slots,topdown-bad-spec,t 97 if perf stat --no-merge -e "$group_needs_bre 98 then 99 echo "Topdown weak groups test [Failed eve 100 err=1 101 return 102 fi 103 echo "Topdown weak groups test [Success]" 104 } 105 106 test_cputype() { 107 # Test --cputype argument. 108 echo "cputype test" 109 110 # Bogus PMU should fail. 111 if perf stat --cputype="123" -e instructions 112 then 113 echo "cputype test [Bogus PMU didn't fail] 114 err=1 115 return 116 fi 117 118 # Find a known PMU for cputype. 119 pmu="" 120 for i in cpu cpu_atom armv8_pmuv3_0 121 do 122 if test -d "/sys/devices/$i" 123 then 124 pmu="$i" 125 break 126 fi 127 if perf stat -e "$i/instructions/" true > 128 then 129 pmu="$i" 130 break 131 fi 132 done 133 if test "x$pmu" = "x" 134 then 135 echo "cputype test [Skipped known PMU not 136 return 137 fi 138 139 # Test running with cputype produces output. 140 if ! perf stat --cputype="$pmu" -e instructi 141 then 142 echo "cputype test [Failed count missed wi 143 err=1 144 return 145 fi 146 echo "cputype test [Success]" 147 } 148 149 test_default_stat 150 test_stat_record_report 151 test_stat_record_script 152 test_stat_repeat_weak_groups 153 test_topdown_groups 154 test_topdown_weak_groups 155 test_cputype 156 exit $err
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.