blob: 0147fc0f4fe74d95e1e1912460e27a2828aaea86 [file] [log] [blame]
Lisa Nguyenadf9df92015-01-25 18:16:45 -08001#!/bin/sh
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +05302#
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
26THERMAL_PATH="/sys/devices/virtual/thermal"
27MAX_ZONE=0-12
28MAX_CDEV=0-50
Lisa Nguyen15e40ff2015-02-02 12:30:06 -080029scaling_freq_array="scaling_freq"
30mode_array="mode_list"
31thermal_gov_array="thermal_governor_backup"
32thermal_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']")
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053033
34check_valid_temp() {
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -080035 file=$1
36 zone_name=$2
Lisa Nguyen2d49a682015-01-26 20:27:48 -080037 dir=$THERMAL_PATH/$zone_name
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053038
Lisa Nguyen2d49a682015-01-26 20:27:48 -080039 temp_file=$dir/$file
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053040 shift 2;
41
Lisa Nguyen2d49a682015-01-26 20:27:48 -080042 temp_val=$(cat $temp_file)
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -080043 descr="'$zone_name'/'$file' ='$temp_val'"
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053044 log_begin "checking $descr"
45
hongbo.zhang2a303c92012-11-22 18:20:24 +080046 if [ $temp_val -gt 0 ]; then
Sanjay Singh Rawat3ab64062014-07-08 16:50:56 +020047 log_end "Ok"
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053048 return 0
49 fi
50
Sanjay Singh Rawat3ab64062014-07-08 16:50:56 +020051 log_end "Err"
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053052
53 return 1
54}
55
56for_each_thermal_zone() {
57
Lisa Nguyen2d49a682015-01-26 20:27:48 -080058 thermal_func=$1
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053059 shift 1
60
Lisa Nguyen15e40ff2015-02-02 12:30:06 -080061 for thermal_zone in $thermal_zones; do
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053062 INC=0
Lisa Nguyen2d49a682015-01-26 20:27:48 -080063 $thermal_func $thermal_zone $@
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053064 done
65
66 return 0
67}
68
69get_total_trip_point_of_zone() {
Lisa Nguyen2d49a682015-01-26 20:27:48 -080070 zone=$1
71 zone_path=$THERMAL_PATH/$zone
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -080072 count=0
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053073 shift 1
74 trips=$(ls $zone_path | grep "trip_point_['$MAX_ZONE']_temp")
Amit Daniel Kachhap1fe389c2012-04-04 15:14:38 +053075 for trip in $trips; do
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053076 count=$((count + 1))
77 done
78 return $count
79}
80
81for_each_trip_point_of_zone() {
82
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -080083 zone_path=$THERMAL_PATH/$1
84 count=0
85 func=$2
86 zone_name=$1
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053087 shift 2
88 trips=$(ls $zone_path | grep "trip_point_['$MAX_ZONE']_temp")
89 for trip in $trips; do
Amit Daniel Kachhap1fe389c2012-04-04 15:14:38 +053090 $func $zone_name $count
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053091 count=$((count + 1))
92 done
93 return 0
94}
95
96for_each_binding_of_zone() {
97
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -080098 zone_path=$THERMAL_PATH/$1
99 count=0
100 func=$2
101 zone_name=$1
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530102 shift 2
103 trips=$(ls $zone_path | grep "cdev['$MAX_CDEV']_trip_point")
104 for trip in $trips; do
Amit Daniel Kachhap1fe389c2012-04-04 15:14:38 +0530105 $func $zone_name $count
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530106 count=$((count + 1))
107 done
108
109 return 0
110
111}
112
113check_valid_binding() {
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800114 trip_point=$1
115 zone_name=$2
Lisa Nguyen2d49a682015-01-26 20:27:48 -0800116 dirpath=$THERMAL_PATH/$zone_name
117 temp_file=$zone_name/$trip_point
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800118 trip_point_val=$(cat $dirpath/$trip_point)
Amit Daniel Kachhap1fe389c2012-04-04 15:14:38 +0530119 get_total_trip_point_of_zone $zone_name
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800120 trip_point_max=$?
121 descr="'$temp_file' valid binding"
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530122 shift 2
123
124 log_begin "checking $descr"
Amit Daniel Kachhap23b56942012-05-05 15:18:29 +0530125 if [ $trip_point_val -ge $trip_point_max ]; then
Lisa Nguyen01a02862014-07-21 16:51:43 -0700126 log_end "Err"
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530127 return 1
128 fi
129
Lisa Nguyen01a02862014-07-21 16:51:43 -0700130 log_end "Ok"
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530131 return 0
132}
133
134validate_trip_bindings() {
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800135 zone_name=$1
136 bind_no=$2
Lisa Nguyen2d49a682015-01-26 20:27:48 -0800137 dirpath=$THERMAL_PATH/$zone_name
138 trip_point=cdev"$bind_no"_trip_point
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530139 shift 2
140
141 check_file $trip_point $dirpath || return 1
142 check_valid_binding $trip_point $zone_name || return 1
143}
144
145validate_trip_level() {
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800146 zone_name=$1
147 trip_no=$2
Lisa Nguyen2d49a682015-01-26 20:27:48 -0800148 dirpath=$THERMAL_PATH/$zone_name
149 trip_temp=trip_point_"$trip_no"_temp
150 trip_type=trip_point_"$trip_no"_type
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530151 shift 2
152
153 check_file $trip_temp $dirpath || return 1
154 check_file $trip_type $dirpath || return 1
155 check_valid_temp $trip_temp $zone_name || return 1
156}
Amit Daniel Kachhap87adb0d2012-03-26 16:13:29 +0530157
158for_each_cooling_device() {
159
Lisa Nguyen2d49a682015-01-26 20:27:48 -0800160 cdev_func=$1
Amit Daniel Kachhap87adb0d2012-03-26 16:13:29 +0530161 shift 1
162
Lisa Nguyen2d49a682015-01-26 20:27:48 -0800163 cooling_devices=$(ls $THERMAL_PATH | grep "cooling_device['$MAX_CDEV']")
164 if [ "$cooling_devices" = "" ]; then
Sanjay Singh Rawat15bcbd52014-07-07 16:47:12 +0200165 log_skip "no cooling devices"
166 return 0
167 fi
Amit Daniel Kachhap87adb0d2012-03-26 16:13:29 +0530168
Lisa Nguyen2d49a682015-01-26 20:27:48 -0800169 for cooling_device in $cooling_devices; do
Amit Daniel Kachhap87adb0d2012-03-26 16:13:29 +0530170 INC=0
Lisa Nguyen2d49a682015-01-26 20:27:48 -0800171 $cdev_func $cooling_device $@
Amit Daniel Kachhap87adb0d2012-03-26 16:13:29 +0530172 done
173
174 return 0
175}
Amit Daniel Kachhapaa119582012-03-26 16:52:20 +0530176check_scaling_freq() {
177
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800178 before_freq_list=$1
179 after_freq_list=$2
Amit Daniel Kachhapaa119582012-03-26 16:52:20 +0530180 shift 2
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800181 index=0
Amit Daniel Kachhapaa119582012-03-26 16:52:20 +0530182
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800183 flag=0
Lisa Nguyen188ca9a2014-08-11 12:21:08 -0700184 for cpu in $cpus; do
Lisa Nguyen15e40ff2015-02-02 12:30:06 -0800185 after_freq=$(eval echo \$$after_freq_list$index)
186 before_freq=$(eval echo \$$before_freq_list$index)
187
188 if [ $after_freq -ne $before_freq ]; then
189 flag=1
190 fi
191
192 index=$((index + 1))
193 done
194
Amit Daniel Kachhapaa119582012-03-26 16:52:20 +0530195 return $flag
196}
197
198store_scaling_maxfreq() {
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800199 index=0
Amit Daniel Kachhapaa119582012-03-26 16:52:20 +0530200
Lisa Nguyen188ca9a2014-08-11 12:21:08 -0700201 for cpu in $cpus; do
Lisa Nguyen15e40ff2015-02-02 12:30:06 -0800202 scaling_freq_max_value=$(cat $CPU_PATH/$cpu/cpufreq/scaling_max_freq)
203 eval $scaling_freq_array$index=$scaling_freq_max_value
204 eval echo $scaling_freq_array$index
Amit Daniel Kachhapaa119582012-03-26 16:52:20 +0530205 done
Lisa Nguyen15e40ff2015-02-02 12:30:06 -0800206
Amit Daniel Kachhapaa119582012-03-26 16:52:20 +0530207 return 0
208}
Amit Daniel Kachhapd57a91c2012-03-26 17:06:54 +0530209
210get_trip_id() {
211
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800212 trip_name=$1
Amit Daniel Kachhapd57a91c2012-03-26 17:06:54 +0530213 shift 1
214
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800215 id1=$(echo $trip_name|cut -c12)
216 id2=$(echo $trip_name|cut -c13)
Amit Daniel Kachhapd57a91c2012-03-26 17:06:54 +0530217 if [ $id2 != "_" ]; then
218 id1=$(($id2 + 10*$id1))
219 fi
220 return $id1
221}
Amit Daniel Kachhap58b807b2012-04-04 12:23:08 +0530222
223disable_all_thermal_zones() {
224
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800225 index=0
Amit Daniel Kachhap58b807b2012-04-04 12:23:08 +0530226
Lisa Nguyen15e40ff2015-02-02 12:30:06 -0800227 for thermal_zone in $thermal_zones; do
228 mode=$(cat $THERMAL_PATH/$thermal_zone/mode)
229 eval $mode_array$index=$mode
230 eval export $mode_array$index
Amit Daniel Kachhap58b807b2012-04-04 12:23:08 +0530231 index=$((index + 1))
Lisa Nguyen15e40ff2015-02-02 12:30:06 -0800232 echo -n "disabled" > $THERMAL_PATH/$thermal_zone/mode
Amit Daniel Kachhap58b807b2012-04-04 12:23:08 +0530233 done
Lisa Nguyen15e40ff2015-02-02 12:30:06 -0800234
Amit Daniel Kachhap58b807b2012-04-04 12:23:08 +0530235 return 0
236}
237
238enable_all_thermal_zones() {
239
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800240 index=0
Amit Daniel Kachhap58b807b2012-04-04 12:23:08 +0530241
Lisa Nguyen15e40ff2015-02-02 12:30:06 -0800242 for thermal_zone in $thermal_zones; do
243 mode=$(eval echo \$$mode_array$index)
244 echo $mode > $THERMAL_PATH/$thermal_zone/mode
Amit Daniel Kachhap58b807b2012-04-04 12:23:08 +0530245 index=$((index + 1))
246 done
Lisa Nguyen15e40ff2015-02-02 12:30:06 -0800247
Amit Daniel Kachhap58b807b2012-04-04 12:23:08 +0530248 return 0
249}
Hongbo Zhang40807512013-01-09 15:01:11 +0800250
251GPU_HEAT_BIN=/usr/bin/glmark2
252gpu_pid=0
253
254start_glmark2() {
Hongbo Zhang0f6d3c92013-01-21 16:32:25 +0800255 if [ -n "$ANDROID" ]; then
256 am start org.linaro.glmark2/.Glmark2Activity
257 return
258 fi
259
Hongbo Zhang40807512013-01-09 15:01:11 +0800260 if [ -x $GPU_HEAT_BIN ]; then
261 $GPU_HEAT_BIN &
262 gpu_pid=$(pidof $GPU_HEAT_BIN)
263 # Starting X application from serial console needs this
264 if [ -z "$gpu_pid" ]; then
265 cp /etc/lightdm/lightdm.conf /etc/lightdm/lightdm.conf.bk
266 echo "autologin-user=root" >> /etc/lightdm/lightdm.conf
267 export DISPLAY=localhost:0.0
268 restart lightdm
269 sleep 5
270 mv /etc/lightdm/lightdm.conf.bk /etc/lightdm/lightdm.conf
271 $GPU_HEAT_BIN &
272 gpu_pid=$(pidof $GPU_HEAT_BIN)
273 fi
274 test -z "$gpu_pid" && cpu_pid=0
275 echo "start gpu heat binary $gpu_pid"
276 else
277 echo "glmark2 not found." 1>&2
278 fi
279}
280
281kill_glmark2() {
Hongbo Zhang0f6d3c92013-01-21 16:32:25 +0800282 if [ -n "$ANDROID" ]; then
283 am kill org.linaro.glmark2
284 return
285 fi
286
Sanjay Singh Rawatc7af87b2013-12-15 13:30:37 +0530287 if [ "$gpu_pid" -ne 0 ]; then
Hongbo Zhang40807512013-01-09 15:01:11 +0800288 kill -9 $gpu_pid
289 fi
290}
Javi Merino07b4b6b2014-09-23 16:57:45 +0530291
292set_thermal_governors() {
293
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800294 gov=$1
295 index=0
Javi Merino07b4b6b2014-09-23 16:57:45 +0530296
Lisa Nguyen15e40ff2015-02-02 12:30:06 -0800297 for thermal_zone in $thermal_zones; do
298 policy=$(cat $THERMAL_PATH/$thermal_zone/policy)
299 eval $thermal_gov_array$index=$policy
300 eval export $thermal_gov_array$index
Javi Merino07b4b6b2014-09-23 16:57:45 +0530301 index=$((index + 1))
Lisa Nguyen15e40ff2015-02-02 12:30:06 -0800302 echo $gov > $THERMAL_PATH/$thermal_zone/policy
Javi Merino07b4b6b2014-09-23 16:57:45 +0530303 done
Lisa Nguyen15e40ff2015-02-02 12:30:06 -0800304
Javi Merino07b4b6b2014-09-23 16:57:45 +0530305 return 0
306}
307
308restore_thermal_governors() {
309
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800310 index=0
Javi Merino07b4b6b2014-09-23 16:57:45 +0530311
Lisa Nguyen15e40ff2015-02-02 12:30:06 -0800312 for thermal_zone in $thermal_zones; do
313 old_policy=$(eval echo \$$thermal_gov_array$index)
314 echo $old_policy > $THERMAL_PATH/$thermal_zone/policy
Javi Merino07b4b6b2014-09-23 16:57:45 +0530315 index=$((index + 1))
316 done
Lisa Nguyen15e40ff2015-02-02 12:30:06 -0800317
Javi Merino07b4b6b2014-09-23 16:57:45 +0530318 return 0
319}