Remove bashisms in the cpufreq test module in addition to renaming variables to more meaningful names and minor cleanups.
Signed-off-by: Lisa Nguyen <lisa.ngu...@linaro.org> --- cpufreq/cpufreq_01.sh | 4 ++-- cpufreq/cpufreq_02.sh | 5 ++--- cpufreq/cpufreq_03.sh | 13 ++++++------ cpufreq/cpufreq_04.sh | 16 +++++++-------- cpufreq/cpufreq_05.sh | 24 +++++++++++------------ cpufreq/cpufreq_06.sh | 48 ++++++++++++++++++++------------------------- cpufreq/cpufreq_07.sh | 48 ++++++++++++++++++++------------------------- cpufreq/cpufreq_08.sh | 26 +++++++++++------------- cpufreq/cpufreq_09.sh | 25 +++++++++++------------ cpufreq/cpufreq_sanity.sh | 9 ++++----- 10 files changed, 96 insertions(+), 122 deletions(-) diff --git a/cpufreq/cpufreq_01.sh b/cpufreq/cpufreq_01.sh index 6f092fe..fa86941 100755 --- a/cpufreq/cpufreq_01.sh +++ b/cpufreq/cpufreq_01.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # PM-QA validation test suite for the power management on Linux # @@ -25,7 +25,7 @@ # URL : https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpufreq_01 -source ../include/functions.sh +. ../include/functions.sh FILES="scaling_available_frequencies scaling_cur_freq scaling_setspeed" diff --git a/cpufreq/cpufreq_02.sh b/cpufreq/cpufreq_02.sh index 34e19b7..760bb78 100755 --- a/cpufreq/cpufreq_02.sh +++ b/cpufreq/cpufreq_02.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # PM-QA validation test suite for the power management on Linux # @@ -22,10 +22,9 @@ # Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation) # - initial API and implementation # - # URL : https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpufreq_02 -source ../include/functions.sh +. ../include/functions.sh FILES="scaling_available_governors scaling_governor" diff --git a/cpufreq/cpufreq_03.sh b/cpufreq/cpufreq_03.sh index 65a6ad7..4a5029b 100755 --- a/cpufreq/cpufreq_03.sh +++ b/cpufreq/cpufreq_03.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # PM-QA validation test suite for the power management on Linux # @@ -25,20 +25,19 @@ # URL : https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpufreq_03 -source ../include/functions.sh +. ../include/functions.sh check_governor() { - - local cpu=$1 - local newgov=$2 + cpu=$1 + newgov=$2 shift 2 - local oldgov=$(get_governor $cpu) + oldgov=$(get_governor $cpu) set_governor $cpu $newgov - check "governor change to '$newgov'" "test \"$(get_governor $cpu)\" == \"$newgov\"" + check "governor change to '$newgov'" "test \"$(get_governor $cpu)\" = \"$newgov\"" set_governor $cpu $oldgov } diff --git a/cpufreq/cpufreq_04.sh b/cpufreq/cpufreq_04.sh index d4ed1bd..f9b16dc 100755 --- a/cpufreq/cpufreq_04.sh +++ b/cpufreq/cpufreq_04.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # PM-QA validation test suite for the power management on Linux # @@ -22,25 +22,23 @@ # Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation) # - initial API and implementation # - # URL : https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpufreq_04 -source ../include/functions.sh +. ../include/functions.sh check_frequency() { - - local cpu=$1 - local newfreq=$2 + cpu=$1 + newfreq=$2 shift 2 - local oldgov=$(get_governor $cpu) - local oldfreq=$(get_frequency $cpu) + oldgov=$(get_governor $cpu) + oldfreq=$(get_frequency $cpu) set_governor $cpu userspace set_frequency $cpu $newfreq - check "setting frequency '$(frequnit $newfreq)'" "test \"$(get_frequency $cpu)\" == \"$newfreq\"" + check "setting frequency '$(frequnit $newfreq)'" "test \"$(get_frequency $cpu)\" = \"$newfreq\"" set_frequency $cpu $oldfreq set_governor $cpu $oldgov diff --git a/cpufreq/cpufreq_05.sh b/cpufreq/cpufreq_05.sh index 1f0dd8d..1113106 100755 --- a/cpufreq/cpufreq_05.sh +++ b/cpufreq/cpufreq_05.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # PM-QA validation test suite for the power management on Linux # @@ -22,37 +22,35 @@ # Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation) # - initial API and implementation # - # URL : https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpufreq_05 -source ../include/functions.sh +. ../include/functions.sh save_governors -trap restore_governors SIGHUP SIGINT SIGTERM +trap restore_governors HUP INT TERM switch_ondemand() { - local cpu=$1 + cpu=$1 set_governor $cpu 'ondemand' } switch_conservative() { - local cpu=$1 + cpu=$1 set_governor $cpu 'conservative' } switch_userspace() { - local cpu=$1 + cpu=$1 set_governor $cpu 'userspace' } check_governor() { - local cpu=$1 - local gov=$2 + cpu=$1 + gov=$2 + GOV_PATH=$CPU_PATH/$cpu/cpufreq/$gov - if [ -d $CPU_PATH/$cpu/cpufreq/$gov ]; then - GOV_PATH=$CPU_PATH/$cpu/cpufreq/$gov - else + if [ ! -d $GOV_PATH ]; then GOV_PATH=$CPU_PATH/cpufreq/$gov fi check "'$gov' directory exists" "test -d $GOV_PATH" @@ -94,7 +92,7 @@ fi nrcpus=$(ls $CPU_PATH | grep "cpu[0-9].*" | wc -l) if [ $nrcpus -gt 1 ]; then affected=$(cat $CPU_PATH/cpu0/cpufreq/affected_cpus | grep 1) - if [ -z $affected ]; then + if [ -z "$affected" ]; then switch_ondemand cpu0 switch_conservative cpu1 check_governor cpu0 'ondemand' diff --git a/cpufreq/cpufreq_06.sh b/cpufreq/cpufreq_06.sh index e2e708a..9159c9e 100755 --- a/cpufreq/cpufreq_06.sh +++ b/cpufreq/cpufreq_06.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # PM-QA validation test suite for the power management on Linux # @@ -22,40 +22,41 @@ # Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation) # - initial API and implementation # - # URL : https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpufreq_06 -source ../include/functions.sh +. ../include/functions.sh CPUCYCLE=../utils/cpucycle +INDEX=1 +cpufreq_ratio_array_name="freq_ratio" compute_freq_ratio() { - - local cpu=$1 - local freq=$2 + cpu=$1 + freq=$2 set_frequency $cpu $freq result=$($CPUCYCLE $cpu) if [ $? -ne 0 ]; then - return 1 + return 1 fi - results[$index]=$(echo "scale=3;($result / $freq)" | bc -l) + result=$(echo "scale=3;($result / $freq)" | bc -l) + + eval $cpufreq_ratio_array_name$index=$result + eval export $cpufreq_ratio_array_name$index index=$((index + 1)) + } compute_freq_ratio_sum() { - - res=${results[$index]} - sum=$(echo "($sum + $res)" | bc -l) - index=$((index + 1)) - + res=$(eval echo \$$cpufreq_ratio_array_name$index) + sum=$(echo "($sum + $res)" | bc) + index=$(($index + 1)) } __check_freq_deviation() { - - res=${results[$index]} + res=$(eval echo \$$cpufreq_ratio_array_name$index) # compute deviation dev=$(echo "scale=3;((( $res - $avg ) / $avg) * 100 )" | bc -l) @@ -63,38 +64,31 @@ __check_freq_deviation() { # change to absolute dev=$(echo $dev | awk '{ print ($1 >= 0) ? $1 : 0 - $1}') - index=$((index + 1)) - res=$(echo "($dev > 5.0)" | bc -l) if [ "$res" = "1" ]; then - return 1 + return 1 fi return 0 } check_freq_deviation() { - - local cpu=$1 - local freq=$2 + cpu=$1 + freq=$2 check "deviation for frequency $(frequnit $freq)" __check_freq_deviation } check_deviation() { - - local cpu=$1 + cpu=$1 set_governor $cpu userspace - for_each_frequency $cpu compute_freq_ratio index=0 sum=0 - for_each_frequency $cpu compute_freq_ratio_sum - avg=$(echo "scale=3;($sum / $index)" | bc -l) index=0 @@ -110,7 +104,7 @@ fi save_governors save_frequencies -trap "restore_frequencies; restore_governors; sigtrap" SIGHUP SIGINT SIGTERM +trap "restore_frequencies; restore_governors; sigtrap" HUP INT TERM for_each_cpu check_deviation diff --git a/cpufreq/cpufreq_07.sh b/cpufreq/cpufreq_07.sh index b65d212..24f7c97 100755 --- a/cpufreq/cpufreq_07.sh +++ b/cpufreq/cpufreq_07.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # PM-QA validation test suite for the power management on Linux # @@ -22,48 +22,42 @@ # Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation) # - initial API and implementation # - # URL : https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpufreq_07 -source ../include/functions.sh +. ../include/functions.sh CPUBURN=../utils/cpuburn check_ondemand() { - - local cpu=$1 - local maxfreq=$(get_max_frequency $cpu) - local minfreq=$(get_min_frequency $cpu) - local curfreq=$(get_frequency $cpu) - local pid= + cpu=$1 + maxfreq=$(get_max_frequency $cpu) + minfreq=$(get_min_frequency $cpu) + curfreq=$(get_frequency $cpu) set_governor $cpu ondemand # wait for a quescient point for i in $(seq 1 10); do + if [ "$minfreq" -eq "$(get_frequency $cpu)" ]; then + $CPUBURN $cpu & + pid=$! - if [ "$minfreq" -eq "$(get_frequency $cpu)" ]; then - - $CPUBURN $cpu & - pid=$! - - sleep 1 - wait_latency $cpu - curfreq=$(get_frequency $cpu) - kill $pid - - check "'ondemand' increase frequency on load" "test \"$curfreq\" == \"$maxfreq\"" + sleep 1 + wait_latency $cpu + curfreq=$(get_frequency $cpu) + kill $pid - sleep 1 - curfreq=$(get_frequency $cpu) + check "'ondemand' increase frequency on load" "test \"$curfreq\" = \"$maxfreq\"" - check "'ondemand' decrease frequency on idle" "test \"$curfreq\" == \"$minfreq\"" + sleep 1 + curfreq=$(get_frequency $cpu) - return 0 - fi + check "'ondemand' decrease frequency on idle" "test \"$curfreq\" = \"$minfreq\"" - sleep 1 + return 0 + fi + sleep 1 done log_skip "can not reach a quescient point for 'ondemand'" @@ -79,7 +73,7 @@ fi save_governors -trap "restore_governors; sigtrap" SIGHUP SIGINT SIGTERM +trap "restore_governors; sigtrap" HUP INT TERM for_each_cpu check_ondemand diff --git a/cpufreq/cpufreq_08.sh b/cpufreq/cpufreq_08.sh index 2250017..e43c002 100755 --- a/cpufreq/cpufreq_08.sh +++ b/cpufreq/cpufreq_08.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # PM-QA validation test suite for the power management on Linux # @@ -22,18 +22,15 @@ # Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation) # - initial API and implementation # - # URL : https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpufreq_08 -source ../include/functions.sh +. ../include/functions.sh CPUBURN=../utils/cpuburn check_frequency() { - local cpu=$1 - local freq=$2 - local curfreq= - local pid= + cpu=$1 + freq=$2 $CPUBURN $cpu & pid=$! @@ -44,20 +41,19 @@ check_frequency() { curfreq=$(get_frequency $cpu) kill $pid - check "'userspace' $(frequnit $freq) is fixed" "test \"$curfreq\" == \"$freq\"" + check "'userspace' $(frequnit $freq) is fixed" "test \"$curfreq\" = \"$freq\"" if [ "$?" != "0" ]; then - return 1 + return 1 fi return 0 } check_userspace() { - - local cpu=$1 - local maxfreq=$(get_max_frequency $cpu) - local minfreq=$(get_min_frequency $cpu) - local curfreq=$(get_frequency $cpu) + cpu=$1 + maxfreq=$(get_max_frequency $cpu) + minfreq=$(get_min_frequency $cpu) + curfreq=$(get_frequency $cpu) set_governor $cpu userspace @@ -72,7 +68,7 @@ if [ -z "$supported" ]; then return 0 fi -trap "restore_governors; sigtrap" SIGHUP SIGINT SIGTERM +trap "restore_governors; sigtrap" HUP INT TERM for_each_cpu check_userspace diff --git a/cpufreq/cpufreq_09.sh b/cpufreq/cpufreq_09.sh index 62c953d..7a3cd26 100755 --- a/cpufreq/cpufreq_09.sh +++ b/cpufreq/cpufreq_09.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # PM-QA validation test suite for the power management on Linux # @@ -22,27 +22,25 @@ # Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation) # - initial API and implementation # - # URL : https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpufreq_09 -source ../include/functions.sh +. ../include/functions.sh CPUBURN=../utils/cpuburn check_powersave() { - - local cpu=$1 - local minfreq=$(get_min_frequency $cpu) - local curfreq=$(get_frequency $cpu) + cpu=$1 + minfreq=$(get_min_frequency $cpu) + curfreq=$(get_frequency $cpu) set_governor $cpu powersave wait_latency $cpu curfreq=$(get_frequency $cpu) - check "'powersave' sets frequency to $(frequnit $minfreq)" "test \"$curfreq\" == \"$minfreq\"" + check "'powersave' sets frequency to $(frequnit $minfreq)" "test \"$curfreq\" = \"$minfreq\"" if [ "$?" != "0" ]; then - return 1 + return 1 fi $CPUBURN $cpu & @@ -52,9 +50,9 @@ check_powersave() { curfreq=$(get_frequency $cpu) kill $pid - check "'powersave' frequency $(frequnit $minfreq) is fixed" "test \"$curfreq\" == \"$minfreq\"" + check "'powersave' frequency $(frequnit $minfreq) is fixed" "test \"$curfreq\" = \"$minfreq\"" if [ "$?" -ne "0" ]; then - return 1 + return 1 fi return 0 @@ -65,12 +63,11 @@ save_governors supported=$(cat $CPU_PATH/cpu0/cpufreq/scaling_available_governors | grep "powersave") if [ -z "$supported" ]; then log_skip "powersave not supported" - return 0 + return 1 fi -trap "restore_governors; sigtrap" SIGHUP SIGINT SIGTERM +trap "restore_governors; sigtrap" HUP INT TERM for_each_cpu check_powersave - restore_governors test_status_show diff --git a/cpufreq/cpufreq_sanity.sh b/cpufreq/cpufreq_sanity.sh index e3518b8..4c598e7 100755 --- a/cpufreq/cpufreq_sanity.sh +++ b/cpufreq/cpufreq_sanity.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # PM-QA validation test suite for the power management on Linux # @@ -23,7 +23,7 @@ # - initial API and implementation # -source ../include/functions.sh +. ../include/functions.sh is_root if [ $? -ne 0 ]; then @@ -32,10 +32,9 @@ if [ $? -ne 0 ]; then fi check_cpufreq_sysfs_entry() { + cpufreq_sysfs_dir=$CPU_PATH/cpufreq - local dirpath=$CPU_PATH/cpufreq - - test -d $dirpath + test -d $cpufreq_sysfs_dir if [ $? -ne 0 ]; then echo "cpufreq is not supported. Skipping all cpufreq tests" skip_tests cpufreq -- 1.7.9.5 _______________________________________________ linaro-dev mailing list linaro-dev@lists.linaro.org http://lists.linaro.org/mailman/listinfo/linaro-dev