blob: b323dc8d56626da72f88ad6a08badf38e241889f [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() {
Lisa Nguyen15e40ff2015-02-02 12:30:06 -080062 res=$(eval echo \$$freq_results_array$index)
Daniel Lezcano2373b912011-07-26 14:39:00 +020063
Lisa Nguyen71eb7a92015-11-17 17:29:12 -080064 if [ ! -z "$res" ]; then
65 # compute deviation
66 dev=$(echo $res $avg | awk '{printf "%.3f", (($1 - $2) / $2) * 100}')
Daniel Lezcano2373b912011-07-26 14:39:00 +020067
Lisa Nguyen71eb7a92015-11-17 17:29:12 -080068 # change to absolute
69 dev=$(echo $dev | awk '{ print ($1 >= 0) ? $1 : 0 - $1}')
Daniel Lezcano2373b912011-07-26 14:39:00 +020070
Lisa Nguyen71eb7a92015-11-17 17:29:12 -080071 index=$((index + 1))
72 res=$(echo $dev | awk '{printf "%f", ($dev > 5.0)}')
Daniel Lezcano2373b912011-07-26 14:39:00 +020073
Lisa Nguyen71eb7a92015-11-17 17:29:12 -080074 if [ "$res" = "1" ]; then
75 return 1
76 fi
77 else
78 return 1
Daniel Lezcano2373b912011-07-26 14:39:00 +020079 fi
80
81 return 0
82}
83
84check_freq_deviation() {
85
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -080086 cpu=$1
87 freq=$2
Daniel Lezcano2373b912011-07-26 14:39:00 +020088
89 check "deviation for frequency $(frequnit $freq)" __check_freq_deviation
90
91}
92
93check_deviation() {
94
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -080095 cpu=$1
Daniel Lezcano2373b912011-07-26 14:39:00 +020096
97 set_governor $cpu userspace
98
99 for_each_frequency $cpu compute_freq_ratio
100
Daniel Lezcano2373b912011-07-26 14:39:00 +0200101 for_each_frequency $cpu compute_freq_ratio_sum
102
Lisa Nguyen374c1b52015-10-21 17:57:04 -0700103 avg=$(echo $sum $index | awk '{ printf "%.3f", $1 / $2}')
Daniel Lezcano2373b912011-07-26 14:39:00 +0200104
Daniel Lezcano2373b912011-07-26 14:39:00 +0200105 for_each_frequency $cpu check_freq_deviation
106}
107
hongbo.zhangba2cbcc2012-08-07 13:35:32 +0800108supported=$(cat $CPU_PATH/cpu0/cpufreq/scaling_available_governors | grep "userspace")
zhanghongbo13a161c2012-08-17 19:06:33 +0800109if [ -z "$supported" ]; then
hongbo.zhangba2cbcc2012-08-07 13:35:32 +0800110 log_skip "userspace not supported"
Lisa Nguyend713d632014-08-20 17:26:04 -0700111 return 0
hongbo.zhangba2cbcc2012-08-07 13:35:32 +0800112fi
113
Daniel Lezcano2373b912011-07-26 14:39:00 +0200114save_governors
115save_frequencies
116
Lisa Nguyen5a0c2ba2015-01-27 13:57:25 -0800117trap "restore_frequencies; restore_governors; sigtrap" HUP INT TERM
Daniel Lezcano2373b912011-07-26 14:39:00 +0200118
119for_each_cpu check_deviation
120
121restore_frequencies
122restore_governors
Sanjay Singh Rawat3bf61942013-04-10 14:06:14 +0530123test_status_show