Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Daniel Lezcano | 35fb172 | 2011-10-03 13:56:11 +0200 | [diff] [blame] | 3 | # PM-QA validation test suite for the power management on Linux |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 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 |
Daniel Lezcano | 9338295 | 2011-09-19 11:41:39 +0200 | [diff] [blame] | 112 | local latency= |
| 113 | local nrfreq= |
| 114 | |
| 115 | latency=$(cat $dirpath/cpuinfo_transition_latency) |
| 116 | if [ $? != 0 ]; then |
Daniel Lezcano | 0b90d41 | 2011-09-20 08:31:04 +0200 | [diff] [blame] | 117 | return 1 |
Daniel Lezcano | 9338295 | 2011-09-19 11:41:39 +0200 | [diff] [blame] | 118 | fi |
| 119 | |
| 120 | nrfreq=$(cat $dirpath/scaling_available_frequencies | wc -w) |
| 121 | if [ $? != 0 ]; then |
Daniel Lezcano | 0b90d41 | 2011-09-20 08:31:04 +0200 | [diff] [blame] | 122 | return 1 |
Daniel Lezcano | 9338295 | 2011-09-19 11:41:39 +0200 | [diff] [blame] | 123 | fi |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 124 | |
| 125 | nrfreq=$((nrfreq + 1)) |
| 126 | ../utils/nanosleep $(($nrfreq * $latency)) |
| 127 | } |
| 128 | |
| 129 | frequnit() { |
| 130 | local freq=$1 |
| 131 | local ghz=$(echo "scale=1;($freq / 1000000)" | bc -l) |
| 132 | local mhz=$(echo "scale=1;($freq / 1000)" | bc -l) |
| 133 | |
| 134 | res=$(echo "($ghz > 1.0)" | bc -l) |
| 135 | if [ "$res" = "1" ]; then |
| 136 | echo $ghz GHz |
| 137 | return 0 |
| 138 | fi |
| 139 | |
| 140 | res=$(echo "($mhz > 1.0)" | bc -l) |
| 141 | if [ "$res" = "1" ];then |
| 142 | echo $mhz MHz |
| 143 | return 0 |
| 144 | fi |
| 145 | |
| 146 | echo $freq KHz |
| 147 | } |
| 148 | |
| 149 | set_frequency() { |
| 150 | |
| 151 | local cpu=$1 |
| 152 | local dirpath=$CPU_PATH/$cpu/cpufreq |
| 153 | local newfreq=$2 |
| 154 | local setfreqpath=$dirpath/scaling_setspeed |
| 155 | |
| 156 | echo $newfreq > $setfreqpath |
| 157 | wait_latency $cpu |
| 158 | } |
| 159 | |
| 160 | get_frequency() { |
| 161 | local cpu=$1 |
| 162 | local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_cur_freq |
| 163 | cat $dirpath |
| 164 | } |
| 165 | |
| 166 | get_max_frequency() { |
| 167 | local cpu=$1 |
| 168 | local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_max_freq |
| 169 | cat $dirpath |
| 170 | } |
| 171 | |
| 172 | get_min_frequency() { |
| 173 | local cpu=$1 |
| 174 | local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_min_freq |
| 175 | cat $dirpath |
| 176 | } |
| 177 | |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 178 | set_online() { |
| 179 | local cpu=$1 |
| 180 | local dirpath=$CPU_PATH/$cpu |
| 181 | |
Daniel Lezcano | 3dd53ee | 2012-04-05 14:03:08 +0200 | [diff] [blame] | 182 | if [ "$cpu" = "cpu0" ]; then |
| 183 | return 0 |
| 184 | fi |
| 185 | |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 186 | echo 1 > $dirpath/online |
| 187 | } |
| 188 | |
| 189 | set_offline() { |
| 190 | local cpu=$1 |
| 191 | local dirpath=$CPU_PATH/$cpu |
| 192 | |
Daniel Lezcano | 3dd53ee | 2012-04-05 14:03:08 +0200 | [diff] [blame] | 193 | if [ "$cpu" = "cpu0" ]; then |
| 194 | return 0 |
| 195 | fi |
| 196 | |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 197 | echo 0 > $dirpath/online |
| 198 | } |
| 199 | |
| 200 | get_online() { |
| 201 | local cpu=$1 |
| 202 | local dirpath=$CPU_PATH/$cpu |
| 203 | |
| 204 | cat $dirpath/online |
| 205 | } |
| 206 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 207 | check() { |
| 208 | |
| 209 | local descr=$1 |
| 210 | local func=$2 |
| 211 | shift 2; |
| 212 | |
| 213 | log_begin "checking $descr" |
| 214 | |
| 215 | $func $@ |
| 216 | if [ $? != 0 ]; then |
Daniel Lezcano | ff4aa11 | 2011-08-16 15:48:38 +0200 | [diff] [blame] | 217 | log_end "fail" |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 218 | return 1 |
| 219 | fi |
| 220 | |
Daniel Lezcano | ff4aa11 | 2011-08-16 15:48:38 +0200 | [diff] [blame] | 221 | log_end "pass" |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 222 | |
| 223 | return 0 |
| 224 | } |
| 225 | |
Daniel Lezcano | b6a3119 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 226 | check_file() { |
| 227 | local file=$1 |
| 228 | local dir=$2 |
| 229 | |
| 230 | check "'$file' exists" "test -f" $dir/$file |
| 231 | } |
| 232 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 233 | check_cpufreq_files() { |
| 234 | |
| 235 | local dirpath=$CPU_PATH/$1/cpufreq |
| 236 | shift 1 |
| 237 | |
| 238 | for i in $@; do |
Daniel Lezcano | b6a3119 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 239 | check_file $i $dirpath || return 1 |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 240 | done |
| 241 | |
| 242 | return 0 |
| 243 | } |
| 244 | |
Daniel Lezcano | a7da520 | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 245 | check_sched_mc_files() { |
| 246 | |
| 247 | local dirpath=$CPU_PATH |
| 248 | |
| 249 | for i in $@; do |
Daniel Lezcano | b6a3119 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 250 | check_file $i $dirpath || return 1 |
Daniel Lezcano | a7da520 | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 251 | done |
| 252 | |
| 253 | return 0 |
| 254 | } |
| 255 | |
Daniel Lezcano | bc043cb | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 256 | check_topology_files() { |
| 257 | |
| 258 | local dirpath=$CPU_PATH/$1/topology |
| 259 | shift 1 |
| 260 | |
| 261 | for i in $@; do |
Daniel Lezcano | b6a3119 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 262 | check_file $i $dirpath || return 1 |
Daniel Lezcano | bc043cb | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 263 | done |
| 264 | |
| 265 | return 0 |
| 266 | } |
| 267 | |
Daniel Lezcano | b10475e | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 268 | check_cpuhotplug_files() { |
| 269 | |
| 270 | local dirpath=$CPU_PATH/$1 |
| 271 | shift 1 |
| 272 | |
| 273 | for i in $@; do |
| 274 | check_file $i $dirpath || return 1 |
| 275 | done |
| 276 | |
| 277 | return 0 |
| 278 | } |
| 279 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 280 | save_governors() { |
| 281 | |
| 282 | governors_backup= |
| 283 | local index=0 |
| 284 | |
| 285 | for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do |
| 286 | governors_backup[$index]=$(cat $CPU_PATH/$i/cpufreq/scaling_governor) |
| 287 | index=$((index + 1)) |
| 288 | done |
| 289 | } |
| 290 | |
| 291 | restore_governors() { |
| 292 | |
| 293 | local index=0 |
| 294 | local oldgov= |
| 295 | |
| 296 | for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do |
| 297 | oldgov=${governors_backup[$index]} |
| 298 | echo $oldgov > $CPU_PATH/$i/cpufreq/scaling_governor |
| 299 | index=$((index + 1)) |
| 300 | done |
| 301 | } |
| 302 | |
| 303 | save_frequencies() { |
| 304 | |
| 305 | frequencies_backup= |
| 306 | local index=0 |
| 307 | local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") |
| 308 | local cpu= |
| 309 | |
| 310 | for cpu in $cpus; do |
| 311 | frequencies_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq) |
| 312 | index=$((index + 1)) |
| 313 | done |
| 314 | } |
| 315 | |
| 316 | restore_frequencies() { |
| 317 | |
| 318 | local index=0 |
| 319 | local oldfreq= |
| 320 | local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") |
| 321 | |
| 322 | for cpu in $cpus; do |
| 323 | oldfreq=${frequencies_backup[$index]} |
| 324 | echo $oldfreq > $CPU_PATH/$cpu/cpufreq/scaling_setspeed |
| 325 | index=$((index + 1)) |
| 326 | done |
| 327 | } |
| 328 | |
| 329 | sigtrap() { |
| 330 | exit 255 |
Daniel Lezcano | 18e22b5 | 2011-08-06 02:52:02 +0200 | [diff] [blame] | 331 | } |