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