Lisa Nguyen | adf9df9 | 2015-01-25 18:16:45 -0800 | [diff] [blame] | 1 | #!/bin/sh |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 2 | # |
| 3 | # PM-QA validation test suite for the power management on Linux |
| 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 | # Amit Daniel <amit.kachhap@linaro.org> (Samsung Electronics) |
| 23 | # - initial API and implementation |
| 24 | # |
| 25 | |
| 26 | THERMAL_PATH="/sys/devices/virtual/thermal" |
| 27 | MAX_ZONE=0-12 |
| 28 | MAX_CDEV=0-50 |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 29 | |
| 30 | check_valid_temp() { |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 31 | file=$1 |
| 32 | zone_name=$2 |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame^] | 33 | dir=$THERMAL_PATH/$zone_name |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 34 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame^] | 35 | temp_file=$dir/$file |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 36 | shift 2; |
| 37 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame^] | 38 | temp_val=$(cat $temp_file) |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 39 | descr="'$zone_name'/'$file' ='$temp_val'" |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 40 | log_begin "checking $descr" |
| 41 | |
hongbo.zhang | 2a303c9 | 2012-11-22 18:20:24 +0800 | [diff] [blame] | 42 | if [ $temp_val -gt 0 ]; then |
Sanjay Singh Rawat | 3ab6406 | 2014-07-08 16:50:56 +0200 | [diff] [blame] | 43 | log_end "Ok" |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 44 | return 0 |
| 45 | fi |
| 46 | |
Sanjay Singh Rawat | 3ab6406 | 2014-07-08 16:50:56 +0200 | [diff] [blame] | 47 | log_end "Err" |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 48 | |
| 49 | return 1 |
| 50 | } |
| 51 | |
| 52 | for_each_thermal_zone() { |
| 53 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame^] | 54 | thermal_func=$1 |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 55 | shift 1 |
| 56 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame^] | 57 | thermal_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 58 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame^] | 59 | for thermal_zone in $zones; do |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 60 | INC=0 |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame^] | 61 | $thermal_func $thermal_zone $@ |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 62 | done |
| 63 | |
| 64 | return 0 |
| 65 | } |
| 66 | |
| 67 | get_total_trip_point_of_zone() { |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame^] | 68 | zone=$1 |
| 69 | zone_path=$THERMAL_PATH/$zone |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 70 | count=0 |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 71 | shift 1 |
| 72 | trips=$(ls $zone_path | grep "trip_point_['$MAX_ZONE']_temp") |
Amit Daniel Kachhap | 1fe389c | 2012-04-04 15:14:38 +0530 | [diff] [blame] | 73 | for trip in $trips; do |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 74 | count=$((count + 1)) |
| 75 | done |
| 76 | return $count |
| 77 | } |
| 78 | |
| 79 | for_each_trip_point_of_zone() { |
| 80 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 81 | zone_path=$THERMAL_PATH/$1 |
| 82 | count=0 |
| 83 | func=$2 |
| 84 | zone_name=$1 |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 85 | shift 2 |
| 86 | trips=$(ls $zone_path | grep "trip_point_['$MAX_ZONE']_temp") |
| 87 | for trip in $trips; do |
Amit Daniel Kachhap | 1fe389c | 2012-04-04 15:14:38 +0530 | [diff] [blame] | 88 | $func $zone_name $count |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 89 | count=$((count + 1)) |
| 90 | done |
| 91 | return 0 |
| 92 | } |
| 93 | |
| 94 | for_each_binding_of_zone() { |
| 95 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 96 | zone_path=$THERMAL_PATH/$1 |
| 97 | count=0 |
| 98 | func=$2 |
| 99 | zone_name=$1 |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 100 | shift 2 |
| 101 | trips=$(ls $zone_path | grep "cdev['$MAX_CDEV']_trip_point") |
| 102 | for trip in $trips; do |
Amit Daniel Kachhap | 1fe389c | 2012-04-04 15:14:38 +0530 | [diff] [blame] | 103 | $func $zone_name $count |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 104 | count=$((count + 1)) |
| 105 | done |
| 106 | |
| 107 | return 0 |
| 108 | |
| 109 | } |
| 110 | |
| 111 | check_valid_binding() { |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 112 | trip_point=$1 |
| 113 | zone_name=$2 |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame^] | 114 | dirpath=$THERMAL_PATH/$zone_name |
| 115 | temp_file=$zone_name/$trip_point |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 116 | trip_point_val=$(cat $dirpath/$trip_point) |
Amit Daniel Kachhap | 1fe389c | 2012-04-04 15:14:38 +0530 | [diff] [blame] | 117 | get_total_trip_point_of_zone $zone_name |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 118 | trip_point_max=$? |
| 119 | descr="'$temp_file' valid binding" |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 120 | shift 2 |
| 121 | |
| 122 | log_begin "checking $descr" |
Amit Daniel Kachhap | 23b5694 | 2012-05-05 15:18:29 +0530 | [diff] [blame] | 123 | if [ $trip_point_val -ge $trip_point_max ]; then |
Lisa Nguyen | 01a0286 | 2014-07-21 16:51:43 -0700 | [diff] [blame] | 124 | log_end "Err" |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 125 | return 1 |
| 126 | fi |
| 127 | |
Lisa Nguyen | 01a0286 | 2014-07-21 16:51:43 -0700 | [diff] [blame] | 128 | log_end "Ok" |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 129 | return 0 |
| 130 | } |
| 131 | |
| 132 | validate_trip_bindings() { |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 133 | zone_name=$1 |
| 134 | bind_no=$2 |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame^] | 135 | dirpath=$THERMAL_PATH/$zone_name |
| 136 | trip_point=cdev"$bind_no"_trip_point |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 137 | shift 2 |
| 138 | |
| 139 | check_file $trip_point $dirpath || return 1 |
| 140 | check_valid_binding $trip_point $zone_name || return 1 |
| 141 | } |
| 142 | |
| 143 | validate_trip_level() { |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 144 | zone_name=$1 |
| 145 | trip_no=$2 |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame^] | 146 | dirpath=$THERMAL_PATH/$zone_name |
| 147 | trip_temp=trip_point_"$trip_no"_temp |
| 148 | trip_type=trip_point_"$trip_no"_type |
Amit Daniel Kachhap | 199ea5d | 2012-03-26 16:07:35 +0530 | [diff] [blame] | 149 | shift 2 |
| 150 | |
| 151 | check_file $trip_temp $dirpath || return 1 |
| 152 | check_file $trip_type $dirpath || return 1 |
| 153 | check_valid_temp $trip_temp $zone_name || return 1 |
| 154 | } |
Amit Daniel Kachhap | 87adb0d | 2012-03-26 16:13:29 +0530 | [diff] [blame] | 155 | |
| 156 | for_each_cooling_device() { |
| 157 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame^] | 158 | cdev_func=$1 |
Amit Daniel Kachhap | 87adb0d | 2012-03-26 16:13:29 +0530 | [diff] [blame] | 159 | shift 1 |
| 160 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame^] | 161 | cooling_devices=$(ls $THERMAL_PATH | grep "cooling_device['$MAX_CDEV']") |
| 162 | if [ "$cooling_devices" = "" ]; then |
Sanjay Singh Rawat | 15bcbd5 | 2014-07-07 16:47:12 +0200 | [diff] [blame] | 163 | log_skip "no cooling devices" |
| 164 | return 0 |
| 165 | fi |
Amit Daniel Kachhap | 87adb0d | 2012-03-26 16:13:29 +0530 | [diff] [blame] | 166 | |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame^] | 167 | for cooling_device in $cooling_devices; do |
Amit Daniel Kachhap | 87adb0d | 2012-03-26 16:13:29 +0530 | [diff] [blame] | 168 | INC=0 |
Lisa Nguyen | 2d49a68 | 2015-01-26 20:27:48 -0800 | [diff] [blame^] | 169 | $cdev_func $cooling_device $@ |
Amit Daniel Kachhap | 87adb0d | 2012-03-26 16:13:29 +0530 | [diff] [blame] | 170 | done |
| 171 | |
| 172 | return 0 |
| 173 | } |
Amit Daniel Kachhap | aa11958 | 2012-03-26 16:52:20 +0530 | [diff] [blame] | 174 | check_scaling_freq() { |
| 175 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 176 | before_freq_list=$1 |
| 177 | after_freq_list=$2 |
Amit Daniel Kachhap | aa11958 | 2012-03-26 16:52:20 +0530 | [diff] [blame] | 178 | shift 2 |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 179 | index=0 |
Amit Daniel Kachhap | aa11958 | 2012-03-26 16:52:20 +0530 | [diff] [blame] | 180 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 181 | flag=0 |
Lisa Nguyen | 188ca9a | 2014-08-11 12:21:08 -0700 | [diff] [blame] | 182 | for cpu in $cpus; do |
Javi Merino | 236ec09 | 2014-09-23 17:38:54 +0530 | [diff] [blame] | 183 | if [ ${before_freq_list[$index]} -ne ${after_freq_list[$index]} ] ; then |
Amit Daniel Kachhap | aa11958 | 2012-03-26 16:52:20 +0530 | [diff] [blame] | 184 | flag=1 |
| 185 | fi |
| 186 | index=$((index + 1)) |
| 187 | done |
| 188 | return $flag |
| 189 | } |
| 190 | |
| 191 | store_scaling_maxfreq() { |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 192 | index=0 |
Amit Daniel Kachhap | aa11958 | 2012-03-26 16:52:20 +0530 | [diff] [blame] | 193 | |
Lisa Nguyen | 188ca9a | 2014-08-11 12:21:08 -0700 | [diff] [blame] | 194 | for cpu in $cpus; do |
Amit Daniel Kachhap | aa11958 | 2012-03-26 16:52:20 +0530 | [diff] [blame] | 195 | scale_freq[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_max_freq) |
| 196 | index=$((index + 1)) |
| 197 | done |
| 198 | return 0 |
| 199 | } |
Amit Daniel Kachhap | d57a91c | 2012-03-26 17:06:54 +0530 | [diff] [blame] | 200 | |
| 201 | get_trip_id() { |
| 202 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 203 | trip_name=$1 |
Amit Daniel Kachhap | d57a91c | 2012-03-26 17:06:54 +0530 | [diff] [blame] | 204 | shift 1 |
| 205 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 206 | id1=$(echo $trip_name|cut -c12) |
| 207 | id2=$(echo $trip_name|cut -c13) |
Amit Daniel Kachhap | d57a91c | 2012-03-26 17:06:54 +0530 | [diff] [blame] | 208 | if [ $id2 != "_" ]; then |
| 209 | id1=$(($id2 + 10*$id1)) |
| 210 | fi |
| 211 | return $id1 |
| 212 | } |
Amit Daniel Kachhap | 58b807b | 2012-04-04 12:23:08 +0530 | [diff] [blame] | 213 | |
| 214 | disable_all_thermal_zones() { |
| 215 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 216 | index=0 |
Amit Daniel Kachhap | 58b807b | 2012-04-04 12:23:08 +0530 | [diff] [blame] | 217 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 218 | th_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") |
Amit Daniel Kachhap | 58b807b | 2012-04-04 12:23:08 +0530 | [diff] [blame] | 219 | for zone in $th_zones; do |
| 220 | mode_list[$index]=$(cat $THERMAL_PATH/$zone/mode) |
| 221 | index=$((index + 1)) |
| 222 | echo -n "disabled" > $THERMAL_PATH/$zone/mode |
| 223 | done |
| 224 | return 0 |
| 225 | } |
| 226 | |
| 227 | enable_all_thermal_zones() { |
| 228 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 229 | index=0 |
Amit Daniel Kachhap | 58b807b | 2012-04-04 12:23:08 +0530 | [diff] [blame] | 230 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 231 | th_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") |
Amit Daniel Kachhap | 58b807b | 2012-04-04 12:23:08 +0530 | [diff] [blame] | 232 | for zone in $th_zones; do |
Javi Merino | 236ec09 | 2014-09-23 17:38:54 +0530 | [diff] [blame] | 233 | echo ${mode_list[$index]} > $THERMAL_PATH/$zone/mode |
Amit Daniel Kachhap | 58b807b | 2012-04-04 12:23:08 +0530 | [diff] [blame] | 234 | index=$((index + 1)) |
| 235 | done |
| 236 | return 0 |
| 237 | } |
Hongbo Zhang | 4080751 | 2013-01-09 15:01:11 +0800 | [diff] [blame] | 238 | |
| 239 | GPU_HEAT_BIN=/usr/bin/glmark2 |
| 240 | gpu_pid=0 |
| 241 | |
| 242 | start_glmark2() { |
Hongbo Zhang | 0f6d3c9 | 2013-01-21 16:32:25 +0800 | [diff] [blame] | 243 | if [ -n "$ANDROID" ]; then |
| 244 | am start org.linaro.glmark2/.Glmark2Activity |
| 245 | return |
| 246 | fi |
| 247 | |
Hongbo Zhang | 4080751 | 2013-01-09 15:01:11 +0800 | [diff] [blame] | 248 | if [ -x $GPU_HEAT_BIN ]; then |
| 249 | $GPU_HEAT_BIN & |
| 250 | gpu_pid=$(pidof $GPU_HEAT_BIN) |
| 251 | # Starting X application from serial console needs this |
| 252 | if [ -z "$gpu_pid" ]; then |
| 253 | cp /etc/lightdm/lightdm.conf /etc/lightdm/lightdm.conf.bk |
| 254 | echo "autologin-user=root" >> /etc/lightdm/lightdm.conf |
| 255 | export DISPLAY=localhost:0.0 |
| 256 | restart lightdm |
| 257 | sleep 5 |
| 258 | mv /etc/lightdm/lightdm.conf.bk /etc/lightdm/lightdm.conf |
| 259 | $GPU_HEAT_BIN & |
| 260 | gpu_pid=$(pidof $GPU_HEAT_BIN) |
| 261 | fi |
| 262 | test -z "$gpu_pid" && cpu_pid=0 |
| 263 | echo "start gpu heat binary $gpu_pid" |
| 264 | else |
| 265 | echo "glmark2 not found." 1>&2 |
| 266 | fi |
| 267 | } |
| 268 | |
| 269 | kill_glmark2() { |
Hongbo Zhang | 0f6d3c9 | 2013-01-21 16:32:25 +0800 | [diff] [blame] | 270 | if [ -n "$ANDROID" ]; then |
| 271 | am kill org.linaro.glmark2 |
| 272 | return |
| 273 | fi |
| 274 | |
Sanjay Singh Rawat | c7af87b | 2013-12-15 13:30:37 +0530 | [diff] [blame] | 275 | if [ "$gpu_pid" -ne 0 ]; then |
Hongbo Zhang | 4080751 | 2013-01-09 15:01:11 +0800 | [diff] [blame] | 276 | kill -9 $gpu_pid |
| 277 | fi |
| 278 | } |
Javi Merino | 07b4b6b | 2014-09-23 16:57:45 +0530 | [diff] [blame] | 279 | |
| 280 | set_thermal_governors() { |
| 281 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 282 | gov=$1 |
| 283 | index=0 |
Javi Merino | 07b4b6b | 2014-09-23 16:57:45 +0530 | [diff] [blame] | 284 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 285 | th_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") |
Javi Merino | 07b4b6b | 2014-09-23 16:57:45 +0530 | [diff] [blame] | 286 | for zone in $th_zones; do |
| 287 | thermal_governor_backup[$index]=$(cat $THERMAL_PATH/$zone/policy) |
| 288 | index=$((index + 1)) |
| 289 | echo $gov > $THERMAL_PATH/$zone/policy |
| 290 | done |
| 291 | return 0 |
| 292 | } |
| 293 | |
| 294 | restore_thermal_governors() { |
| 295 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 296 | index=0 |
Javi Merino | 07b4b6b | 2014-09-23 16:57:45 +0530 | [diff] [blame] | 297 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 298 | th_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") |
Javi Merino | 07b4b6b | 2014-09-23 16:57:45 +0530 | [diff] [blame] | 299 | for zone in $th_zones; do |
| 300 | echo ${thermal_governor_backup[$index]} > $THERMAL_PATH/$zone/policy |
| 301 | index=$((index + 1)) |
| 302 | done |
| 303 | return 0 |
| 304 | } |