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 | |
Hongbo Zhang | 974802b | 2013-02-04 19:22:58 +0800 | [diff] [blame^] | 26 | source ../Switches |
| 27 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 28 | CPU_PATH="/sys/devices/system/cpu" |
| 29 | TEST_NAME=$(basename ${0%.sh}) |
Daniel Lezcano | 1efddc1 | 2011-08-09 23:45:30 +0200 | [diff] [blame] | 30 | PREFIX=$TEST_NAME |
| 31 | INC=0 |
| 32 | CPU= |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 33 | |
| 34 | log_begin() { |
Daniel Lezcano | 994f6f1 | 2011-08-16 13:28:33 +0200 | [diff] [blame] | 35 | printf "%-76s" "$TEST_NAME.$INC$CPU: $@... " |
Daniel Lezcano | 1efddc1 | 2011-08-09 23:45:30 +0200 | [diff] [blame] | 36 | INC=$(($INC+1)) |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | log_end() { |
| 40 | printf "$*\n" |
| 41 | } |
| 42 | |
| 43 | log_skip() { |
| 44 | log_begin "$@" |
Daniel Lezcano | ff4aa11 | 2011-08-16 15:48:38 +0200 | [diff] [blame] | 45 | log_end "skip" |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | for_each_cpu() { |
| 49 | |
| 50 | local func=$1 |
| 51 | shift 1 |
| 52 | |
| 53 | cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") |
| 54 | |
| 55 | for cpu in $cpus; do |
Daniel Lezcano | 1efddc1 | 2011-08-09 23:45:30 +0200 | [diff] [blame] | 56 | INC=0 |
| 57 | CPU=/$cpu |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 58 | $func $cpu $@ |
| 59 | done |
| 60 | |
| 61 | return 0 |
| 62 | } |
| 63 | |
| 64 | for_each_governor() { |
| 65 | |
| 66 | local cpu=$1 |
| 67 | local func=$2 |
| 68 | local dirpath=$CPU_PATH/$cpu/cpufreq |
| 69 | local governors=$(cat $dirpath/scaling_available_governors) |
| 70 | shift 2 |
| 71 | |
| 72 | for governor in $governors; do |
| 73 | $func $cpu $governor $@ |
| 74 | done |
| 75 | |
| 76 | return 0 |
| 77 | } |
| 78 | |
| 79 | for_each_frequency() { |
| 80 | |
| 81 | local cpu=$1 |
| 82 | local func=$2 |
| 83 | local dirpath=$CPU_PATH/$cpu/cpufreq |
| 84 | local frequencies=$(cat $dirpath/scaling_available_frequencies) |
| 85 | shift 2 |
| 86 | |
| 87 | for frequency in $frequencies; do |
| 88 | $func $cpu $frequency $@ |
| 89 | done |
| 90 | |
| 91 | return 0 |
| 92 | } |
| 93 | |
| 94 | set_governor() { |
| 95 | |
| 96 | local cpu=$1 |
| 97 | local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor |
| 98 | local newgov=$2 |
| 99 | |
| 100 | echo $newgov > $dirpath |
| 101 | } |
| 102 | |
| 103 | get_governor() { |
| 104 | |
| 105 | local cpu=$1 |
| 106 | local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor |
| 107 | |
| 108 | cat $dirpath |
| 109 | } |
| 110 | |
| 111 | wait_latency() { |
| 112 | local cpu=$1 |
| 113 | local dirpath=$CPU_PATH/$cpu/cpufreq |
Daniel Lezcano | 9338295 | 2011-09-19 11:41:39 +0200 | [diff] [blame] | 114 | local latency= |
| 115 | local nrfreq= |
| 116 | |
| 117 | latency=$(cat $dirpath/cpuinfo_transition_latency) |
| 118 | if [ $? != 0 ]; then |
Daniel Lezcano | 0b90d41 | 2011-09-20 08:31:04 +0200 | [diff] [blame] | 119 | return 1 |
Daniel Lezcano | 9338295 | 2011-09-19 11:41:39 +0200 | [diff] [blame] | 120 | fi |
| 121 | |
| 122 | nrfreq=$(cat $dirpath/scaling_available_frequencies | wc -w) |
| 123 | if [ $? != 0 ]; then |
Daniel Lezcano | 0b90d41 | 2011-09-20 08:31:04 +0200 | [diff] [blame] | 124 | return 1 |
Daniel Lezcano | 9338295 | 2011-09-19 11:41:39 +0200 | [diff] [blame] | 125 | fi |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 126 | |
| 127 | nrfreq=$((nrfreq + 1)) |
| 128 | ../utils/nanosleep $(($nrfreq * $latency)) |
| 129 | } |
| 130 | |
| 131 | frequnit() { |
| 132 | local freq=$1 |
| 133 | local ghz=$(echo "scale=1;($freq / 1000000)" | bc -l) |
| 134 | local mhz=$(echo "scale=1;($freq / 1000)" | bc -l) |
| 135 | |
| 136 | res=$(echo "($ghz > 1.0)" | bc -l) |
| 137 | if [ "$res" = "1" ]; then |
| 138 | echo $ghz GHz |
| 139 | return 0 |
| 140 | fi |
| 141 | |
| 142 | res=$(echo "($mhz > 1.0)" | bc -l) |
| 143 | if [ "$res" = "1" ];then |
| 144 | echo $mhz MHz |
| 145 | return 0 |
| 146 | fi |
| 147 | |
| 148 | echo $freq KHz |
| 149 | } |
| 150 | |
| 151 | set_frequency() { |
| 152 | |
| 153 | local cpu=$1 |
| 154 | local dirpath=$CPU_PATH/$cpu/cpufreq |
| 155 | local newfreq=$2 |
| 156 | local setfreqpath=$dirpath/scaling_setspeed |
| 157 | |
| 158 | echo $newfreq > $setfreqpath |
| 159 | wait_latency $cpu |
| 160 | } |
| 161 | |
| 162 | get_frequency() { |
| 163 | local cpu=$1 |
| 164 | local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_cur_freq |
| 165 | cat $dirpath |
| 166 | } |
| 167 | |
| 168 | get_max_frequency() { |
| 169 | local cpu=$1 |
| 170 | local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_max_freq |
| 171 | cat $dirpath |
| 172 | } |
| 173 | |
| 174 | get_min_frequency() { |
| 175 | local cpu=$1 |
| 176 | local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_min_freq |
| 177 | cat $dirpath |
| 178 | } |
| 179 | |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 180 | set_online() { |
| 181 | local cpu=$1 |
| 182 | local dirpath=$CPU_PATH/$cpu |
| 183 | |
Daniel Lezcano | 3dd53ee | 2012-04-05 14:03:08 +0200 | [diff] [blame] | 184 | if [ "$cpu" = "cpu0" ]; then |
| 185 | return 0 |
| 186 | fi |
| 187 | |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 188 | echo 1 > $dirpath/online |
| 189 | } |
| 190 | |
| 191 | set_offline() { |
| 192 | local cpu=$1 |
| 193 | local dirpath=$CPU_PATH/$cpu |
| 194 | |
Daniel Lezcano | 3dd53ee | 2012-04-05 14:03:08 +0200 | [diff] [blame] | 195 | if [ "$cpu" = "cpu0" ]; then |
| 196 | return 0 |
| 197 | fi |
| 198 | |
Daniel Lezcano | 805e335 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 199 | echo 0 > $dirpath/online |
| 200 | } |
| 201 | |
| 202 | get_online() { |
| 203 | local cpu=$1 |
| 204 | local dirpath=$CPU_PATH/$cpu |
| 205 | |
| 206 | cat $dirpath/online |
| 207 | } |
| 208 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 209 | check() { |
| 210 | |
| 211 | local descr=$1 |
| 212 | local func=$2 |
| 213 | shift 2; |
| 214 | |
| 215 | log_begin "checking $descr" |
| 216 | |
| 217 | $func $@ |
| 218 | if [ $? != 0 ]; then |
Daniel Lezcano | ff4aa11 | 2011-08-16 15:48:38 +0200 | [diff] [blame] | 219 | log_end "fail" |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 220 | return 1 |
| 221 | fi |
| 222 | |
Daniel Lezcano | ff4aa11 | 2011-08-16 15:48:38 +0200 | [diff] [blame] | 223 | log_end "pass" |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 224 | |
| 225 | return 0 |
| 226 | } |
| 227 | |
Daniel Lezcano | b6a3119 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 228 | check_file() { |
| 229 | local file=$1 |
| 230 | local dir=$2 |
| 231 | |
| 232 | check "'$file' exists" "test -f" $dir/$file |
| 233 | } |
| 234 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 235 | check_cpufreq_files() { |
| 236 | |
| 237 | local dirpath=$CPU_PATH/$1/cpufreq |
| 238 | shift 1 |
| 239 | |
| 240 | for i in $@; do |
Daniel Lezcano | b6a3119 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 241 | check_file $i $dirpath || return 1 |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 242 | done |
| 243 | |
| 244 | return 0 |
| 245 | } |
| 246 | |
Daniel Lezcano | a7da520 | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 247 | check_sched_mc_files() { |
| 248 | |
| 249 | local dirpath=$CPU_PATH |
| 250 | |
| 251 | for i in $@; do |
Daniel Lezcano | b6a3119 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 252 | check_file $i $dirpath || return 1 |
Daniel Lezcano | a7da520 | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 253 | done |
| 254 | |
| 255 | return 0 |
| 256 | } |
| 257 | |
Daniel Lezcano | bc043cb | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 258 | check_topology_files() { |
| 259 | |
| 260 | local dirpath=$CPU_PATH/$1/topology |
| 261 | shift 1 |
| 262 | |
| 263 | for i in $@; do |
Daniel Lezcano | b6a3119 | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 264 | check_file $i $dirpath || return 1 |
Daniel Lezcano | bc043cb | 2011-08-05 15:01:42 +0200 | [diff] [blame] | 265 | done |
| 266 | |
| 267 | return 0 |
| 268 | } |
| 269 | |
Daniel Lezcano | b10475e | 2011-10-03 11:07:36 +0200 | [diff] [blame] | 270 | check_cpuhotplug_files() { |
| 271 | |
| 272 | local dirpath=$CPU_PATH/$1 |
| 273 | shift 1 |
| 274 | |
| 275 | for i in $@; do |
| 276 | check_file $i $dirpath || return 1 |
| 277 | done |
| 278 | |
| 279 | return 0 |
| 280 | } |
| 281 | |
Daniel Lezcano | d84ec06 | 2011-07-26 14:38:59 +0200 | [diff] [blame] | 282 | save_governors() { |
| 283 | |
| 284 | governors_backup= |
| 285 | local index=0 |
| 286 | |
| 287 | for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do |
| 288 | governors_backup[$index]=$(cat $CPU_PATH/$i/cpufreq/scaling_governor) |
| 289 | index=$((index + 1)) |
| 290 | done |
| 291 | } |
| 292 | |
| 293 | restore_governors() { |
| 294 | |
| 295 | local index=0 |
| 296 | local oldgov= |
| 297 | |
| 298 | for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do |
| 299 | oldgov=${governors_backup[$index]} |
| 300 | echo $oldgov > $CPU_PATH/$i/cpufreq/scaling_governor |
| 301 | index=$((index + 1)) |
| 302 | done |
| 303 | } |
| 304 | |
| 305 | save_frequencies() { |
| 306 | |
| 307 | frequencies_backup= |
| 308 | local index=0 |
| 309 | local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") |
| 310 | local cpu= |
| 311 | |
| 312 | for cpu in $cpus; do |
| 313 | frequencies_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq) |
| 314 | index=$((index + 1)) |
| 315 | done |
| 316 | } |
| 317 | |
| 318 | restore_frequencies() { |
| 319 | |
| 320 | local index=0 |
| 321 | local oldfreq= |
| 322 | local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") |
| 323 | |
| 324 | for cpu in $cpus; do |
| 325 | oldfreq=${frequencies_backup[$index]} |
| 326 | echo $oldfreq > $CPU_PATH/$cpu/cpufreq/scaling_setspeed |
| 327 | index=$((index + 1)) |
| 328 | done |
| 329 | } |
| 330 | |
| 331 | sigtrap() { |
| 332 | exit 255 |
Daniel Lezcano | 18e22b5 | 2011-08-06 02:52:02 +0200 | [diff] [blame] | 333 | } |