linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf test stat_all_pmu.sh: Parse return value of perf stat
@ 2024-04-09 13:02 vmolnaro
  2024-04-11 18:18 ` Arnaldo Carvalho de Melo
  2024-04-16 15:03 ` [PATCH] " Ian Rogers
  0 siblings, 2 replies; 18+ messages in thread
From: vmolnaro @ 2024-04-09 13:02 UTC (permalink / raw)
  To: linux-perf-users, acme, acme; +Cc: mpetlan

From: Veronika Molnarova <vmolnaro@redhat.com>

With the MR a381bd3615de6 ('powerpc/hv-gpci: Fix the
H_GET_PERF_COUNTER_INFO hcall return value checks') the perf stat for
hv_gpci events without required permission set returns an error value
of -1 to differentiate the output from the unsupported events. The
stat_all_pmu test, however, exits immediately if any command exits with
a non-zero value due to 'set -e' option.

Remove the 'set -e' option from the test and rework the test case to log
the status of the event for better maintainability. Instead of exiting
immediately after 'perf stat' ends with a non-zero value, check the
return value and output of the 'perf stat' command with appriopriate action.
---
 tools/perf/tests/shell/stat_all_pmu.sh | 36 ++++++++++++++++++--------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/tools/perf/tests/shell/stat_all_pmu.sh b/tools/perf/tests/shell/stat_all_pmu.sh
index c77955419173..d9f0d2100baa 100755
--- a/tools/perf/tests/shell/stat_all_pmu.sh
+++ b/tools/perf/tests/shell/stat_all_pmu.sh
@@ -2,21 +2,35 @@
 # perf all PMU test
 # SPDX-License-Identifier: GPL-2.0
 
-set -e
 
 # Test all PMU events; however exclude parametrized ones (name contains '?')
 for p in $(perf list --raw-dump pmu | sed 's/[[:graph:]]\+?[[:graph:]]\+[[:space:]]//g'); do
-  echo "Testing $p"
-  result=$(perf stat -e "$p" true 2>&1)
-  if ! echo "$result" | grep -q "$p" && ! echo "$result" | grep -q "<not supported>" ; then
-    # We failed to see the event and it is supported. Possibly the workload was
-    # too small so retry with something longer.
-    result=$(perf stat -e "$p" perf bench internals synthesize 2>&1)
-    if ! echo "$result" | grep -q "$p" ; then
-      echo "Event '$p' not printed in:"
-      echo "$result"
-      exit 1
+  echo -n "Testing event '$p' -- "
+  stat_output=$(perf stat -e "$p" true 2>&1)
+  stat_result=$?
+  if echo "$stat_output" | grep -q "$p"; then
+    # return value 0 if counters gets printed either if the event is supported or not
+    if [ $stat_result -eq 0 ] && ! echo "$stat_output" | grep -q "<not supported>"; then
+        echo "supported"
+    elif [ $stat_result -eq 0 ]; then
+        echo "not supported"
+    # return value 255 when the required pemission for the event is not set
+    elif [ $stat_result -eq 255 ] && echo "$stat_output" | grep -q "No permission"; then
+        echo "no permission to enable"
+    # return value 129 when trying to run 'perf stat' with a non-existent event
+    elif [ $stat_result -eq 129 ] && echo "$stat_output" | grep -q "Bad event name"; then
+        echo "Fail: Bad event name"
+        echo "$stat_output"
+        exit 1
+    else
+        echo "Fail: Unknown return value $stat_result"
+        echo "$stat_output"
+        exit 1
     fi
+  else
+      echo "Fail: Event '$p' not printed in:"
+      echo "$stat_output"
+      exit 1
   fi
 done
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2024-08-14 16:35 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-09 13:02 [PATCH] perf test stat_all_pmu.sh: Parse return value of perf stat vmolnaro
2024-04-11 18:18 ` Arnaldo Carvalho de Melo
2024-04-15  9:42   ` [PATCH v2] " vmolnaro
2024-04-15 17:41     ` Arnaldo Carvalho de Melo
2024-04-16 14:33     ` Arnaldo Carvalho de Melo
2024-04-18  7:06       ` kajoljain
2024-04-23  8:01     ` kajoljain
2024-04-26 16:30       ` Veronika Molnarova
2024-04-16 15:03 ` [PATCH] " Ian Rogers
2024-04-16 15:28   ` Arnaldo Carvalho de Melo
2024-04-29 10:56     ` [PATCH v2] " vmolnaro
2024-05-03 20:25       ` Arnaldo Carvalho de Melo
2024-05-08 10:28         ` Veronika Molnarova
2024-08-12 13:13         ` Arnaldo Carvalho de Melo
2024-08-13  7:51           ` kajoljain
2024-08-13 15:15             ` Arnaldo Carvalho de Melo
2024-08-14 16:35               ` Veronika Molnarova
2024-04-26 16:19   ` [PATCH] " Veronika Molnarova

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).