blob: 7ee809bf9121c5db0683a284f248f5d1a91f0daa [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=
Daniel Lezcanod84ec062011-07-26 14:38:59 +020033
34log_begin() {
Daniel Lezcano994f6f12011-08-16 13:28:33 +020035 printf "%-76s" "$TEST_NAME.$INC$CPU: $@... "
Daniel Lezcano1efddc12011-08-09 23:45:30 +020036 INC=$(($INC+1))
Daniel Lezcanod84ec062011-07-26 14:38:59 +020037}
38
39log_end() {
40 printf "$*\n"
41}
42
43log_skip() {
44 log_begin "$@"
Daniel Lezcanoff4aa112011-08-16 15:48:38 +020045 log_end "skip"
Daniel Lezcanod84ec062011-07-26 14:38:59 +020046}
47
48for_each_cpu() {
49
50 local func=$1
51 shift 1
52
53 cpus=$(ls $CPU_PATH | grep "cpu[0-9].*")
54
55 for cpu in $cpus; do
Daniel Lezcano1efddc12011-08-09 23:45:30 +020056 INC=0
57 CPU=/$cpu
Daniel Lezcanod84ec062011-07-26 14:38:59 +020058 $func $cpu $@
59 done
60
61 return 0
62}
63
64for_each_governor() {
65
66 local cpu=$1
67 local func=$2
68 local dirpath=$CPU_PATH/$cpu/cpufreq
69 local governors=$(cat $dirpath/scaling_available_governors)
70 shift 2
71
72 for governor in $governors; do
73 $func $cpu $governor $@
74 done
75
76 return 0
77}
78
79for_each_frequency() {
80
81 local cpu=$1
82 local func=$2
83 local dirpath=$CPU_PATH/$cpu/cpufreq
84 local frequencies=$(cat $dirpath/scaling_available_frequencies)
85 shift 2
86
87 for frequency in $frequencies; do
88 $func $cpu $frequency $@
89 done
90
91 return 0
92}
93
94set_governor() {
95
96 local cpu=$1
97 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor
98 local newgov=$2
99
100 echo $newgov > $dirpath
101}
102
103get_governor() {
104
105 local cpu=$1
106 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor
107
108 cat $dirpath
109}
110
111wait_latency() {
112 local cpu=$1
113 local dirpath=$CPU_PATH/$cpu/cpufreq
Daniel Lezcano93382952011-09-19 11:41:39 +0200114 local latency=
115 local nrfreq=
116
117 latency=$(cat $dirpath/cpuinfo_transition_latency)
118 if [ $? != 0 ]; then
Daniel Lezcano0b90d412011-09-20 08:31:04 +0200119 return 1
Daniel Lezcano93382952011-09-19 11:41:39 +0200120 fi
121
122 nrfreq=$(cat $dirpath/scaling_available_frequencies | wc -w)
123 if [ $? != 0 ]; then
Daniel Lezcano0b90d412011-09-20 08:31:04 +0200124 return 1
Daniel Lezcano93382952011-09-19 11:41:39 +0200125 fi
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200126
127 nrfreq=$((nrfreq + 1))
128 ../utils/nanosleep $(($nrfreq * $latency))
129}
130
131frequnit() {
132 local freq=$1
133 local ghz=$(echo "scale=1;($freq / 1000000)" | bc -l)
134 local mhz=$(echo "scale=1;($freq / 1000)" | bc -l)
135
136 res=$(echo "($ghz > 1.0)" | bc -l)
137 if [ "$res" = "1" ]; then
138 echo $ghz GHz
139 return 0
140 fi
141
142 res=$(echo "($mhz > 1.0)" | bc -l)
143 if [ "$res" = "1" ];then
144 echo $mhz MHz
145 return 0
146 fi
147
148 echo $freq KHz
149}
150
151set_frequency() {
152
153 local cpu=$1
154 local dirpath=$CPU_PATH/$cpu/cpufreq
155 local newfreq=$2
156 local setfreqpath=$dirpath/scaling_setspeed
157
158 echo $newfreq > $setfreqpath
159 wait_latency $cpu
160}
161
162get_frequency() {
163 local cpu=$1
164 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_cur_freq
165 cat $dirpath
166}
167
168get_max_frequency() {
169 local cpu=$1
170 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_max_freq
171 cat $dirpath
172}
173
174get_min_frequency() {
175 local cpu=$1
176 local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_min_freq
177 cat $dirpath
178}
179
Daniel Lezcano805e3352011-10-03 11:07:36 +0200180set_online() {
181 local cpu=$1
182 local dirpath=$CPU_PATH/$cpu
183
Daniel Lezcano3dd53ee2012-04-05 14:03:08 +0200184 if [ "$cpu" = "cpu0" ]; then
185 return 0
186 fi
187
Daniel Lezcano805e3352011-10-03 11:07:36 +0200188 echo 1 > $dirpath/online
189}
190
191set_offline() {
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 0 > $dirpath/online
200}
201
202get_online() {
203 local cpu=$1
204 local dirpath=$CPU_PATH/$cpu
205
206 cat $dirpath/online
207}
208
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200209check() {
210
211 local descr=$1
212 local func=$2
213 shift 2;
214
215 log_begin "checking $descr"
216
217 $func $@
218 if [ $? != 0 ]; then
Daniel Lezcanoff4aa112011-08-16 15:48:38 +0200219 log_end "fail"
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200220 return 1
221 fi
222
Daniel Lezcanoff4aa112011-08-16 15:48:38 +0200223 log_end "pass"
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200224
225 return 0
226}
227
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200228check_file() {
229 local file=$1
230 local dir=$2
231
232 check "'$file' exists" "test -f" $dir/$file
233}
234
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200235check_cpufreq_files() {
236
237 local dirpath=$CPU_PATH/$1/cpufreq
238 shift 1
239
240 for i in $@; do
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200241 check_file $i $dirpath || return 1
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200242 done
243
244 return 0
245}
246
Daniel Lezcanoa7da5202011-08-05 15:01:42 +0200247check_sched_mc_files() {
248
249 local dirpath=$CPU_PATH
250
251 for i in $@; do
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200252 check_file $i $dirpath || return 1
Daniel Lezcanoa7da5202011-08-05 15:01:42 +0200253 done
254
255 return 0
256}
257
Daniel Lezcanobc043cb2011-08-05 15:01:42 +0200258check_topology_files() {
259
260 local dirpath=$CPU_PATH/$1/topology
261 shift 1
262
263 for i in $@; do
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200264 check_file $i $dirpath || return 1
Daniel Lezcanobc043cb2011-08-05 15:01:42 +0200265 done
266
267 return 0
268}
269
Daniel Lezcanob10475e2011-10-03 11:07:36 +0200270check_cpuhotplug_files() {
271
272 local dirpath=$CPU_PATH/$1
273 shift 1
274
275 for i in $@; do
276 check_file $i $dirpath || return 1
277 done
278
279 return 0
280}
281
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200282save_governors() {
283
284 governors_backup=
285 local index=0
286
287 for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
288 governors_backup[$index]=$(cat $CPU_PATH/$i/cpufreq/scaling_governor)
289 index=$((index + 1))
290 done
291}
292
293restore_governors() {
294
295 local index=0
296 local oldgov=
297
298 for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
299 oldgov=${governors_backup[$index]}
300 echo $oldgov > $CPU_PATH/$i/cpufreq/scaling_governor
301 index=$((index + 1))
302 done
303}
304
305save_frequencies() {
306
307 frequencies_backup=
308 local index=0
309 local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*")
310 local cpu=
311
312 for cpu in $cpus; do
313 frequencies_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq)
314 index=$((index + 1))
315 done
316}
317
318restore_frequencies() {
319
320 local index=0
321 local oldfreq=
322 local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*")
323
324 for cpu in $cpus; do
325 oldfreq=${frequencies_backup[$index]}
326 echo $oldfreq > $CPU_PATH/$cpu/cpufreq/scaling_setspeed
327 index=$((index + 1))
328 done
329}
330
331sigtrap() {
332 exit 255
Daniel Lezcano18e22b52011-08-06 02:52:02 +0200333}