0001
0002
0003
0004
0005
0006
0007 set -e
0008
0009 pythonchecker=$(dirname $0)/lib/perf_json_output_lint.py
0010 if [ "x$PYTHON" == "x" ]
0011 then
0012 if which python3 > /dev/null
0013 then
0014 PYTHON=python3
0015 elif which python > /dev/null
0016 then
0017 PYTHON=python
0018 else
0019 echo Skipping test, python not detected please set environment variable PYTHON.
0020 exit 2
0021 fi
0022 fi
0023
0024
0025 function ParanoidAndNotRoot()
0026 {
0027 [ $(id -u) != 0 ] && [ $(cat /proc/sys/kernel/perf_event_paranoid) -gt $1 ]
0028 }
0029
0030 check_no_args()
0031 {
0032 echo -n "Checking json output: no args "
0033 perf stat -j true 2>&1 | $PYTHON $pythonchecker --no-args
0034 echo "[Success]"
0035 }
0036
0037 check_system_wide()
0038 {
0039 echo -n "Checking json output: system wide "
0040 if ParanoidAndNotRoot 0
0041 then
0042 echo "[Skip] paranoia and not root"
0043 return
0044 fi
0045 perf stat -j -a true 2>&1 | $PYTHON $pythonchecker --system-wide
0046 echo "[Success]"
0047 }
0048
0049 check_system_wide_no_aggr()
0050 {
0051 echo -n "Checking json output: system wide "
0052 if ParanoidAndNotRoot 0
0053 then
0054 echo "[Skip] paranoia and not root"
0055 return
0056 fi
0057 echo -n "Checking json output: system wide no aggregation "
0058 perf stat -j -A -a --no-merge true 2>&1 | $PYTHON $pythonchecker --system-wide-no-aggr
0059 echo "[Success]"
0060 }
0061
0062 check_interval()
0063 {
0064 echo -n "Checking json output: interval "
0065 perf stat -j -I 1000 true 2>&1 | $PYTHON $pythonchecker --interval
0066 echo "[Success]"
0067 }
0068
0069
0070 check_event()
0071 {
0072 echo -n "Checking json output: event "
0073 perf stat -j -e cpu-clock true 2>&1 | $PYTHON $pythonchecker --event
0074 echo "[Success]"
0075 }
0076
0077 check_per_core()
0078 {
0079 echo -n "Checking json output: per core "
0080 if ParanoidAndNotRoot 0
0081 then
0082 echo "[Skip] paranoia and not root"
0083 return
0084 fi
0085 perf stat -j --per-core -a true 2>&1 | $PYTHON $pythonchecker --per-core
0086 echo "[Success]"
0087 }
0088
0089 check_per_thread()
0090 {
0091 echo -n "Checking json output: per thread "
0092 if ParanoidAndNotRoot 0
0093 then
0094 echo "[Skip] paranoia and not root"
0095 return
0096 fi
0097 perf stat -j --per-thread -a true 2>&1 | $PYTHON $pythonchecker --per-thread
0098 echo "[Success]"
0099 }
0100
0101 check_per_die()
0102 {
0103 echo -n "Checking json output: per die "
0104 if ParanoidAndNotRoot 0
0105 then
0106 echo "[Skip] paranoia and not root"
0107 return
0108 fi
0109 perf stat -j --per-die -a true 2>&1 | $PYTHON $pythonchecker --per-die
0110 echo "[Success]"
0111 }
0112
0113 check_per_node()
0114 {
0115 echo -n "Checking json output: per node "
0116 if ParanoidAndNotRoot 0
0117 then
0118 echo "[Skip] paranoia and not root"
0119 return
0120 fi
0121 perf stat -j --per-node -a true 2>&1 | $PYTHON $pythonchecker --per-node
0122 echo "[Success]"
0123 }
0124
0125 check_per_socket()
0126 {
0127 echo -n "Checking json output: per socket "
0128 if ParanoidAndNotRoot 0
0129 then
0130 echo "[Skip] paranoia and not root"
0131 return
0132 fi
0133 perf stat -j --per-socket -a true 2>&1 | $PYTHON $pythonchecker --per-socket
0134 echo "[Success]"
0135 }
0136
0137 check_no_args
0138 check_system_wide
0139 check_system_wide_no_aggr
0140 check_interval
0141 check_event
0142 check_per_core
0143 check_per_thread
0144 check_per_die
0145 check_per_node
0146 check_per_socket
0147 exit 0