blob: 56f9d33eddbd60ed574de704acbda71771ba7db1 [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
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053029
30check_valid_temp() {
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -080031 file=$1
32 zone_name=$2
Lisa Nguyen2d49a682015-01-26 20:27:48 -080033 dir=$THERMAL_PATH/$zone_name
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053034
Lisa Nguyen2d49a682015-01-26 20:27:48 -080035 temp_file=$dir/$file
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053036 shift 2;
37
Lisa Nguyen2d49a682015-01-26 20:27:48 -080038 temp_val=$(cat $temp_file)
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -080039 descr="'$zone_name'/'$file' ='$temp_val'"
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053040 log_begin "checking $descr"
41
hongbo.zhang2a303c92012-11-22 18:20:24 +080042 if [ $temp_val -gt 0 ]; then
Sanjay Singh Rawat3ab64062014-07-08 16:50:56 +020043 log_end "Ok"
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053044 return 0
45 fi
46
Sanjay Singh Rawat3ab64062014-07-08 16:50:56 +020047 log_end "Err"
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053048
49 return 1
50}
51
52for_each_thermal_zone() {
53
Lisa Nguyen2d49a682015-01-26 20:27:48 -080054 thermal_func=$1
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053055 shift 1
56
Lisa Nguyen2d49a682015-01-26 20:27:48 -080057 thermal_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']")
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053058
Lisa Nguyen2d49a682015-01-26 20:27:48 -080059 for thermal_zone in $zones; do
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053060 INC=0
Lisa Nguyen2d49a682015-01-26 20:27:48 -080061 $thermal_func $thermal_zone $@
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053062 done
63
64 return 0
65}
66
67get_total_trip_point_of_zone() {
Lisa Nguyen2d49a682015-01-26 20:27:48 -080068 zone=$1
69 zone_path=$THERMAL_PATH/$zone
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -080070 count=0
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053071 shift 1
72 trips=$(ls $zone_path | grep "trip_point_['$MAX_ZONE']_temp")
Amit Daniel Kachhap1fe389c2012-04-04 15:14:38 +053073 for trip in $trips; do
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053074 count=$((count + 1))
75 done
76 return $count
77}
78
79for_each_trip_point_of_zone() {
80
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -080081 zone_path=$THERMAL_PATH/$1
82 count=0
83 func=$2
84 zone_name=$1
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053085 shift 2
86 trips=$(ls $zone_path | grep "trip_point_['$MAX_ZONE']_temp")
87 for trip in $trips; do
Amit Daniel Kachhap1fe389c2012-04-04 15:14:38 +053088 $func $zone_name $count
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053089 count=$((count + 1))
90 done
91 return 0
92}
93
94for_each_binding_of_zone() {
95
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -080096 zone_path=$THERMAL_PATH/$1
97 count=0
98 func=$2
99 zone_name=$1
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530100 shift 2
101 trips=$(ls $zone_path | grep "cdev['$MAX_CDEV']_trip_point")
102 for trip in $trips; do
Amit Daniel Kachhap1fe389c2012-04-04 15:14:38 +0530103 $func $zone_name $count
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530104 count=$((count + 1))
105 done
106
107 return 0
108
109}
110
111check_valid_binding() {
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800112 trip_point=$1
113 zone_name=$2
Lisa Nguyen2d49a682015-01-26 20:27:48 -0800114 dirpath=$THERMAL_PATH/$zone_name
115 temp_file=$zone_name/$trip_point
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800116 trip_point_val=$(cat $dirpath/$trip_point)
Amit Daniel Kachhap1fe389c2012-04-04 15:14:38 +0530117 get_total_trip_point_of_zone $zone_name
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800118 trip_point_max=$?
119 descr="'$temp_file' valid binding"
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530120 shift 2
121
122 log_begin "checking $descr"
Amit Daniel Kachhap23b56942012-05-05 15:18:29 +0530123 if [ $trip_point_val -ge $trip_point_max ]; then
Lisa Nguyen01a02862014-07-21 16:51:43 -0700124 log_end "Err"
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530125 return 1
126 fi
127
Lisa Nguyen01a02862014-07-21 16:51:43 -0700128 log_end "Ok"
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530129 return 0
130}
131
132validate_trip_bindings() {
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800133 zone_name=$1
134 bind_no=$2
Lisa Nguyen2d49a682015-01-26 20:27:48 -0800135 dirpath=$THERMAL_PATH/$zone_name
136 trip_point=cdev"$bind_no"_trip_point
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530137 shift 2
138
139 check_file $trip_point $dirpath || return 1
140 check_valid_binding $trip_point $zone_name || return 1
141}
142
143validate_trip_level() {
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800144 zone_name=$1
145 trip_no=$2
Lisa Nguyen2d49a682015-01-26 20:27:48 -0800146 dirpath=$THERMAL_PATH/$zone_name
147 trip_temp=trip_point_"$trip_no"_temp
148 trip_type=trip_point_"$trip_no"_type
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530149 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 Kachhap87adb0d2012-03-26 16:13:29 +0530155
156for_each_cooling_device() {
157
Lisa Nguyen2d49a682015-01-26 20:27:48 -0800158 cdev_func=$1
Amit Daniel Kachhap87adb0d2012-03-26 16:13:29 +0530159 shift 1
160
Lisa Nguyen2d49a682015-01-26 20:27:48 -0800161 cooling_devices=$(ls $THERMAL_PATH | grep "cooling_device['$MAX_CDEV']")
162 if [ "$cooling_devices" = "" ]; then
Sanjay Singh Rawat15bcbd52014-07-07 16:47:12 +0200163 log_skip "no cooling devices"
164 return 0
165 fi
Amit Daniel Kachhap87adb0d2012-03-26 16:13:29 +0530166
Lisa Nguyen2d49a682015-01-26 20:27:48 -0800167 for cooling_device in $cooling_devices; do
Amit Daniel Kachhap87adb0d2012-03-26 16:13:29 +0530168 INC=0
Lisa Nguyen2d49a682015-01-26 20:27:48 -0800169 $cdev_func $cooling_device $@
Amit Daniel Kachhap87adb0d2012-03-26 16:13:29 +0530170 done
171
172 return 0
173}
Amit Daniel Kachhapaa119582012-03-26 16:52:20 +0530174check_scaling_freq() {
175
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800176 before_freq_list=$1
177 after_freq_list=$2
Amit Daniel Kachhapaa119582012-03-26 16:52:20 +0530178 shift 2
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800179 index=0
Amit Daniel Kachhapaa119582012-03-26 16:52:20 +0530180
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800181 flag=0
Lisa Nguyen188ca9a2014-08-11 12:21:08 -0700182 for cpu in $cpus; do
Javi Merino236ec092014-09-23 17:38:54 +0530183 if [ ${before_freq_list[$index]} -ne ${after_freq_list[$index]} ] ; then
Amit Daniel Kachhapaa119582012-03-26 16:52:20 +0530184 flag=1
185 fi
186 index=$((index + 1))
187 done
188 return $flag
189}
190
191store_scaling_maxfreq() {
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800192 index=0
Amit Daniel Kachhapaa119582012-03-26 16:52:20 +0530193
Lisa Nguyen188ca9a2014-08-11 12:21:08 -0700194 for cpu in $cpus; do
Amit Daniel Kachhapaa119582012-03-26 16:52:20 +0530195 scale_freq[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_max_freq)
196 index=$((index + 1))
197 done
198 return 0
199}
Amit Daniel Kachhapd57a91c2012-03-26 17:06:54 +0530200
201get_trip_id() {
202
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800203 trip_name=$1
Amit Daniel Kachhapd57a91c2012-03-26 17:06:54 +0530204 shift 1
205
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800206 id1=$(echo $trip_name|cut -c12)
207 id2=$(echo $trip_name|cut -c13)
Amit Daniel Kachhapd57a91c2012-03-26 17:06:54 +0530208 if [ $id2 != "_" ]; then
209 id1=$(($id2 + 10*$id1))
210 fi
211 return $id1
212}
Amit Daniel Kachhap58b807b2012-04-04 12:23:08 +0530213
214disable_all_thermal_zones() {
215
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800216 index=0
Amit Daniel Kachhap58b807b2012-04-04 12:23:08 +0530217
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800218 th_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']")
Amit Daniel Kachhap58b807b2012-04-04 12:23:08 +0530219 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
227enable_all_thermal_zones() {
228
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800229 index=0
Amit Daniel Kachhap58b807b2012-04-04 12:23:08 +0530230
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800231 th_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']")
Amit Daniel Kachhap58b807b2012-04-04 12:23:08 +0530232 for zone in $th_zones; do
Javi Merino236ec092014-09-23 17:38:54 +0530233 echo ${mode_list[$index]} > $THERMAL_PATH/$zone/mode
Amit Daniel Kachhap58b807b2012-04-04 12:23:08 +0530234 index=$((index + 1))
235 done
236 return 0
237}
Hongbo Zhang40807512013-01-09 15:01:11 +0800238
239GPU_HEAT_BIN=/usr/bin/glmark2
240gpu_pid=0
241
242start_glmark2() {
Hongbo Zhang0f6d3c92013-01-21 16:32:25 +0800243 if [ -n "$ANDROID" ]; then
244 am start org.linaro.glmark2/.Glmark2Activity
245 return
246 fi
247
Hongbo Zhang40807512013-01-09 15:01:11 +0800248 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
269kill_glmark2() {
Hongbo Zhang0f6d3c92013-01-21 16:32:25 +0800270 if [ -n "$ANDROID" ]; then
271 am kill org.linaro.glmark2
272 return
273 fi
274
Sanjay Singh Rawatc7af87b2013-12-15 13:30:37 +0530275 if [ "$gpu_pid" -ne 0 ]; then
Hongbo Zhang40807512013-01-09 15:01:11 +0800276 kill -9 $gpu_pid
277 fi
278}
Javi Merino07b4b6b2014-09-23 16:57:45 +0530279
280set_thermal_governors() {
281
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800282 gov=$1
283 index=0
Javi Merino07b4b6b2014-09-23 16:57:45 +0530284
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800285 th_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']")
Javi Merino07b4b6b2014-09-23 16:57:45 +0530286 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
294restore_thermal_governors() {
295
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800296 index=0
Javi Merino07b4b6b2014-09-23 16:57:45 +0530297
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -0800298 th_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']")
Javi Merino07b4b6b2014-09-23 16:57:45 +0530299 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}