blob: 8f1dc22c168fe2a134ecc27f58d4d83fb8e295b0 [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 Nguyen4e0b59a2015-01-25 17:46:40 -080034 cpu=$1
35 freq=$2
Daniel Lezcano2373b912011-07-26 14:39:00 +020036
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
Lisa Nguyen374c1b52015-10-21 17:57:04 -070044 value=$(echo $result $freq | awk '{ printf "%.3f", $1 / $2 }')
Lisa Nguyen15e40ff2015-02-02 12:30:06 -080045 eval $freq_results_array$index=$value
46 eval export $freq_results_array$index
Daniel Lezcano2373b912011-07-26 14:39:00 +020047 index=$((index + 1))
48}
49
50compute_freq_ratio_sum() {
Lisa Nguyen15e40ff2015-02-02 12:30:06 -080051 res=$(eval echo \$$freq_results_array$index)
Lisa Nguyen374c1b52015-10-21 17:57:04 -070052 sum=$(echo $sum $res | awk '{ printf "%f", $1 + $2 }')
Daniel Lezcano2373b912011-07-26 14:39:00 +020053 index=$((index + 1))
Daniel Lezcano2373b912011-07-26 14:39:00 +020054}
55
56__check_freq_deviation() {
Lisa Nguyen15e40ff2015-02-02 12:30:06 -080057 res=$(eval echo \$$freq_results_array$index)
Lisa Nguyen71eb7a92015-11-17 17:29:12 -080058 if [ ! -z "$res" ]; then
59 # compute deviation
60 dev=$(echo $res $avg | awk '{printf "%.3f", (($1 - $2) / $2) * 100}')
Lisa Nguyen71eb7a92015-11-17 17:29:12 -080061 # change to absolute
62 dev=$(echo $dev | awk '{ print ($1 >= 0) ? $1 : 0 - $1}')
Lisa Nguyen71eb7a92015-11-17 17:29:12 -080063 index=$((index + 1))
64 res=$(echo $dev | awk '{printf "%f", ($dev > 5.0)}')
Daniel Lezcano2373b912011-07-26 14:39:00 +020065
Lisa Nguyen71eb7a92015-11-17 17:29:12 -080066 if [ "$res" = "1" ]; then
67 return 1
68 fi
69 else
70 return 1
Daniel Lezcano2373b912011-07-26 14:39:00 +020071 fi
72
73 return 0
74}
75
76check_freq_deviation() {
77
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -080078 cpu=$1
79 freq=$2
Daniel Lezcano2373b912011-07-26 14:39:00 +020080 check "deviation for frequency $(frequnit $freq)" __check_freq_deviation
Daniel Lezcano2373b912011-07-26 14:39:00 +020081}
82
83check_deviation() {
84
Lisa Nguyen4e0b59a2015-01-25 17:46:40 -080085 cpu=$1
Daniel Lezcano2373b912011-07-26 14:39:00 +020086 set_governor $cpu userspace
Saul Romero7c616e72016-05-31 16:50:54 +010087 index=0
Daniel Lezcano2373b912011-07-26 14:39:00 +020088 for_each_frequency $cpu compute_freq_ratio
Saul Romero7c616e72016-05-31 16:50:54 +010089 index=0;sum=0
Daniel Lezcano2373b912011-07-26 14:39:00 +020090 for_each_frequency $cpu compute_freq_ratio_sum
91
Lisa Nguyen374c1b52015-10-21 17:57:04 -070092 avg=$(echo $sum $index | awk '{ printf "%.3f", $1 / $2}')
Saul Romero7c616e72016-05-31 16:50:54 +010093 index=0
Daniel Lezcano2373b912011-07-26 14:39:00 +020094 for_each_frequency $cpu check_freq_deviation
95}
96
hongbo.zhangba2cbcc2012-08-07 13:35:32 +080097supported=$(cat $CPU_PATH/cpu0/cpufreq/scaling_available_governors | grep "userspace")
zhanghongbo13a161c2012-08-17 19:06:33 +080098if [ -z "$supported" ]; then
hongbo.zhangba2cbcc2012-08-07 13:35:32 +080099 log_skip "userspace not supported"
Lisa Nguyend713d632014-08-20 17:26:04 -0700100 return 0
hongbo.zhangba2cbcc2012-08-07 13:35:32 +0800101fi
102
Daniel Lezcano2373b912011-07-26 14:39:00 +0200103save_governors
104save_frequencies
105
Lisa Nguyen5a0c2ba2015-01-27 13:57:25 -0800106trap "restore_frequencies; restore_governors; sigtrap" HUP INT TERM
Daniel Lezcano2373b912011-07-26 14:39:00 +0200107
108for_each_cpu check_deviation
109
110restore_frequencies
111restore_governors
Sanjay Singh Rawat3bf61942013-04-10 14:06:14 +0530112test_status_show