Ian Rogers | 6a973e2 | 2022-05-16 22:27:24 -0700 | [diff] [blame] | 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 | 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 | |
Ian Rogers | 0dd9769 | 2022-05-18 20:20:02 -0700 | [diff] [blame] | 19 | test_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 | |
Ian Rogers | 0c361c6 | 2022-08-22 14:33:52 -0700 | [diff] [blame] | 31 | test_stat_repeat_weak_groups() { |
| 32 | echo "stat repeat weak groups test" |
| 33 | if ! perf stat -e '{cycles,cycles,cycles,cycles,cycles,cycles,cycles,cycles,cycles,cycles}' \ |
| 34 | true 2>&1 | grep -q 'seconds time elapsed' |
| 35 | then |
| 36 | echo "stat repeat weak groups test [Skipped event parsing failed]" |
| 37 | return |
| 38 | fi |
| 39 | if ! perf stat -r2 -e '{cycles,cycles,cycles,cycles,cycles,cycles,cycles,cycles,cycles,cycles}:W' \ |
| 40 | true > /dev/null 2>&1 |
| 41 | then |
| 42 | echo "stat repeat weak groups test [Failed]" |
| 43 | err=1 |
| 44 | return |
| 45 | fi |
| 46 | echo "stat repeat weak groups test [Success]" |
| 47 | } |
| 48 | |
Ian Rogers | 6a973e2 | 2022-05-16 22:27:24 -0700 | [diff] [blame] | 49 | test_topdown_groups() { |
| 50 | # Topdown events must be grouped with the slots event first. Test that |
| 51 | # parse-events reorders this. |
| 52 | echo "Topdown event group test" |
| 53 | if ! perf stat -e '{slots,topdown-retiring}' true > /dev/null 2>&1 |
| 54 | then |
| 55 | echo "Topdown event group test [Skipped event parsing failed]" |
| 56 | return |
| 57 | fi |
| 58 | if perf stat -e '{slots,topdown-retiring}' true 2>&1 | egrep -q "<not supported>" |
| 59 | then |
| 60 | echo "Topdown event group test [Failed events not supported]" |
| 61 | err=1 |
| 62 | return |
| 63 | fi |
| 64 | if perf stat -e '{topdown-retiring,slots}' true 2>&1 | egrep -q "<not supported>" |
| 65 | then |
| 66 | echo "Topdown event group test [Failed slots not reordered first]" |
| 67 | err=1 |
| 68 | return |
| 69 | fi |
| 70 | echo "Topdown event group test [Success]" |
| 71 | } |
| 72 | |
| 73 | test_topdown_weak_groups() { |
| 74 | # Weak groups break if the perf_event_open of multiple grouped events |
| 75 | # fails. Breaking a topdown group causes the events to fail. Test a very large |
| 76 | # grouping to see that the topdown events aren't broken out. |
| 77 | echo "Topdown weak groups test" |
| 78 | 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" |
| 79 | if ! perf stat --no-merge -e "$ok_grouping" true > /dev/null 2>&1 |
| 80 | then |
| 81 | echo "Topdown weak groups test [Skipped event parsing failed]" |
| 82 | return |
| 83 | fi |
| 84 | 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" |
| 85 | if perf stat --no-merge -e "$group_needs_break" true 2>&1 | egrep -q "<not supported>" |
| 86 | then |
| 87 | echo "Topdown weak groups test [Failed events not supported]" |
| 88 | err=1 |
| 89 | return |
| 90 | fi |
| 91 | echo "Topdown weak groups test [Success]" |
| 92 | } |
| 93 | |
| 94 | test_default_stat |
Ian Rogers | 0dd9769 | 2022-05-18 20:20:02 -0700 | [diff] [blame] | 95 | test_stat_record_report |
Ian Rogers | 0c361c6 | 2022-08-22 14:33:52 -0700 | [diff] [blame] | 96 | test_stat_repeat_weak_groups |
Ian Rogers | 6a973e2 | 2022-05-16 22:27:24 -0700 | [diff] [blame] | 97 | test_topdown_groups |
| 98 | test_topdown_weak_groups |
| 99 | exit $err |