xref: /linux/tools/perf/tests/shell/stat.sh (revision 7482c19173b7eb044d476b3444d7ee55bc669d03)
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 | grep -E -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    grep -E -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_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
49test_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 | grep -E -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 | grep -E -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
73test_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 | grep -E -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
94test_default_stat
95test_stat_record_report
96test_stat_repeat_weak_groups
97test_topdown_groups
98test_topdown_weak_groups
99exit $err
100