blob: b86db3489864365672c07b44198b1948398ce54b [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
Lisa Nguyen15e40ff2015-02-02 12:30:06 -080031freq_results_array="results"
Daniel Lezcano2373b912011-07-26 14:39:00 +020032
33compute_freq_ratio() {
Lisa Nguyen15e40ff2015-02-02 12:30:06 -080034 index=0
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -080035 cpu=$1
36 freq=$2
Daniel Lezcano2373b912011-07-26 14:39:00 +020037
38 set_frequency $cpu $freq
39
40 result=$($CPUCYCLE $cpu)
Sanjay Singh Rawatc7af87b2013-12-15 13:30:37 +053041 if [ $? -ne 0 ]; then
Daniel Lezcano2373b912011-07-26 14:39:00 +020042 return 1
43 fi
44
Lisa Nguyen374c1b52015-10-21 17:57:04 -070045 value=$(echo $result $freq | awk '{ printf "%.3f", $1 / $2 }')
Lisa Nguyen15e40ff2015-02-02 12:30:06 -080046 eval $freq_results_array$index=$value
47 eval export $freq_results_array$index
Daniel Lezcano2373b912011-07-26 14:39:00 +020048 index=$((index + 1))
49}
50
51compute_freq_ratio_sum() {
Lisa Nguyen15e40ff2015-02-02 12:30:06 -080052 index=0
53 sum=0
Daniel Lezcano2373b912011-07-26 14:39:00 +020054
Lisa Nguyen15e40ff2015-02-02 12:30:06 -080055 res=$(eval echo \$$freq_results_array$index)
Lisa Nguyen374c1b52015-10-21 17:57:04 -070056 sum=$(echo $sum $res | awk '{ printf "%f", $1 + $2 }')
Daniel Lezcano2373b912011-07-26 14:39:00 +020057 index=$((index + 1))
58
59}
60
61__check_freq_deviation() {
62
Lisa Nguyen15e40ff2015-02-02 12:30:06 -080063 res=$(eval echo \$$freq_results_array$index)
Daniel Lezcano2373b912011-07-26 14:39:00 +020064
65 # compute deviation
Lisa Nguyen374c1b52015-10-21 17:57:04 -070066 dev=$(echo $res $avg | awk '{printf "%.3f", (($1 - $2) / $2) * 100}')
Daniel Lezcano2373b912011-07-26 14:39:00 +020067
68 # change to absolute
69 dev=$(echo $dev | awk '{ print ($1 >= 0) ? $1 : 0 - $1}')
70
71 index=$((index + 1))
72
Lisa Nguyen374c1b52015-10-21 17:57:04 -070073 res=$(echo $dev | awk '{printf "%f", ($dev > 5.0)}')
Daniel Lezcano2373b912011-07-26 14:39:00 +020074 if [ "$res" = "1" ]; then
75 return 1
76 fi
77
78 return 0
79}
80
81check_freq_deviation() {
82
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -080083 cpu=$1
84 freq=$2
Daniel Lezcano2373b912011-07-26 14:39:00 +020085
86 check "deviation for frequency $(frequnit $freq)" __check_freq_deviation
87
88}
89
90check_deviation() {
91
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -080092 cpu=$1
Daniel Lezcano2373b912011-07-26 14:39:00 +020093
94 set_governor $cpu userspace
95
96 for_each_frequency $cpu compute_freq_ratio
97
Daniel Lezcano2373b912011-07-26 14:39:00 +020098 for_each_frequency $cpu compute_freq_ratio_sum
99
Lisa Nguyen374c1b52015-10-21 17:57:04 -0700100 avg=$(echo $sum $index | awk '{ printf "%.3f", $1 / $2}')
Daniel Lezcano2373b912011-07-26 14:39:00 +0200101
Daniel Lezcano2373b912011-07-26 14:39:00 +0200102 for_each_frequency $cpu check_freq_deviation
103}
104
hongbo.zhangba2cbcc2012-08-07 13:35:32 +0800105supported=$(cat $CPU_PATH/cpu0/cpufreq/scaling_available_governors | grep "userspace")
zhanghongbo13a161c2012-08-17 19:06:33 +0800106if [ -z "$supported" ]; then
hongbo.zhangba2cbcc2012-08-07 13:35:32 +0800107 log_skip "userspace not supported"
Lisa Nguyend713d632014-08-20 17:26:04 -0700108 return 0
hongbo.zhangba2cbcc2012-08-07 13:35:32 +0800109fi
110
Daniel Lezcano2373b912011-07-26 14:39:00 +0200111save_governors
112save_frequencies
113
Lisa Nguyen5a0c2ba2015-01-27 13:57:25 -0800114trap "restore_frequencies; restore_governors; sigtrap" HUP INT TERM
Daniel Lezcano2373b912011-07-26 14:39:00 +0200115
116for_each_cpu check_deviation
117
118restore_frequencies
119restore_governors
Sanjay Singh Rawat3bf61942013-04-10 14:06:14 +0530120test_status_show