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