91 lines · bash
1#!/bin/bash2# perf stat CSV output linter3# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)4# Tests various perf stat CSV output commands for the5# correct number of fields and the CSV separator set to ','.6 7set -e8 9# shellcheck source=lib/stat_output.sh10. "$(dirname $0)"/lib/stat_output.sh11 12csv_sep=@13 14stat_output=$(mktemp /tmp/__perf_test.stat_output.csv.XXXXX)15 16cleanup() {17 rm -f "${stat_output}"18 19 trap - EXIT TERM INT20}21 22trap_cleanup() {23 cleanup24 exit 125}26trap trap_cleanup EXIT TERM INT27 28function commachecker()29{30 local -i cnt=031 local exp=032 33 case "$1"34 in "--no-args") exp=635 ;; "--system-wide") exp=636 ;; "--event") exp=637 ;; "--interval") exp=738 ;; "--per-thread") exp=739 ;; "--system-wide-no-aggr") exp=740 [ "$(uname -m)" = "s390x" ] && exp='^[6-7]$'41 ;; "--per-core") exp=842 ;; "--per-socket") exp=843 ;; "--per-node") exp=844 ;; "--per-die") exp=845 ;; "--per-cluster") exp=846 ;; "--per-cache") exp=847 esac48 49 while read line50 do51 # Ignore initial "started on" comment.52 x=${line:0:1}53 [ "$x" = "#" ] && continue54 # Ignore initial blank line.55 [ "$line" = "" ] && continue56 57 # Count the number of commas58 x=$(echo $line | tr -d -c $csv_sep)59 cnt="${#x}"60 # echo $line $cnt61 [[ ! "$cnt" =~ $exp ]] && {62 echo "wrong number of fields. expected $exp in $line" 1>&263 exit 1;64 }65 done < "${stat_output}"66 return 067}68 69perf_cmd="-x$csv_sep -o ${stat_output}"70 71skip_test=$(check_for_topology)72check_no_args "CSV" "$perf_cmd"73check_system_wide "CSV" "$perf_cmd"74check_interval "CSV" "$perf_cmd"75check_event "CSV" "$perf_cmd"76check_per_thread "CSV" "$perf_cmd"77check_per_node "CSV" "$perf_cmd"78if [ $skip_test -ne 1 ]79then80 check_system_wide_no_aggr "CSV" "$perf_cmd"81 check_per_core "CSV" "$perf_cmd"82 check_per_cache_instance "CSV" "$perf_cmd"83 check_per_cluster "CSV" "$perf_cmd"84 check_per_die "CSV" "$perf_cmd"85 check_per_socket "CSV" "$perf_cmd"86else87 echo "[Skip] Skipping tests for system_wide_no_aggr, per_core, per_die and per_socket since socket id exposed via topology is invalid"88fi89cleanup90exit 091