]> Git Repo - linux.git/blob - tools/perf/tests/shell/stat+csv_output.sh
x86/alternative: Make custom return thunk unconditional
[linux.git] / tools / perf / tests / shell / stat+csv_output.sh
1 #!/bin/bash
2 # perf stat CSV output linter
3 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
4 # Tests various perf stat CSV output commands for the
5 # correct number of fields and the CSV separator set to ','.
6
7 set -e
8
9 . $(dirname $0)/lib/stat_output.sh
10
11 csv_sep=@
12
13 stat_output=$(mktemp /tmp/__perf_test.stat_output.csv.XXXXX)
14
15 cleanup() {
16   rm -f "${stat_output}"
17
18   trap - EXIT TERM INT
19 }
20
21 trap_cleanup() {
22   cleanup
23   exit 1
24 }
25 trap trap_cleanup EXIT TERM INT
26
27 function commachecker()
28 {
29         local -i cnt=0
30         local exp=0
31
32         case "$1"
33         in "--no-args")         exp=6
34         ;; "--system-wide")     exp=6
35         ;; "--event")           exp=6
36         ;; "--interval")        exp=7
37         ;; "--per-thread")      exp=7
38         ;; "--system-wide-no-aggr")     exp=7
39                                 [ "$(uname -m)" = "s390x" ] && exp='^[6-7]$'
40         ;; "--per-core")        exp=8
41         ;; "--per-socket")      exp=8
42         ;; "--per-node")        exp=8
43         ;; "--per-die")         exp=8
44         ;; "--per-cache")       exp=8
45         esac
46
47         while read line
48         do
49                 # Ignore initial "started on" comment.
50                 x=${line:0:1}
51                 [ "$x" = "#" ] && continue
52                 # Ignore initial blank line.
53                 [ "$line" = "" ] && continue
54
55                 # Count the number of commas
56                 x=$(echo $line | tr -d -c $csv_sep)
57                 cnt="${#x}"
58                 # echo $line $cnt
59                 [[ ! "$cnt" =~ $exp ]] && {
60                         echo "wrong number of fields. expected $exp in $line" 1>&2
61                         exit 1;
62                 }
63         done < "${stat_output}"
64         return 0
65 }
66
67 perf_cmd="-x$csv_sep -o ${stat_output}"
68
69 skip_test=$(check_for_topology)
70 check_no_args "CSV" "$perf_cmd"
71 check_system_wide "CSV" "$perf_cmd"
72 check_interval "CSV" "$perf_cmd"
73 check_event "CSV" "$perf_cmd"
74 check_per_thread "CSV" "$perf_cmd"
75 check_per_node "CSV" "$perf_cmd"
76 if [ $skip_test -ne 1 ]
77 then
78         check_system_wide_no_aggr "CSV" "$perf_cmd"
79         check_per_core "CSV" "$perf_cmd"
80         check_per_cache_instance "CSV" "$perf_cmd"
81         check_per_die "CSV" "$perf_cmd"
82         check_per_socket "CSV" "$perf_cmd"
83 else
84         echo "[Skip] Skipping tests for system_wide_no_aggr, per_core, per_die and per_socket since socket id exposed via topology is invalid"
85 fi
86 cleanup
87 exit 0
This page took 0.029707 seconds and 4 git commands to generate.