blob: fa9a370fded6463b2423df9e51e93663729168f1 [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
Hongbo Zhang974802b2013-02-04 19:22:58 +080026source ../Switches
27
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].*")
65
66 for cpu in $cpus; do
Daniel Lezcano1efddc12011-08-09 23:45:30 +020067 INC=0
68 CPU=/$cpu
Daniel Lezcanod84ec062011-07-26 14:38:59 +020069 $func $cpu $@
70 done
71
72 return 0
73}
74
75for_each_governor() {
76
77 local cpu=$1
78 local func=$2
79 local dirpath=$CPU_PATH/$cpu/cpufreq
80 local governors=$(cat $dirpath/scaling_available_governors)
81 shift 2
82
83 for governor in $governors; do
84 $func $cpu $governor $@
85 done
86
87 return 0
88}
89
90for_each_frequency() {
91
92 local cpu=$1
93 local func=$2
94 local dirpath=$CPU_PATH/$cpu/cpufreq
95 local frequencies=$(cat $dirpath/scaling_available_frequencies)
96 shift 2
97
98 for frequency in $frequencies; do
99 $func $cpu $frequency $@
100 done
101
102 return 0
103}
104
105set_governor() {
106
107 local cpu=$1
108 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor
109 local newgov=$2
110
111 echo $newgov > $dirpath
112}
113
114get_governor() {
115
116 local cpu=$1
117 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor
118
119 cat $dirpath
120}
121
122wait_latency() {
123 local cpu=$1
124 local dirpath=$CPU_PATH/$cpu/cpufreq
Daniel Lezcano93382952011-09-19 11:41:39 +0200125 local latency=
126 local nrfreq=
127
128 latency=$(cat $dirpath/cpuinfo_transition_latency)
129 if [ $? != 0 ]; then
Daniel Lezcano0b90d412011-09-20 08:31:04 +0200130 return 1
Daniel Lezcano93382952011-09-19 11:41:39 +0200131 fi
132
133 nrfreq=$(cat $dirpath/scaling_available_frequencies | wc -w)
134 if [ $? != 0 ]; then
Daniel Lezcano0b90d412011-09-20 08:31:04 +0200135 return 1
Daniel Lezcano93382952011-09-19 11:41:39 +0200136 fi
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200137
138 nrfreq=$((nrfreq + 1))
139 ../utils/nanosleep $(($nrfreq * $latency))
140}
141
142frequnit() {
143 local freq=$1
144 local ghz=$(echo "scale=1;($freq / 1000000)" | bc -l)
145 local mhz=$(echo "scale=1;($freq / 1000)" | bc -l)
146
147 res=$(echo "($ghz > 1.0)" | bc -l)
148 if [ "$res" = "1" ]; then
149 echo $ghz GHz
150 return 0
151 fi
152
153 res=$(echo "($mhz > 1.0)" | bc -l)
154 if [ "$res" = "1" ];then
155 echo $mhz MHz
156 return 0
157 fi
158
159 echo $freq KHz
160}
161
162set_frequency() {
163
164 local cpu=$1
165 local dirpath=$CPU_PATH/$cpu/cpufreq
166 local newfreq=$2
167 local setfreqpath=$dirpath/scaling_setspeed
168
169 echo $newfreq > $setfreqpath
170 wait_latency $cpu
171}
172
173get_frequency() {
174 local cpu=$1
175 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_cur_freq
176 cat $dirpath
177}
178
179get_max_frequency() {
180 local cpu=$1
181 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_max_freq
182 cat $dirpath
183}
184
185get_min_frequency() {
186 local cpu=$1
187 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_min_freq
188 cat $dirpath
189}
190
Daniel Lezcano805e3352011-10-03 11:07:36 +0200191set_online() {
192 local cpu=$1
193 local dirpath=$CPU_PATH/$cpu
194
Daniel Lezcano3dd53ee2012-04-05 14:03:08 +0200195 if [ "$cpu" = "cpu0" ]; then
196 return 0
197 fi
198
Daniel Lezcano805e3352011-10-03 11:07:36 +0200199 echo 1 > $dirpath/online
200}
201
202set_offline() {
203 local cpu=$1
204 local dirpath=$CPU_PATH/$cpu
205
Daniel Lezcano3dd53ee2012-04-05 14:03:08 +0200206 if [ "$cpu" = "cpu0" ]; then
207 return 0
208 fi
209
Daniel Lezcano805e3352011-10-03 11:07:36 +0200210 echo 0 > $dirpath/online
211}
212
213get_online() {
214 local cpu=$1
215 local dirpath=$CPU_PATH/$cpu
216
217 cat $dirpath/online
218}
219
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200220check() {
221
222 local descr=$1
223 local func=$2
224 shift 2;
225
226 log_begin "checking $descr"
227
228 $func $@
229 if [ $? != 0 ]; then
Sanjay Singh Rawat3bf61942013-04-10 14:06:14 +0530230 log_end "Err"
231 fail_count=$(($fail_count + 1))
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200232 return 1
233 fi
234
Sanjay Singh Rawat3bf61942013-04-10 14:06:14 +0530235 log_end "Ok"
236 pass_count=$(($pass_count + 1))
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200237
238 return 0
239}
240
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200241check_file() {
242 local file=$1
243 local dir=$2
244
245 check "'$file' exists" "test -f" $dir/$file
246}
247
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200248check_cpufreq_files() {
249
250 local dirpath=$CPU_PATH/$1/cpufreq
251 shift 1
252
253 for i in $@; do
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200254 check_file $i $dirpath || return 1
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200255 done
256
257 return 0
258}
259
Daniel Lezcanoa7da5202011-08-05 15:01:42 +0200260check_sched_mc_files() {
261
262 local dirpath=$CPU_PATH
263
264 for i in $@; do
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200265 check_file $i $dirpath || return 1
Daniel Lezcanoa7da5202011-08-05 15:01:42 +0200266 done
267
268 return 0
269}
270
Daniel Lezcanobc043cb2011-08-05 15:01:42 +0200271check_topology_files() {
272
273 local dirpath=$CPU_PATH/$1/topology
274 shift 1
275
276 for i in $@; do
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200277 check_file $i $dirpath || return 1
Daniel Lezcanobc043cb2011-08-05 15:01:42 +0200278 done
279
280 return 0
281}
282
Daniel Lezcanob10475e2011-10-03 11:07:36 +0200283check_cpuhotplug_files() {
284
285 local dirpath=$CPU_PATH/$1
286 shift 1
287
288 for i in $@; do
289 check_file $i $dirpath || return 1
290 done
291
292 return 0
293}
294
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200295save_governors() {
296
297 governors_backup=
298 local index=0
299
300 for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
301 governors_backup[$index]=$(cat $CPU_PATH/$i/cpufreq/scaling_governor)
302 index=$((index + 1))
303 done
304}
305
306restore_governors() {
307
308 local index=0
309 local oldgov=
310
311 for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
312 oldgov=${governors_backup[$index]}
313 echo $oldgov > $CPU_PATH/$i/cpufreq/scaling_governor
314 index=$((index + 1))
315 done
316}
317
318save_frequencies() {
319
320 frequencies_backup=
321 local index=0
322 local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*")
323 local cpu=
324
325 for cpu in $cpus; do
326 frequencies_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq)
327 index=$((index + 1))
328 done
329}
330
331restore_frequencies() {
332
333 local index=0
334 local oldfreq=
335 local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*")
336
337 for cpu in $cpus; do
338 oldfreq=${frequencies_backup[$index]}
339 echo $oldfreq > $CPU_PATH/$cpu/cpufreq/scaling_setspeed
340 index=$((index + 1))
341 done
342}
343
344sigtrap() {
345 exit 255
Daniel Lezcano18e22b52011-08-06 02:52:02 +0200346}