blob: ffdac84bd15dbb40bd6632131e9fd0c1cec5e3ad [file] [log] [blame]
Daniel Lezcanod84ec062011-07-26 14:38:59 +02001#!/bin/bash
2#
Daniel Lezcano35fb1722011-10-03 13:56:11 +02003# PM-QA validation test suite for the power management on Linux
Daniel Lezcanod84ec062011-07-26 14:38:59 +02004#
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
Sanjay Singh Rawatb579c102013-06-19 18:59:36 +053026source ../Switches.sh
Hongbo Zhang974802b2013-02-04 19:22:58 +080027
Daniel Lezcanod84ec062011-07-26 14:38:59 +020028CPU_PATH="/sys/devices/system/cpu"
29TEST_NAME=$(basename ${0%.sh})
Daniel Lezcano1efddc12011-08-09 23:45:30 +020030PREFIX=$TEST_NAME
31INC=0
32CPU=
Sanjay Singh Rawat3bf61942013-04-10 14:06:14 +053033pass_count=0
34fail_count=0
35
36test_status_show() {
37 echo "-------- total = $(($pass_count + $fail_count))"
38 echo "-------- pass = $pass_count"
39 # report failure only if it is there
40 if [ $fail_count -ne 0 ] ; then
41 echo "-------- fail = $fail_count"
42 fi
43}
Daniel Lezcanod84ec062011-07-26 14:38:59 +020044
45log_begin() {
Daniel Lezcano994f6f12011-08-16 13:28:33 +020046 printf "%-76s" "$TEST_NAME.$INC$CPU: $@... "
Daniel Lezcano1efddc12011-08-09 23:45:30 +020047 INC=$(($INC+1))
Daniel Lezcanod84ec062011-07-26 14:38:59 +020048}
49
50log_end() {
51 printf "$*\n"
52}
53
54log_skip() {
55 log_begin "$@"
Daniel Lezcanoff4aa112011-08-16 15:48:38 +020056 log_end "skip"
Daniel Lezcanod84ec062011-07-26 14:38:59 +020057}
58
59for_each_cpu() {
60
61 local func=$1
62 shift 1
63
64 cpus=$(ls $CPU_PATH | grep "cpu[0-9].*")
Daniel Lezcanod84ec062011-07-26 14:38:59 +020065 for cpu in $cpus; do
Daniel Lezcano1efddc12011-08-09 23:45:30 +020066 INC=0
67 CPU=/$cpu
Daniel Lezcanod84ec062011-07-26 14:38:59 +020068 $func $cpu $@
69 done
70
71 return 0
72}
73
74for_each_governor() {
75
76 local cpu=$1
77 local func=$2
78 local dirpath=$CPU_PATH/$cpu/cpufreq
79 local governors=$(cat $dirpath/scaling_available_governors)
80 shift 2
81
82 for governor in $governors; do
83 $func $cpu $governor $@
84 done
85
86 return 0
87}
88
89for_each_frequency() {
90
91 local cpu=$1
92 local func=$2
93 local dirpath=$CPU_PATH/$cpu/cpufreq
94 local frequencies=$(cat $dirpath/scaling_available_frequencies)
95 shift 2
96
97 for frequency in $frequencies; do
98 $func $cpu $frequency $@
99 done
100
101 return 0
102}
103
104set_governor() {
105
106 local cpu=$1
107 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor
108 local newgov=$2
109
110 echo $newgov > $dirpath
111}
112
113get_governor() {
114
115 local cpu=$1
116 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor
117
118 cat $dirpath
119}
120
121wait_latency() {
122 local cpu=$1
123 local dirpath=$CPU_PATH/$cpu/cpufreq
Daniel Lezcano93382952011-09-19 11:41:39 +0200124 local latency=
125 local nrfreq=
126
127 latency=$(cat $dirpath/cpuinfo_transition_latency)
Sanjay Singh Rawatc7af87b2013-12-15 13:30:37 +0530128 if [ $? -ne 0 ]; then
Daniel Lezcano0b90d412011-09-20 08:31:04 +0200129 return 1
Daniel Lezcano93382952011-09-19 11:41:39 +0200130 fi
131
132 nrfreq=$(cat $dirpath/scaling_available_frequencies | wc -w)
Sanjay Singh Rawatc7af87b2013-12-15 13:30:37 +0530133 if [ $? -ne 0 ]; then
Daniel Lezcano0b90d412011-09-20 08:31:04 +0200134 return 1
Daniel Lezcano93382952011-09-19 11:41:39 +0200135 fi
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200136
137 nrfreq=$((nrfreq + 1))
138 ../utils/nanosleep $(($nrfreq * $latency))
139}
140
141frequnit() {
142 local freq=$1
143 local ghz=$(echo "scale=1;($freq / 1000000)" | bc -l)
144 local mhz=$(echo "scale=1;($freq / 1000)" | bc -l)
145
146 res=$(echo "($ghz > 1.0)" | bc -l)
147 if [ "$res" = "1" ]; then
148 echo $ghz GHz
149 return 0
150 fi
151
152 res=$(echo "($mhz > 1.0)" | bc -l)
153 if [ "$res" = "1" ];then
154 echo $mhz MHz
155 return 0
156 fi
157
158 echo $freq KHz
159}
160
161set_frequency() {
162
163 local cpu=$1
164 local dirpath=$CPU_PATH/$cpu/cpufreq
165 local newfreq=$2
166 local setfreqpath=$dirpath/scaling_setspeed
167
168 echo $newfreq > $setfreqpath
169 wait_latency $cpu
170}
171
172get_frequency() {
173 local cpu=$1
174 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_cur_freq
175 cat $dirpath
176}
177
178get_max_frequency() {
179 local cpu=$1
180 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_max_freq
181 cat $dirpath
182}
183
184get_min_frequency() {
185 local cpu=$1
186 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_min_freq
187 cat $dirpath
188}
189
Daniel Lezcano805e3352011-10-03 11:07:36 +0200190set_online() {
191 local cpu=$1
192 local dirpath=$CPU_PATH/$cpu
193
Daniel Lezcano3dd53ee2012-04-05 14:03:08 +0200194 if [ "$cpu" = "cpu0" ]; then
195 return 0
196 fi
197
Daniel Lezcano805e3352011-10-03 11:07:36 +0200198 echo 1 > $dirpath/online
199}
200
201set_offline() {
202 local cpu=$1
203 local dirpath=$CPU_PATH/$cpu
204
Daniel Lezcano3dd53ee2012-04-05 14:03:08 +0200205 if [ "$cpu" = "cpu0" ]; then
206 return 0
207 fi
208
Daniel Lezcano805e3352011-10-03 11:07:36 +0200209 echo 0 > $dirpath/online
210}
211
212get_online() {
213 local cpu=$1
214 local dirpath=$CPU_PATH/$cpu
215
216 cat $dirpath/online
217}
218
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200219check() {
220
221 local descr=$1
222 local func=$2
223 shift 2;
224
225 log_begin "checking $descr"
226
227 $func $@
Sanjay Singh Rawatc7af87b2013-12-15 13:30:37 +0530228 if [ $? -ne 0 ]; then
Sanjay Singh Rawat3bf61942013-04-10 14:06:14 +0530229 log_end "Err"
230 fail_count=$(($fail_count + 1))
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200231 return 1
232 fi
233
Sanjay Singh Rawat3bf61942013-04-10 14:06:14 +0530234 log_end "Ok"
235 pass_count=$(($pass_count + 1))
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200236
237 return 0
238}
239
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200240check_file() {
241 local file=$1
242 local dir=$2
243
244 check "'$file' exists" "test -f" $dir/$file
245}
246
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200247check_cpufreq_files() {
248
249 local dirpath=$CPU_PATH/$1/cpufreq
250 shift 1
251
252 for i in $@; do
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200253 check_file $i $dirpath || return 1
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200254 done
255
256 return 0
257}
258
Daniel Lezcanoa7da5202011-08-05 15:01:42 +0200259check_sched_mc_files() {
260
261 local dirpath=$CPU_PATH
262
263 for i in $@; do
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200264 check_file $i $dirpath || return 1
Daniel Lezcanoa7da5202011-08-05 15:01:42 +0200265 done
266
267 return 0
268}
269
Daniel Lezcanobc043cb2011-08-05 15:01:42 +0200270check_topology_files() {
271
272 local dirpath=$CPU_PATH/$1/topology
273 shift 1
274
275 for i in $@; do
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200276 check_file $i $dirpath || return 1
Daniel Lezcanobc043cb2011-08-05 15:01:42 +0200277 done
278
279 return 0
280}
281
Daniel Lezcanob10475e2011-10-03 11:07:36 +0200282check_cpuhotplug_files() {
283
284 local dirpath=$CPU_PATH/$1
285 shift 1
286
287 for i in $@; do
Sanjay Singh Rawat28766572014-01-27 22:30:08 +0530288 # skip check for cpu0
289 if [ `echo $dirpath | grep -c "cpu0"` -eq 1 ]; then
290 continue
291 fi
Daniel Lezcanob10475e2011-10-03 11:07:36 +0200292 check_file $i $dirpath || return 1
293 done
294
295 return 0
296}
297
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200298save_governors() {
299
300 governors_backup=
301 local index=0
302
303 for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
304 governors_backup[$index]=$(cat $CPU_PATH/$i/cpufreq/scaling_governor)
305 index=$((index + 1))
306 done
307}
308
309restore_governors() {
310
311 local index=0
312 local oldgov=
313
314 for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
315 oldgov=${governors_backup[$index]}
316 echo $oldgov > $CPU_PATH/$i/cpufreq/scaling_governor
317 index=$((index + 1))
318 done
319}
320
321save_frequencies() {
322
323 frequencies_backup=
324 local index=0
325 local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*")
326 local cpu=
327
328 for cpu in $cpus; do
329 frequencies_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq)
330 index=$((index + 1))
331 done
332}
333
334restore_frequencies() {
335
336 local index=0
337 local oldfreq=
338 local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*")
339
340 for cpu in $cpus; do
341 oldfreq=${frequencies_backup[$index]}
342 echo $oldfreq > $CPU_PATH/$cpu/cpufreq/scaling_setspeed
343 index=$((index + 1))
344 done
345}
346
347sigtrap() {
348 exit 255
Daniel Lezcano18e22b52011-08-06 02:52:02 +0200349}