Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # PM-QA validation test suite for the power management on ARM |
| 4 | # |
| 5 | # Copyright (C) 2011, Linaro Limited. |
| 6 | # |
| 7 | # This program is free software; you can redistribute it and/or |
| 8 | # modify it under the terms of the GNU General Public License |
| 9 | # as published by the Free Software Foundation; either version 2 |
| 10 | # of the License, or (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with this program; if not, write to the Free Software |
| 19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | # |
| 21 | # Contributors: |
| 22 | # Daniel Lezcano <daniel.lezcano@linaro.org> (IBM Corporation) |
| 23 | # - initial API and implementation |
| 24 | # |
| 25 | |
| 26 | CPU_PATH="/sys/devices/system/cpu" |
| 27 | TEST_NAME=$(basename ${0%.sh}) |
Daniel Lezcano | 1efddc1 | 2011-08-09 23:45:30 +0200 | [diff] [blame] | 28 | PREFIX=$TEST_NAME |
| 29 | INC=0 |
| 30 | CPU= |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 31 | |
| 32 | log_begin() { |
Daniel Lezcano | 994f6f1 | 2011-08-16 13:28:33 +0200 | [diff] [blame] | 33 | printf "%-76s" "$TEST_NAME.$INC$CPU: $@... " |
Daniel Lezcano | 1efddc1 | 2011-08-09 23:45:30 +0200 | [diff] [blame] | 34 | INC=$(($INC+1)) |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | log_end() { |
| 38 | printf "$*\n" |
| 39 | } |
| 40 | |
| 41 | log_skip() { |
| 42 | log_begin "$@" |
Daniel Lezcano | ff4aa11 | 2011-08-16 15:48:38 +0200 | [diff] [blame^] | 43 | log_end "skip" |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | for_each_cpu() { |
| 47 | |
| 48 | local func=$1 |
| 49 | shift 1 |
| 50 | |
| 51 | cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") |
| 52 | |
| 53 | for cpu in $cpus; do |
Daniel Lezcano | 1efddc1 | 2011-08-09 23:45:30 +0200 | [diff] [blame] | 54 | INC=0 |
| 55 | CPU=/$cpu |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 56 | $func $cpu $@ |
| 57 | done |
| 58 | |
| 59 | return 0 |
| 60 | } |
| 61 | |
| 62 | for_each_governor() { |
| 63 | |
| 64 | local cpu=$1 |
| 65 | local func=$2 |
| 66 | local dirpath=$CPU_PATH/$cpu/cpufreq |
| 67 | local governors=$(cat $dirpath/scaling_available_governors) |
| 68 | shift 2 |
| 69 | |
| 70 | for governor in $governors; do |
| 71 | $func $cpu $governor $@ |
| 72 | done |
| 73 | |
| 74 | return 0 |
| 75 | } |
| 76 | |
| 77 | for_each_frequency() { |
| 78 | |
| 79 | local cpu=$1 |
| 80 | local func=$2 |
| 81 | local dirpath=$CPU_PATH/$cpu/cpufreq |
| 82 | local frequencies=$(cat $dirpath/scaling_available_frequencies) |
| 83 | shift 2 |
| 84 | |
| 85 | for frequency in $frequencies; do |
| 86 | $func $cpu $frequency $@ |
| 87 | done |
| 88 | |
| 89 | return 0 |
| 90 | } |
| 91 | |
| 92 | set_governor() { |
| 93 | |
| 94 | local cpu=$1 |
| 95 | local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor |
| 96 | local newgov=$2 |
| 97 | |
| 98 | echo $newgov > $dirpath |
| 99 | } |
| 100 | |
| 101 | get_governor() { |
| 102 | |
| 103 | local cpu=$1 |
| 104 | local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor |
| 105 | |
| 106 | cat $dirpath |
| 107 | } |
| 108 | |
| 109 | wait_latency() { |
| 110 | local cpu=$1 |
| 111 | local dirpath=$CPU_PATH/$cpu/cpufreq |
| 112 | local latency=$(cat $dirpath/cpuinfo_transition_latency) |
| 113 | local nrfreq=$(cat $dirpath/scaling_available_frequencies | wc -w) |
| 114 | |
| 115 | nrfreq=$((nrfreq + 1)) |
| 116 | ../utils/nanosleep $(($nrfreq * $latency)) |
| 117 | } |
| 118 | |
| 119 | frequnit() { |
| 120 | local freq=$1 |
| 121 | local ghz=$(echo "scale=1;($freq / 1000000)" | bc -l) |
| 122 | local mhz=$(echo "scale=1;($freq / 1000)" | bc -l) |
| 123 | |
| 124 | res=$(echo "($ghz > 1.0)" | bc -l) |
| 125 | if [ "$res" = "1" ]; then |
| 126 | echo $ghz GHz |
| 127 | return 0 |
| 128 | fi |
| 129 | |
| 130 | res=$(echo "($mhz > 1.0)" | bc -l) |
| 131 | if [ "$res" = "1" ];then |
| 132 | echo $mhz MHz |
| 133 | return 0 |
| 134 | fi |
| 135 | |
| 136 | echo $freq KHz |
| 137 | } |
| 138 | |
| 139 | set_frequency() { |
| 140 | |
| 141 | local cpu=$1 |
| 142 | local dirpath=$CPU_PATH/$cpu/cpufreq |
| 143 | local newfreq=$2 |
| 144 | local setfreqpath=$dirpath/scaling_setspeed |
| 145 | |
| 146 | echo $newfreq > $setfreqpath |
| 147 | wait_latency $cpu |
| 148 | } |
| 149 | |
| 150 | get_frequency() { |
| 151 | local cpu=$1 |
| 152 | local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_cur_freq |
| 153 | cat $dirpath |
| 154 | } |
| 155 | |
| 156 | get_max_frequency() { |
| 157 | local cpu=$1 |
| 158 | local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_max_freq |
| 159 | cat $dirpath |
| 160 | } |
| 161 | |
| 162 | get_min_frequency() { |
| 163 | local cpu=$1 |
| 164 | local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_min_freq |
| 165 | cat $dirpath |
| 166 | } |
| 167 | |
| 168 | check() { |
| 169 | |
| 170 | local descr=$1 |
| 171 | local func=$2 |
| 172 | shift 2; |
| 173 | |
| 174 | log_begin "checking $descr" |
| 175 | |
| 176 | $func $@ |
| 177 | if [ $? != 0 ]; then |
Daniel Lezcano | ff4aa11 | 2011-08-16 15:48:38 +0200 | [diff] [blame^] | 178 | log_end "fail" |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 179 | return 1 |
| 180 | fi |
| 181 | |
Daniel Lezcano | ff4aa11 | 2011-08-16 15:48:38 +0200 | [diff] [blame^] | 182 | log_end "pass" |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 183 | |
| 184 | return 0 |
| 185 | } |
| 186 | |
| 187 | check_cpufreq_files() { |
| 188 | |
| 189 | local dirpath=$CPU_PATH/$1/cpufreq |
| 190 | shift 1 |
| 191 | |
| 192 | for i in $@; do |
| 193 | check "$i exists" "test -f" $dirpath/$i || return 1 |
| 194 | done |
| 195 | |
| 196 | return 0 |
| 197 | } |
| 198 | |
Daniel Lezcano | a7da520 | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 199 | check_sched_mc_files() { |
| 200 | |
| 201 | local dirpath=$CPU_PATH |
| 202 | |
| 203 | for i in $@; do |
| 204 | check "$i exists" "test -f" $dirpath/$i || return 1 |
| 205 | done |
| 206 | |
| 207 | return 0 |
| 208 | } |
| 209 | |
Daniel Lezcano | bc043cb | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 210 | check_topology_files() { |
| 211 | |
| 212 | local dirpath=$CPU_PATH/$1/topology |
| 213 | shift 1 |
| 214 | |
| 215 | for i in $@; do |
| 216 | check "$i exists" "test -f" $dirpath/$i || return 1 |
| 217 | done |
| 218 | |
| 219 | return 0 |
| 220 | } |
| 221 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 222 | save_governors() { |
| 223 | |
| 224 | governors_backup= |
| 225 | local index=0 |
| 226 | |
| 227 | for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do |
| 228 | governors_backup[$index]=$(cat $CPU_PATH/$i/cpufreq/scaling_governor) |
| 229 | index=$((index + 1)) |
| 230 | done |
| 231 | } |
| 232 | |
| 233 | restore_governors() { |
| 234 | |
| 235 | local index=0 |
| 236 | local oldgov= |
| 237 | |
| 238 | for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do |
| 239 | oldgov=${governors_backup[$index]} |
| 240 | echo $oldgov > $CPU_PATH/$i/cpufreq/scaling_governor |
| 241 | index=$((index + 1)) |
| 242 | done |
| 243 | } |
| 244 | |
| 245 | save_frequencies() { |
| 246 | |
| 247 | frequencies_backup= |
| 248 | local index=0 |
| 249 | local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") |
| 250 | local cpu= |
| 251 | |
| 252 | for cpu in $cpus; do |
| 253 | frequencies_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq) |
| 254 | index=$((index + 1)) |
| 255 | done |
| 256 | } |
| 257 | |
| 258 | restore_frequencies() { |
| 259 | |
| 260 | local index=0 |
| 261 | local oldfreq= |
| 262 | local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") |
| 263 | |
| 264 | for cpu in $cpus; do |
| 265 | oldfreq=${frequencies_backup[$index]} |
| 266 | echo $oldfreq > $CPU_PATH/$cpu/cpufreq/scaling_setspeed |
| 267 | index=$((index + 1)) |
| 268 | done |
| 269 | } |
| 270 | |
| 271 | sigtrap() { |
| 272 | exit 255 |
Daniel Lezcano | 18e22b5 | 2011-08-06 02:52:02 +0200 | [diff] [blame] | 273 | } |