blob: b34d49bc179e35384808e2c27277bdcd10a06e6c [file] [log] [blame]
Daniel Lezcanod84ec062011-07-26 14:38:59 +02001#!/bin/bash
2#
3# PM-QA validation test suite for the power management on ARM
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# Daniel Lezcano <daniel.lezcano@linaro.org> (IBM Corporation)
23# - initial API and implementation
24#
25
26CPU_PATH="/sys/devices/system/cpu"
27TEST_NAME=$(basename ${0%.sh})
Daniel Lezcano1efddc12011-08-09 23:45:30 +020028PREFIX=$TEST_NAME
29INC=0
30CPU=
Daniel Lezcanod84ec062011-07-26 14:38:59 +020031
32log_begin() {
Daniel Lezcano994f6f12011-08-16 13:28:33 +020033 printf "%-76s" "$TEST_NAME.$INC$CPU: $@... "
Daniel Lezcano1efddc12011-08-09 23:45:30 +020034 INC=$(($INC+1))
Daniel Lezcanod84ec062011-07-26 14:38:59 +020035}
36
37log_end() {
38 printf "$*\n"
39}
40
41log_skip() {
42 log_begin "$@"
Daniel Lezcanoff4aa112011-08-16 15:48:38 +020043 log_end "skip"
Daniel Lezcanod84ec062011-07-26 14:38:59 +020044}
45
46for_each_cpu() {
47
48 local func=$1
49 shift 1
50
51 cpus=$(ls $CPU_PATH | grep "cpu[0-9].*")
52
53 for cpu in $cpus; do
Daniel Lezcano1efddc12011-08-09 23:45:30 +020054 INC=0
55 CPU=/$cpu
Daniel Lezcanod84ec062011-07-26 14:38:59 +020056 $func $cpu $@
57 done
58
59 return 0
60}
61
62for_each_governor() {
63
64 local cpu=$1
65 local func=$2
66 local dirpath=$CPU_PATH/$cpu/cpufreq
67 local governors=$(cat $dirpath/scaling_available_governors)
68 shift 2
69
70 for governor in $governors; do
71 $func $cpu $governor $@
72 done
73
74 return 0
75}
76
77for_each_frequency() {
78
79 local cpu=$1
80 local func=$2
81 local dirpath=$CPU_PATH/$cpu/cpufreq
82 local frequencies=$(cat $dirpath/scaling_available_frequencies)
83 shift 2
84
85 for frequency in $frequencies; do
86 $func $cpu $frequency $@
87 done
88
89 return 0
90}
91
92set_governor() {
93
94 local cpu=$1
95 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor
96 local newgov=$2
97
98 echo $newgov > $dirpath
99}
100
101get_governor() {
102
103 local cpu=$1
104 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor
105
106 cat $dirpath
107}
108
109wait_latency() {
110 local cpu=$1
111 local dirpath=$CPU_PATH/$cpu/cpufreq
Daniel Lezcano93382952011-09-19 11:41:39 +0200112 local latency=
113 local nrfreq=
114
115 latency=$(cat $dirpath/cpuinfo_transition_latency)
116 if [ $? != 0 ]; then
Daniel Lezcano0b90d412011-09-20 08:31:04 +0200117 return 1
Daniel Lezcano93382952011-09-19 11:41:39 +0200118 fi
119
120 nrfreq=$(cat $dirpath/scaling_available_frequencies | wc -w)
121 if [ $? != 0 ]; then
Daniel Lezcano0b90d412011-09-20 08:31:04 +0200122 return 1
Daniel Lezcano93382952011-09-19 11:41:39 +0200123 fi
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200124
125 nrfreq=$((nrfreq + 1))
126 ../utils/nanosleep $(($nrfreq * $latency))
127}
128
129frequnit() {
130 local freq=$1
131 local ghz=$(echo "scale=1;($freq / 1000000)" | bc -l)
132 local mhz=$(echo "scale=1;($freq / 1000)" | bc -l)
133
134 res=$(echo "($ghz > 1.0)" | bc -l)
135 if [ "$res" = "1" ]; then
136 echo $ghz GHz
137 return 0
138 fi
139
140 res=$(echo "($mhz > 1.0)" | bc -l)
141 if [ "$res" = "1" ];then
142 echo $mhz MHz
143 return 0
144 fi
145
146 echo $freq KHz
147}
148
149set_frequency() {
150
151 local cpu=$1
152 local dirpath=$CPU_PATH/$cpu/cpufreq
153 local newfreq=$2
154 local setfreqpath=$dirpath/scaling_setspeed
155
156 echo $newfreq > $setfreqpath
157 wait_latency $cpu
158}
159
160get_frequency() {
161 local cpu=$1
162 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_cur_freq
163 cat $dirpath
164}
165
166get_max_frequency() {
167 local cpu=$1
168 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_max_freq
169 cat $dirpath
170}
171
172get_min_frequency() {
173 local cpu=$1
174 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_min_freq
175 cat $dirpath
176}
177
Daniel Lezcano805e3352011-10-03 11:07:36 +0200178set_online() {
179 local cpu=$1
180 local dirpath=$CPU_PATH/$cpu
181
182 echo 1 > $dirpath/online
183}
184
185set_offline() {
186 local cpu=$1
187 local dirpath=$CPU_PATH/$cpu
188
189 echo 0 > $dirpath/online
190}
191
192get_online() {
193 local cpu=$1
194 local dirpath=$CPU_PATH/$cpu
195
196 cat $dirpath/online
197}
198
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200199check() {
200
201 local descr=$1
202 local func=$2
203 shift 2;
204
205 log_begin "checking $descr"
206
207 $func $@
208 if [ $? != 0 ]; then
Daniel Lezcanoff4aa112011-08-16 15:48:38 +0200209 log_end "fail"
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200210 return 1
211 fi
212
Daniel Lezcanoff4aa112011-08-16 15:48:38 +0200213 log_end "pass"
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200214
215 return 0
216}
217
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200218check_file() {
219 local file=$1
220 local dir=$2
221
222 check "'$file' exists" "test -f" $dir/$file
223}
224
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200225check_cpufreq_files() {
226
227 local dirpath=$CPU_PATH/$1/cpufreq
228 shift 1
229
230 for i in $@; do
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200231 check_file $i $dirpath || return 1
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200232 done
233
234 return 0
235}
236
Daniel Lezcanoa7da5202011-08-05 15:01:42 +0200237check_sched_mc_files() {
238
239 local dirpath=$CPU_PATH
240
241 for i in $@; do
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200242 check_file $i $dirpath || return 1
Daniel Lezcanoa7da5202011-08-05 15:01:42 +0200243 done
244
245 return 0
246}
247
Daniel Lezcanobc043cb2011-08-05 15:01:42 +0200248check_topology_files() {
249
250 local dirpath=$CPU_PATH/$1/topology
251 shift 1
252
253 for i in $@; do
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200254 check_file $i $dirpath || return 1
Daniel Lezcanobc043cb2011-08-05 15:01:42 +0200255 done
256
257 return 0
258}
259
Daniel Lezcanob10475e2011-10-03 11:07:36 +0200260check_cpuhotplug_files() {
261
262 local dirpath=$CPU_PATH/$1
263 shift 1
264
265 for i in $@; do
266 check_file $i $dirpath || return 1
267 done
268
269 return 0
270}
271
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200272save_governors() {
273
274 governors_backup=
275 local index=0
276
277 for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
278 governors_backup[$index]=$(cat $CPU_PATH/$i/cpufreq/scaling_governor)
279 index=$((index + 1))
280 done
281}
282
283restore_governors() {
284
285 local index=0
286 local oldgov=
287
288 for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
289 oldgov=${governors_backup[$index]}
290 echo $oldgov > $CPU_PATH/$i/cpufreq/scaling_governor
291 index=$((index + 1))
292 done
293}
294
295save_frequencies() {
296
297 frequencies_backup=
298 local index=0
299 local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*")
300 local cpu=
301
302 for cpu in $cpus; do
303 frequencies_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq)
304 index=$((index + 1))
305 done
306}
307
308restore_frequencies() {
309
310 local index=0
311 local oldfreq=
312 local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*")
313
314 for cpu in $cpus; do
315 oldfreq=${frequencies_backup[$index]}
316 echo $oldfreq > $CPU_PATH/$cpu/cpufreq/scaling_setspeed
317 index=$((index + 1))
318 done
319}
320
321sigtrap() {
322 exit 255
Daniel Lezcano18e22b52011-08-06 02:52:02 +0200323}