blob: 4fbd4b7d644baa0342a9045f0a9626b5343fc511 [file] [log] [blame]
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +05301#!/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
26THERMAL_PATH="/sys/devices/virtual/thermal"
27MAX_ZONE=0-12
28MAX_CDEV=0-50
29ALL_ZONE=
30ALL_CDEV=
31
32check_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.zhang2a303c92012-11-22 18:20:24 +080045 if [ $temp_val -gt 0 ]; then
Sanjay Singh Rawat3ab64062014-07-08 16:50:56 +020046 log_end "Ok"
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053047 return 0
48 fi
49
Sanjay Singh Rawat3ab64062014-07-08 16:50:56 +020050 log_end "Err"
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053051
52 return 1
53}
54
55for_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
71get_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 Kachhap1fe389c2012-04-04 15:14:38 +053077 for trip in $trips; do
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053078 count=$((count + 1))
79 done
80 return $count
81}
82
83for_each_trip_point_of_zone() {
84
85 local zone_path=$THERMAL_PATH/$1
86 local count=0
87 local func=$2
Amit Daniel Kachhap1fe389c2012-04-04 15:14:38 +053088 local zone_name=$1
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053089 shift 2
90 trips=$(ls $zone_path | grep "trip_point_['$MAX_ZONE']_temp")
91 for trip in $trips; do
Amit Daniel Kachhap1fe389c2012-04-04 15:14:38 +053092 $func $zone_name $count
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +053093 count=$((count + 1))
94 done
95 return 0
96}
97
98for_each_binding_of_zone() {
99
100 local zone_path=$THERMAL_PATH/$1
101 local count=0
102 local func=$2
Amit Daniel Kachhap1fe389c2012-04-04 15:14:38 +0530103 local zone_name=$1
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530104 shift 2
105 trips=$(ls $zone_path | grep "cdev['$MAX_CDEV']_trip_point")
106 for trip in $trips; do
Amit Daniel Kachhap1fe389c2012-04-04 15:14:38 +0530107 $func $zone_name $count
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530108 count=$((count + 1))
109 done
110
111 return 0
112
113}
114
115check_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 Kachhap1fe389c2012-04-04 15:14:38 +0530120 local trip_point_val=$(cat $dirpath/$trip_point)
121 get_total_trip_point_of_zone $zone_name
122 local trip_point_max=$?
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530123 local descr="'$temp_file' valid binding"
124 shift 2
125
126 log_begin "checking $descr"
Amit Daniel Kachhap23b56942012-05-05 15:18:29 +0530127 if [ $trip_point_val -ge $trip_point_max ]; then
Lisa Nguyen01a02862014-07-21 16:51:43 -0700128 log_end "Err"
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530129 return 1
130 fi
131
Lisa Nguyen01a02862014-07-21 16:51:43 -0700132 log_end "Ok"
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530133 return 0
134}
135
136validate_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
147validate_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 Kachhap87adb0d2012-03-26 16:13:29 +0530159
160for_each_cooling_device() {
161
162 local func=$1
163 shift 1
164
165 devices=$(ls $THERMAL_PATH | grep "cooling_device['$MAX_CDEV']")
Sanjay Singh Rawat15bcbd52014-07-07 16:47:12 +0200166 if [ "$devices" == "" ]; then
167 log_skip "no cooling devices"
168 return 0
169 fi
Amit Daniel Kachhap87adb0d2012-03-26 16:13:29 +0530170
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 Kachhapaa119582012-03-26 16:52:20 +0530179check_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 Nguyen188ca9a2014-08-11 12:21:08 -0700187 for cpu in $cpus; do
Sanjay Singh Rawatc7af87b2013-12-15 13:30:37 +0530188 if [ $before_freq_list[$index] -ne $afterf_req_list[$index] ] ; then
Amit Daniel Kachhapaa119582012-03-26 16:52:20 +0530189 flag=1
190 fi
191 index=$((index + 1))
192 done
193 return $flag
194}
195
196store_scaling_maxfreq() {
197 scale_freq=
198 local index=0
199
Lisa Nguyen188ca9a2014-08-11 12:21:08 -0700200 for cpu in $cpus; do
Amit Daniel Kachhapaa119582012-03-26 16:52:20 +0530201 scale_freq[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_max_freq)
202 index=$((index + 1))
203 done
204 return 0
205}
Amit Daniel Kachhapd57a91c2012-03-26 17:06:54 +0530206
207get_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 Kachhap58b807b2012-04-04 12:23:08 +0530219
220disable_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
234enable_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 Zhang40807512013-01-09 15:01:11 +0800245
246GPU_HEAT_BIN=/usr/bin/glmark2
247gpu_pid=0
248
249start_glmark2() {
Hongbo Zhang0f6d3c92013-01-21 16:32:25 +0800250 if [ -n "$ANDROID" ]; then
251 am start org.linaro.glmark2/.Glmark2Activity
252 return
253 fi
254
Hongbo Zhang40807512013-01-09 15:01:11 +0800255 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
276kill_glmark2() {
Hongbo Zhang0f6d3c92013-01-21 16:32:25 +0800277 if [ -n "$ANDROID" ]; then
278 am kill org.linaro.glmark2
279 return
280 fi
281
Sanjay Singh Rawatc7af87b2013-12-15 13:30:37 +0530282 if [ "$gpu_pid" -ne 0 ]; then
Hongbo Zhang40807512013-01-09 15:01:11 +0800283 kill -9 $gpu_pid
284 fi
285}
Javi Merino07b4b6b2014-09-23 16:57:45 +0530286
287set_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
302restore_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}