diff options
author | Lisa Nguyen <lisa.nguyen@linaro.org> | 2015-02-02 12:30:06 -0800 |
---|---|---|
committer | Lisa Nguyen <lisa.nguyen@linaro.org> | 2015-02-02 13:56:29 -0800 |
commit | 15e40ffbbd7397c84c66397d60a9f042cda3818b (patch) | |
tree | 43310bfc758fbd98ff2e498e66a38b44a96e1211 | |
parent | 2d49a68f00af4db9e69ef86b45e0d17432835c9e (diff) | |
download | pm-qa-15e40ffbbd7397c84c66397d60a9f042cda3818b.tar.gz |
Remove BASH arrays
The syntax for arrays, foo[index], is defined in BASH. Replace BASH
arrays with ones that are POSIX compliant.
Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org>
Signed-off-by: Lisa Nguyen <lisa.nguyen@linaro.org>
-rwxr-xr-x | cpufreq/cpufreq_06.sh | 17 | ||||
-rw-r--r-- | include/functions.sh | 20 | ||||
-rw-r--r-- | include/thermal_functions.sh | 63 | ||||
-rwxr-xr-x | thermal/thermal_06.sh | 69 |
4 files changed, 102 insertions, 67 deletions
diff --git a/cpufreq/cpufreq_06.sh b/cpufreq/cpufreq_06.sh index a6fbd15..87b2c73 100755 --- a/cpufreq/cpufreq_06.sh +++ b/cpufreq/cpufreq_06.sh @@ -28,9 +28,10 @@ . ../include/functions.sh CPUCYCLE=../utils/cpucycle +freq_results_array="results" compute_freq_ratio() { - + index=0 cpu=$1 freq=$2 @@ -41,13 +42,17 @@ compute_freq_ratio() { return 1 fi - results[$index]=$(echo "scale=3;($result / $freq)" | bc -l) + value=$(echo "scale=3;($result / $freq)" | bc -l) + eval $freq_results_array$index=$value + eval export $freq_results_array$index index=$((index + 1)) } compute_freq_ratio_sum() { + index=0 + sum=0 - res=${results[$index]} + res=$(eval echo \$$freq_results_array$index) sum=$(echo "($sum + $res)" | bc -l) index=$((index + 1)) @@ -55,7 +60,7 @@ compute_freq_ratio_sum() { __check_freq_deviation() { - res=${results[$index]} + res=$(eval echo \$$freq_results_array$index) # compute deviation dev=$(echo "scale=3;((( $res - $avg ) / $avg) * 100 )" | bc -l) @@ -90,14 +95,10 @@ check_deviation() { 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 for_each_frequency $cpu check_freq_deviation } diff --git a/include/functions.sh b/include/functions.sh index b05ded0..11c911a 100644 --- a/include/functions.sh +++ b/include/functions.sh @@ -35,6 +35,8 @@ fail_count=0 skip_count=0 test_script_status="pass" NANOSLEEP="../utils/nanosleep" +gov_array="governors_backup" +freq_array="frequencies_backup" test_status_show() { if [ $fail_count -ne 0 ]; then @@ -344,8 +346,9 @@ save_governors() { index=0 for cpu in $cpus; do - governors_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_governor) - index=$((index + 1)) + scaling_gov_value=$(cat $CPU_PATH/$cpu/cpufreq/scaling_governor) + eval $gov_array$index=$scaling_gov_value + eval export $gov_array$index done } @@ -354,9 +357,9 @@ restore_governors() { index=0 for cpu in $cpus; do - oldgov=${governors_backup[$index]} - echo $oldgov > $CPU_PATH/$cpu/cpufreq/scaling_governor - index=$((index + 1)) + oldgov=$(eval echo \$$gov_array$index) + echo $oldgov > $CPU_PATH/$cpu/cpufreq/scaling_governor + index=$((index + 1)) done } @@ -365,8 +368,9 @@ save_frequencies() { index=0 for cpu in $cpus; do - frequencies_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq) - index=$((index + 1)) + freq_value=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq) + eval $freq_array$index=$freq_value + eval export $freq_array$index done } @@ -375,7 +379,7 @@ restore_frequencies() { index=0 for cpu in $cpus; do - oldfreq=${frequencies_backup[$index]} + oldfreq=$(eval echo \$$freq_array$index) echo $oldfreq > $CPU_PATH/$cpu/cpufreq/scaling_setspeed index=$((index + 1)) done diff --git a/include/thermal_functions.sh b/include/thermal_functions.sh index 56f9d33..0147fc0 100644 --- a/include/thermal_functions.sh +++ b/include/thermal_functions.sh @@ -26,6 +26,10 @@ THERMAL_PATH="/sys/devices/virtual/thermal" MAX_ZONE=0-12 MAX_CDEV=0-50 +scaling_freq_array="scaling_freq" +mode_array="mode_list" +thermal_gov_array="thermal_governor_backup" +thermal_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") check_valid_temp() { file=$1 @@ -54,9 +58,7 @@ for_each_thermal_zone() { thermal_func=$1 shift 1 - thermal_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") - - for thermal_zone in $zones; do + for thermal_zone in $thermal_zones; do INC=0 $thermal_func $thermal_zone $@ done @@ -180,11 +182,16 @@ check_scaling_freq() { flag=0 for cpu in $cpus; do - if [ ${before_freq_list[$index]} -ne ${after_freq_list[$index]} ] ; then - flag=1 - fi - index=$((index + 1)) - done + after_freq=$(eval echo \$$after_freq_list$index) + before_freq=$(eval echo \$$before_freq_list$index) + + if [ $after_freq -ne $before_freq ]; then + flag=1 + fi + + index=$((index + 1)) + done + return $flag } @@ -192,9 +199,11 @@ store_scaling_maxfreq() { index=0 for cpu in $cpus; do - scale_freq[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_max_freq) - index=$((index + 1)) + scaling_freq_max_value=$(cat $CPU_PATH/$cpu/cpufreq/scaling_max_freq) + eval $scaling_freq_array$index=$scaling_freq_max_value + eval echo $scaling_freq_array$index done + return 0 } @@ -215,12 +224,14 @@ disable_all_thermal_zones() { index=0 - th_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") - for zone in $th_zones; do - mode_list[$index]=$(cat $THERMAL_PATH/$zone/mode) + for thermal_zone in $thermal_zones; do + mode=$(cat $THERMAL_PATH/$thermal_zone/mode) + eval $mode_array$index=$mode + eval export $mode_array$index index=$((index + 1)) - echo -n "disabled" > $THERMAL_PATH/$zone/mode + echo -n "disabled" > $THERMAL_PATH/$thermal_zone/mode done + return 0 } @@ -228,11 +239,12 @@ enable_all_thermal_zones() { index=0 - th_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") - for zone in $th_zones; do - echo ${mode_list[$index]} > $THERMAL_PATH/$zone/mode + for thermal_zone in $thermal_zones; do + mode=$(eval echo \$$mode_array$index) + echo $mode > $THERMAL_PATH/$thermal_zone/mode index=$((index + 1)) done + return 0 } @@ -282,12 +294,14 @@ set_thermal_governors() { gov=$1 index=0 - th_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") - for zone in $th_zones; do - thermal_governor_backup[$index]=$(cat $THERMAL_PATH/$zone/policy) + for thermal_zone in $thermal_zones; do + policy=$(cat $THERMAL_PATH/$thermal_zone/policy) + eval $thermal_gov_array$index=$policy + eval export $thermal_gov_array$index index=$((index + 1)) - echo $gov > $THERMAL_PATH/$zone/policy + echo $gov > $THERMAL_PATH/$thermal_zone/policy done + return 0 } @@ -295,10 +309,11 @@ restore_thermal_governors() { index=0 - th_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") - for zone in $th_zones; do - echo ${thermal_governor_backup[$index]} > $THERMAL_PATH/$zone/policy + for thermal_zone in $thermal_zones; do + old_policy=$(eval echo \$$thermal_gov_array$index) + echo $old_policy > $THERMAL_PATH/$thermal_zone/policy index=$((index + 1)) done + return 0 } diff --git a/thermal/thermal_06.sh b/thermal/thermal_06.sh index 9d62a07..8c42fa9 100755 --- a/thermal/thermal_06.sh +++ b/thermal/thermal_06.sh @@ -31,6 +31,7 @@ TEST_LOOP=100 CPU_HEAT_BIN=../utils/heat_cpu cpu_pid=0 +trip_cross_array="trip_cross" heater_kill() { if [ $cpu_pid -ne 0 ]; then @@ -40,8 +41,8 @@ heater_kill() { } check_trip_point_change() { - dirpath=$THERMAL_PATH/$1 zone_name=$1 + dirpath=$THERMAL_PATH/$zone_name shift 1 count=0 @@ -58,36 +59,50 @@ check_trip_point_change() { start_glmark2 index=0 - for trip in $(ls $dirpath | grep "trip_point_['$MAX_ZONE']_temp"); do - trip_cross[$index]=0 - index=$((index + 1)) + + trip_point_temps=$(ls $thermal_zone_path | grep "trip_point_['$MAX_ZONE']_temp") + + for trip in $trip_point_temps; do + trip_value=0 + eval $trip_cross_array$index=$trip_value + eval export $trip_cross_array$index + index=$((index + 1)) done + while (test $count -lt $TEST_LOOP); do - index=0 - sleep 1 - for trip in $(ls $dirpath | grep "trip_point_['$MAX_ZONE']_temp"); do - cur_temp=$(cat $dirpath/temp) - trip_temp=$(cat $dirpath/$trip) - if [ $cur_temp -gt $trip_temp ]; then - trip_cross[$index]=$((${trip_cross[$index]} + 1)) - fi - index=$((index + 1)) - - done - count=$((count + 1)) + index=0 + sleep 1 + + for trip in $trip_point_temps; do + cur_temp=$(cat $thermal_zone_path/temp) + trip_temp=$(cat $thermal_zone_path/$trip) + + if [ $cur_temp -gt $trip_temp ]; then + value=$(eval echo \$$trip_cross_array$index) + value=$((value + 1)) + eval $trip_cross_array$index=$value + eval export $trip_cross_array$index + fi + + index=$((index + 1)) + done + + count=$((count + 1)) done + index=0 - for trip in $(ls $dirpath | grep "trip_point_['$MAX_ZONE']_temp"); do - get_trip_id $trip - trip_id=$? - trip_type=$(cat $dirpath/trip_point_$((trip_id))_type) - trip_temp=$(cat $dirpath/$trip) - - if [ $trip_type != "critical" ]; then - count=${trip_cross[$index]} - check "$trip:$trip_temp crossed" "test $count -gt 0" - fi - index=$((index + 1)) + for trip in $trip_point_temps; do + get_trip_id $trip + trip_id=$? + trip_type=$(cat $thermal_zone_path/trip_point_"$trip_id"_type) + trip_temp=$(cat $thermal_zone_path/$trip) + + if [ $trip_type != "critical" ]; then + count=$(eval echo \$$trip_cross_array$index) + check "$trip:$trip_temp crossed" "test $count -gt 0" + fi + + index=$((index + 1)) done heater_kill |