blob: 803b9378bba2f5c90116937d699749a7681a46dc [file] [log] [blame]
Lisa Nguyenadf9df92015-01-25 18:16:45 -08001#!/bin/sh
Daniel Lezcano2373b912011-07-26 14:39:00 +02002#
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
Sanjay Singh Rawat912729b2013-08-21 20:18:40 +053026# URL : https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpufreq_06
Daniel Lezcano2373b912011-07-26 14:39:00 +020027
Lisa Nguyenadf9df92015-01-25 18:16:45 -080028. ../include/functions.sh
Daniel Lezcano2373b912011-07-26 14:39:00 +020029
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)
Sanjay Singh Rawatc7af87b2013-12-15 13:30:37 +053040 if [ $? -ne 0 ]; then
Daniel Lezcano2373b912011-07-26 14:39:00 +020041 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
hongbo.zhangba2cbcc2012-08-07 13:35:32 +0800104supported=$(cat $CPU_PATH/cpu0/cpufreq/scaling_available_governors | grep "userspace")
zhanghongbo13a161c2012-08-17 19:06:33 +0800105if [ -z "$supported" ]; then
hongbo.zhangba2cbcc2012-08-07 13:35:32 +0800106 log_skip "userspace not supported"
Lisa Nguyend713d632014-08-20 17:26:04 -0700107 return 0
hongbo.zhangba2cbcc2012-08-07 13:35:32 +0800108fi
109
Daniel Lezcano2373b912011-07-26 14:39:00 +0200110save_governors
111save_frequencies
112
Lisa Nguyen5a0c2ba2015-01-27 13:57:25 -0800113trap "restore_frequencies; restore_governors; sigtrap" HUP INT TERM
Daniel Lezcano2373b912011-07-26 14:39:00 +0200114
115for_each_cpu check_deviation
116
117restore_frequencies
118restore_governors
Sanjay Singh Rawat3bf61942013-04-10 14:06:14 +0530119test_status_show