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