Lisa Nguyen | adf9df9 | 2015-01-25 18:16:45 -0800 | [diff] [blame] | 1 | #!/bin/sh |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 2 | # |
Daniel Lezcano | 35fb172 | 2011-10-03 13:56:11 +0200 | [diff] [blame] | 3 | # PM-QA validation test suite for the power management on Linux |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 4 | # |
| 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 Rawat | 912729b | 2013-08-21 20:18:40 +0530 | [diff] [blame] | 26 | # URL : https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpufreq_06 |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 27 | |
Lisa Nguyen | adf9df9 | 2015-01-25 18:16:45 -0800 | [diff] [blame] | 28 | . ../include/functions.sh |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 29 | |
| 30 | CPUCYCLE=../utils/cpucycle |
Lisa Nguyen | 15e40ff | 2015-02-02 12:30:06 -0800 | [diff] [blame] | 31 | freq_results_array="results" |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 32 | |
| 33 | compute_freq_ratio() { |
Lisa Nguyen | 15e40ff | 2015-02-02 12:30:06 -0800 | [diff] [blame] | 34 | index=0 |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 35 | cpu=$1 |
| 36 | freq=$2 |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 37 | |
| 38 | set_frequency $cpu $freq |
| 39 | |
| 40 | result=$($CPUCYCLE $cpu) |
Sanjay Singh Rawat | c7af87b | 2013-12-15 13:30:37 +0530 | [diff] [blame] | 41 | if [ $? -ne 0 ]; then |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 42 | return 1 |
| 43 | fi |
| 44 | |
Lisa Nguyen | 374c1b5 | 2015-10-21 17:57:04 -0700 | [diff] [blame] | 45 | value=$(echo $result $freq | awk '{ printf "%.3f", $1 / $2 }') |
Lisa Nguyen | 15e40ff | 2015-02-02 12:30:06 -0800 | [diff] [blame] | 46 | eval $freq_results_array$index=$value |
| 47 | eval export $freq_results_array$index |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 48 | index=$((index + 1)) |
| 49 | } |
| 50 | |
| 51 | compute_freq_ratio_sum() { |
Lisa Nguyen | 15e40ff | 2015-02-02 12:30:06 -0800 | [diff] [blame] | 52 | index=0 |
| 53 | sum=0 |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 54 | |
Lisa Nguyen | 15e40ff | 2015-02-02 12:30:06 -0800 | [diff] [blame] | 55 | res=$(eval echo \$$freq_results_array$index) |
Lisa Nguyen | 374c1b5 | 2015-10-21 17:57:04 -0700 | [diff] [blame] | 56 | sum=$(echo $sum $res | awk '{ printf "%f", $1 + $2 }') |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 57 | index=$((index + 1)) |
| 58 | |
| 59 | } |
| 60 | |
| 61 | __check_freq_deviation() { |
Lisa Nguyen | 15e40ff | 2015-02-02 12:30:06 -0800 | [diff] [blame] | 62 | res=$(eval echo \$$freq_results_array$index) |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 63 | |
Lisa Nguyen | 71eb7a9 | 2015-11-17 17:29:12 -0800 | [diff] [blame^] | 64 | if [ ! -z "$res" ]; then |
| 65 | # compute deviation |
| 66 | dev=$(echo $res $avg | awk '{printf "%.3f", (($1 - $2) / $2) * 100}') |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 67 | |
Lisa Nguyen | 71eb7a9 | 2015-11-17 17:29:12 -0800 | [diff] [blame^] | 68 | # change to absolute |
| 69 | dev=$(echo $dev | awk '{ print ($1 >= 0) ? $1 : 0 - $1}') |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 70 | |
Lisa Nguyen | 71eb7a9 | 2015-11-17 17:29:12 -0800 | [diff] [blame^] | 71 | index=$((index + 1)) |
| 72 | res=$(echo $dev | awk '{printf "%f", ($dev > 5.0)}') |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 73 | |
Lisa Nguyen | 71eb7a9 | 2015-11-17 17:29:12 -0800 | [diff] [blame^] | 74 | if [ "$res" = "1" ]; then |
| 75 | return 1 |
| 76 | fi |
| 77 | else |
| 78 | return 1 |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 79 | fi |
| 80 | |
| 81 | return 0 |
| 82 | } |
| 83 | |
| 84 | check_freq_deviation() { |
| 85 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 86 | cpu=$1 |
| 87 | freq=$2 |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 88 | |
| 89 | check "deviation for frequency $(frequnit $freq)" __check_freq_deviation |
| 90 | |
| 91 | } |
| 92 | |
| 93 | check_deviation() { |
| 94 | |
Lisa Nguyen | 4e0b59a | 2015-01-25 17:46:40 -0800 | [diff] [blame] | 95 | cpu=$1 |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 96 | |
| 97 | set_governor $cpu userspace |
| 98 | |
| 99 | for_each_frequency $cpu compute_freq_ratio |
| 100 | |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 101 | for_each_frequency $cpu compute_freq_ratio_sum |
| 102 | |
Lisa Nguyen | 374c1b5 | 2015-10-21 17:57:04 -0700 | [diff] [blame] | 103 | avg=$(echo $sum $index | awk '{ printf "%.3f", $1 / $2}') |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 104 | |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 105 | for_each_frequency $cpu check_freq_deviation |
| 106 | } |
| 107 | |
hongbo.zhang | ba2cbcc | 2012-08-07 13:35:32 +0800 | [diff] [blame] | 108 | supported=$(cat $CPU_PATH/cpu0/cpufreq/scaling_available_governors | grep "userspace") |
zhanghongbo | 13a161c | 2012-08-17 19:06:33 +0800 | [diff] [blame] | 109 | if [ -z "$supported" ]; then |
hongbo.zhang | ba2cbcc | 2012-08-07 13:35:32 +0800 | [diff] [blame] | 110 | log_skip "userspace not supported" |
Lisa Nguyen | d713d63 | 2014-08-20 17:26:04 -0700 | [diff] [blame] | 111 | return 0 |
hongbo.zhang | ba2cbcc | 2012-08-07 13:35:32 +0800 | [diff] [blame] | 112 | fi |
| 113 | |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 114 | save_governors |
| 115 | save_frequencies |
| 116 | |
Lisa Nguyen | 5a0c2ba | 2015-01-27 13:57:25 -0800 | [diff] [blame] | 117 | trap "restore_frequencies; restore_governors; sigtrap" HUP INT TERM |
Daniel Lezcano | 2373b91 | 2011-07-26 14:39:00 +0200 | [diff] [blame] | 118 | |
| 119 | for_each_cpu check_deviation |
| 120 | |
| 121 | restore_frequencies |
| 122 | restore_governors |
Sanjay Singh Rawat | 3bf6194 | 2013-04-10 14:06:14 +0530 | [diff] [blame] | 123 | test_status_show |