xref: /openbmc/linux/tools/perf/tests/shell/stat.sh (revision 0c361c6e)
16a973e29SIan Rogers#!/bin/sh
26a973e29SIan Rogers# perf stat tests
36a973e29SIan Rogers# SPDX-License-Identifier: GPL-2.0
46a973e29SIan Rogers
56a973e29SIan Rogersset -e
66a973e29SIan Rogers
76a973e29SIan Rogerserr=0
86a973e29SIan Rogerstest_default_stat() {
96a973e29SIan Rogers  echo "Basic stat command test"
106a973e29SIan Rogers  if ! perf stat true 2>&1 | egrep -q "Performance counter stats for 'true':"
116a973e29SIan Rogers  then
126a973e29SIan Rogers    echo "Basic stat command test [Failed]"
136a973e29SIan Rogers    err=1
146a973e29SIan Rogers    return
156a973e29SIan Rogers  fi
166a973e29SIan Rogers  echo "Basic stat command test [Success]"
176a973e29SIan Rogers}
186a973e29SIan Rogers
190dd9769fSIan Rogerstest_stat_record_report() {
200dd9769fSIan Rogers  echo "stat record and report test"
210dd9769fSIan Rogers  if ! perf stat record -o - true | perf stat report -i - 2>&1 | \
220dd9769fSIan Rogers    egrep -q "Performance counter stats for 'pipe':"
230dd9769fSIan Rogers  then
240dd9769fSIan Rogers    echo "stat record and report test [Failed]"
250dd9769fSIan Rogers    err=1
260dd9769fSIan Rogers    return
270dd9769fSIan Rogers  fi
280dd9769fSIan Rogers  echo "stat record and report test [Success]"
290dd9769fSIan Rogers}
300dd9769fSIan Rogers
31*0c361c6eSIan Rogerstest_stat_repeat_weak_groups() {
32*0c361c6eSIan Rogers  echo "stat repeat weak groups test"
33*0c361c6eSIan Rogers  if ! perf stat -e '{cycles,cycles,cycles,cycles,cycles,cycles,cycles,cycles,cycles,cycles}' \
34*0c361c6eSIan Rogers     true 2>&1 | grep -q 'seconds time elapsed'
35*0c361c6eSIan Rogers  then
36*0c361c6eSIan Rogers    echo "stat repeat weak groups test [Skipped event parsing failed]"
37*0c361c6eSIan Rogers    return
38*0c361c6eSIan Rogers  fi
39*0c361c6eSIan Rogers  if ! perf stat -r2 -e '{cycles,cycles,cycles,cycles,cycles,cycles,cycles,cycles,cycles,cycles}:W' \
40*0c361c6eSIan Rogers    true > /dev/null 2>&1
41*0c361c6eSIan Rogers  then
42*0c361c6eSIan Rogers    echo "stat repeat weak groups test [Failed]"
43*0c361c6eSIan Rogers    err=1
44*0c361c6eSIan Rogers    return
45*0c361c6eSIan Rogers  fi
46*0c361c6eSIan Rogers  echo "stat repeat weak groups test [Success]"
47*0c361c6eSIan Rogers}
48*0c361c6eSIan Rogers
496a973e29SIan Rogerstest_topdown_groups() {
506a973e29SIan Rogers  # Topdown events must be grouped with the slots event first. Test that
516a973e29SIan Rogers  # parse-events reorders this.
526a973e29SIan Rogers  echo "Topdown event group test"
536a973e29SIan Rogers  if ! perf stat -e '{slots,topdown-retiring}' true > /dev/null 2>&1
546a973e29SIan Rogers  then
556a973e29SIan Rogers    echo "Topdown event group test [Skipped event parsing failed]"
566a973e29SIan Rogers    return
576a973e29SIan Rogers  fi
586a973e29SIan Rogers  if perf stat -e '{slots,topdown-retiring}' true 2>&1 | egrep -q "<not supported>"
596a973e29SIan Rogers  then
606a973e29SIan Rogers    echo "Topdown event group test [Failed events not supported]"
616a973e29SIan Rogers    err=1
626a973e29SIan Rogers    return
636a973e29SIan Rogers  fi
646a973e29SIan Rogers  if perf stat -e '{topdown-retiring,slots}' true 2>&1 | egrep -q "<not supported>"
656a973e29SIan Rogers  then
666a973e29SIan Rogers    echo "Topdown event group test [Failed slots not reordered first]"
676a973e29SIan Rogers    err=1
686a973e29SIan Rogers    return
696a973e29SIan Rogers  fi
706a973e29SIan Rogers  echo "Topdown event group test [Success]"
716a973e29SIan Rogers}
726a973e29SIan Rogers
736a973e29SIan Rogerstest_topdown_weak_groups() {
746a973e29SIan Rogers  # Weak groups break if the perf_event_open of multiple grouped events
756a973e29SIan Rogers  # fails. Breaking a topdown group causes the events to fail. Test a very large
766a973e29SIan Rogers  # grouping to see that the topdown events aren't broken out.
776a973e29SIan Rogers  echo "Topdown weak groups test"
786a973e29SIan Rogers  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"
796a973e29SIan Rogers  if ! perf stat --no-merge -e "$ok_grouping" true > /dev/null 2>&1
806a973e29SIan Rogers  then
816a973e29SIan Rogers    echo "Topdown weak groups test [Skipped event parsing failed]"
826a973e29SIan Rogers    return
836a973e29SIan Rogers  fi
846a973e29SIan Rogers  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"
856a973e29SIan Rogers  if perf stat --no-merge -e "$group_needs_break" true 2>&1 | egrep -q "<not supported>"
866a973e29SIan Rogers  then
876a973e29SIan Rogers    echo "Topdown weak groups test [Failed events not supported]"
886a973e29SIan Rogers    err=1
896a973e29SIan Rogers    return
906a973e29SIan Rogers  fi
916a973e29SIan Rogers  echo "Topdown weak groups test [Success]"
926a973e29SIan Rogers}
936a973e29SIan Rogers
946a973e29SIan Rogerstest_default_stat
950dd9769fSIan Rogerstest_stat_record_report
96*0c361c6eSIan Rogerstest_stat_repeat_weak_groups
976a973e29SIan Rogerstest_topdown_groups
986a973e29SIan Rogerstest_topdown_weak_groups
996a973e29SIan Rogersexit $err
100