blob: c39b6b74aafb4eded9f8c82578bdb9beaa4d7e9d [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
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
Daniel Lezcano3dd53ee2012-04-05 14:03:08 +0200182 if [ "$cpu" = "cpu0" ]; then
183 return 0
184 fi
185
Daniel Lezcano805e3352011-10-03 11:07:36 +0200186 echo 1 > $dirpath/online
187}
188
189set_offline() {
190 local cpu=$1
191 local dirpath=$CPU_PATH/$cpu
192
Daniel Lezcano3dd53ee2012-04-05 14:03:08 +0200193 if [ "$cpu" = "cpu0" ]; then
194 return 0
195 fi
196
Daniel Lezcano805e3352011-10-03 11:07:36 +0200197 echo 0 > $dirpath/online
198}
199
200get_online() {
201 local cpu=$1
202 local dirpath=$CPU_PATH/$cpu
203
204 cat $dirpath/online
205}
206
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200207check() {
208
209 local descr=$1
210 local func=$2
211 shift 2;
212
213 log_begin "checking $descr"
214
215 $func $@
216 if [ $? != 0 ]; then
Daniel Lezcanoff4aa112011-08-16 15:48:38 +0200217 log_end "fail"
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200218 return 1
219 fi
220
Daniel Lezcanoff4aa112011-08-16 15:48:38 +0200221 log_end "pass"
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200222
223 return 0
224}
225
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200226check_file() {
227 local file=$1
228 local dir=$2
229
230 check "'$file' exists" "test -f" $dir/$file
231}
232
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200233check_cpufreq_files() {
234
235 local dirpath=$CPU_PATH/$1/cpufreq
236 shift 1
237
238 for i in $@; do
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200239 check_file $i $dirpath || return 1
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200240 done
241
242 return 0
243}
244
Daniel Lezcanoa7da5202011-08-05 15:01:42 +0200245check_sched_mc_files() {
246
247 local dirpath=$CPU_PATH
248
249 for i in $@; do
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200250 check_file $i $dirpath || return 1
Daniel Lezcanoa7da5202011-08-05 15:01:42 +0200251 done
252
253 return 0
254}
255
Daniel Lezcanobc043cb2011-08-05 15:01:42 +0200256check_topology_files() {
257
258 local dirpath=$CPU_PATH/$1/topology
259 shift 1
260
261 for i in $@; do
Daniel Lezcanob6a31192011-10-03 11:07:36 +0200262 check_file $i $dirpath || return 1
Daniel Lezcanobc043cb2011-08-05 15:01:42 +0200263 done
264
265 return 0
266}
267
Daniel Lezcanob10475e2011-10-03 11:07:36 +0200268check_cpuhotplug_files() {
269
270 local dirpath=$CPU_PATH/$1
271 shift 1
272
273 for i in $@; do
274 check_file $i $dirpath || return 1
275 done
276
277 return 0
278}
279
Daniel Lezcanod84ec062011-07-26 14:38:59 +0200280save_governors() {
281
282 governors_backup=
283 local index=0
284
285 for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
286 governors_backup[$index]=$(cat $CPU_PATH/$i/cpufreq/scaling_governor)
287 index=$((index + 1))
288 done
289}
290
291restore_governors() {
292
293 local index=0
294 local oldgov=
295
296 for i in $(ls $CPU_PATH | grep "cpu[0-9].*"); do
297 oldgov=${governors_backup[$index]}
298 echo $oldgov > $CPU_PATH/$i/cpufreq/scaling_governor
299 index=$((index + 1))
300 done
301}
302
303save_frequencies() {
304
305 frequencies_backup=
306 local index=0
307 local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*")
308 local cpu=
309
310 for cpu in $cpus; do
311 frequencies_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq)
312 index=$((index + 1))
313 done
314}
315
316restore_frequencies() {
317
318 local index=0
319 local oldfreq=
320 local cpus=$(ls $CPU_PATH | grep "cpu[0-9].*")
321
322 for cpu in $cpus; do
323 oldfreq=${frequencies_backup[$index]}
324 echo $oldfreq > $CPU_PATH/$cpu/cpufreq/scaling_setspeed
325 index=$((index + 1))
326 done
327}
328
329sigtrap() {
330 exit 255
Daniel Lezcano18e22b52011-08-06 02:52:02 +0200331}