stat.sh (2673B)
1#!/bin/sh 2# perf stat tests 3# SPDX-License-Identifier: GPL-2.0 4 5set -e 6 7err=0 8test_default_stat() { 9 echo "Basic stat command test" 10 if ! perf stat true 2>&1 | egrep -q "Performance counter stats for 'true':" 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 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 egrep -q "Performance counter stats for 'pipe':" 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 31test_topdown_groups() { 32 # Topdown events must be grouped with the slots event first. Test that 33 # parse-events reorders this. 34 echo "Topdown event group test" 35 if ! perf stat -e '{slots,topdown-retiring}' true > /dev/null 2>&1 36 then 37 echo "Topdown event group test [Skipped event parsing failed]" 38 return 39 fi 40 if perf stat -e '{slots,topdown-retiring}' true 2>&1 | egrep -q "<not supported>" 41 then 42 echo "Topdown event group test [Failed events not supported]" 43 err=1 44 return 45 fi 46 if perf stat -e '{topdown-retiring,slots}' true 2>&1 | egrep -q "<not supported>" 47 then 48 echo "Topdown event group test [Failed slots not reordered first]" 49 err=1 50 return 51 fi 52 echo "Topdown event group test [Success]" 53} 54 55test_topdown_weak_groups() { 56 # Weak groups break if the perf_event_open of multiple grouped events 57 # fails. Breaking a topdown group causes the events to fail. Test a very large 58 # grouping to see that the topdown events aren't broken out. 59 echo "Topdown weak groups test" 60 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" 61 if ! perf stat --no-merge -e "$ok_grouping" true > /dev/null 2>&1 62 then 63 echo "Topdown weak groups test [Skipped event parsing failed]" 64 return 65 fi 66 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" 67 if perf stat --no-merge -e "$group_needs_break" true 2>&1 | egrep -q "<not supported>" 68 then 69 echo "Topdown weak groups test [Failed events not supported]" 70 err=1 71 return 72 fi 73 echo "Topdown weak groups test [Success]" 74} 75 76test_default_stat 77test_stat_record_report 78test_topdown_groups 79test_topdown_weak_groups 80exit $err