blob: 08f7a6d983799ccc40fcb3528cfd27a65fdd1a4e [file] [log] [blame]
Daniel Lezcano2373b912011-07-26 14:39:00 +02001#!/bin/bash
2#
Daniel Lezcano35fb1722011-10-03 13:56:11 +02003# PM-QA validation test suite for the power management on Linux
Daniel Lezcano2373b912011-07-26 14:39:00 +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
Daniel Lezcano65b8b4b2011-08-03 09:58:11 +020026# URL : https://wiki.linaro.org/WorkingGroups/PowerManagement/Doc/QA/Scripts#cpufreq_06
Daniel Lezcano2373b912011-07-26 14:39:00 +020027
28source ../include/functions.sh
29
30CPUCYCLE=../utils/cpucycle
31
32compute_freq_ratio() {
33
34 local cpu=$1
35 local freq=$2
36
37 set_frequency $cpu $freq
38
39 result=$($CPUCYCLE $cpu)
40 if [ $? != 0 ]; then
41 return 1
42 fi
43
44 results[$index]=$(echo "scale=3;($result / $freq)" | bc -l)
45 index=$((index + 1))
46}
47
48compute_freq_ratio_sum() {
49
50 res=${results[$index]}
51 sum=$(echo "($sum + $res)" | bc -l)
52 index=$((index + 1))
53
54}
55
56__check_freq_deviation() {
57
58 res=${results[$index]}
59
60 # compute deviation
61 dev=$(echo "scale=3;((( $res - $avg ) / $avg) * 100 )" | bc -l)
62
63 # change to absolute
64 dev=$(echo $dev | awk '{ print ($1 >= 0) ? $1 : 0 - $1}')
65
66 index=$((index + 1))
67
68 res=$(echo "($dev > 5.0)" | bc -l)
69 if [ "$res" = "1" ]; then
70 return 1
71 fi
72
73 return 0
74}
75
76check_freq_deviation() {
77
78 local cpu=$1
79 local freq=$2
80
81 check "deviation for frequency $(frequnit $freq)" __check_freq_deviation
82
83}
84
85check_deviation() {
86
87 local cpu=$1
88
89 set_governor $cpu userspace
90
91 for_each_frequency $cpu compute_freq_ratio
92
93 index=0
94 sum=0
95
96 for_each_frequency $cpu compute_freq_ratio_sum
97
98 avg=$(echo "scale=3;($sum / $index)" | bc -l)
99
100 index=0
101 for_each_frequency $cpu check_freq_deviation
102}
103
104if [ $(id -u) != 0 ]; then
105 log_skip "run as non-root"
106 exit 0
107fi
108
hongbo.zhangba2cbcc2012-08-07 13:35:32 +0800109supported=$(cat $CPU_PATH/cpu0/cpufreq/scaling_available_governors | grep "userspace")
zhanghongbo13a161c2012-08-17 19:06:33 +0800110if [ -z "$supported" ]; then
hongbo.zhangba2cbcc2012-08-07 13:35:32 +0800111 log_skip "userspace not supported"
112 exit 0
113fi
114
Daniel Lezcano2373b912011-07-26 14:39:00 +0200115save_governors
116save_frequencies
117
118trap "restore_frequencies; restore_governors; sigtrap" SIGHUP SIGINT SIGTERM
119
120for_each_cpu check_deviation
121
122restore_frequencies
123restore_governors
Sanjay Singh Rawat3bf61942013-04-10 14:06:14 +0530124test_status_show