blob: 5b60698325f79db2f9d5bb3767d1d48d9b3054a1 [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
45 if [ $temp_val > 0 ]; then
46 log_end "pass"
47 return 0
48 fi
49
50 log_end "fail"
51
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
Amit Daniel Kachhap199ea5d2012-03-26 16:07:35 +0530128 log_end "fail"
129 return 1
130 fi
131
132 log_end "pass"
133 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']")
166
167 ALL_DEVICE=$devices
168 for device in $devices; do
169 INC=0
170 $func $device $@
171 done
172
173 return 0
174}
Amit Daniel Kachhapaa119582012-03-26 16:52:20 +0530175check_scaling_freq() {
176
177 local before_freq_list=$1
178 local after_freq_list=$2
179 shift 2
180 local index=0
181
182 local flag=0
183 for cpu in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
184 if [ $before_freq_list[$index] != $afterf_req_list[$index] ] ; then
185 flag=1
186 fi
187 index=$((index + 1))
188 done
189 return $flag
190}
191
192store_scaling_maxfreq() {
193 scale_freq=
194 local index=0
195
196 for cpu in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
197 scale_freq[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_max_freq)
198 index=$((index + 1))
199 done
200 return 0
201}
Amit Daniel Kachhapd57a91c2012-03-26 17:06:54 +0530202
203get_trip_id() {
204
205 local trip_name=$1
206 shift 1
207
208 local id1=$(echo $trip_name|cut -c12)
209 local id2=$(echo $trip_name|cut -c13)
210 if [ $id2 != "_" ]; then
211 id1=$(($id2 + 10*$id1))
212 fi
213 return $id1
214}
Amit Daniel Kachhap58b807b2012-04-04 12:23:08 +0530215
216disable_all_thermal_zones() {
217
218 mode_list=
219 local index=0
220
221 local th_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']")
222 for zone in $th_zones; do
223 mode_list[$index]=$(cat $THERMAL_PATH/$zone/mode)
224 index=$((index + 1))
225 echo -n "disabled" > $THERMAL_PATH/$zone/mode
226 done
227 return 0
228}
229
230enable_all_thermal_zones() {
231
232 local index=0
233
234 local th_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']")
235 for zone in $th_zones; do
236 echo $mode_list[$index] > $THERMAL_PATH/$zone/mode
237 index=$((index + 1))
238 done
239 return 0
240}