The syntax for arrays, foo[index], is defined in BASH. Replace BASH arrays with ones that are POSIX compliant.
Signed-off-by: Lisa Nguyen lisa.nguyen@linaro.org --- cpufreq/cpufreq_06.sh | 20 ++++++++-------- include/functions.sh | 14 +++++++---- include/thermal_functions.sh | 54 +++++++++++++++++++++++++----------------- thermal/thermal_02.sh | 21 ++++++++-------- thermal/thermal_06.sh | 32 +++++++++++++++---------- 5 files changed, 82 insertions(+), 59 deletions(-)
diff --git a/cpufreq/cpufreq_06.sh b/cpufreq/cpufreq_06.sh index a6fbd15..3bb104d 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,21 +42,24 @@ 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() { - - res=${results[$index]} + index=0 + sum=0 + res=$(eval echo $$freq_results_array$index) sum=$(echo "($sum + $res)" | bc -l) index=$((index + 1))
}
__check_freq_deviation() { - - res=${results[$index]} + index=0 + res=$(eval echo $$freq_results_array$index)
# compute deviation dev=$(echo "scale=3;((( $res - $avg ) / $avg) * 100 )" | bc -l) @@ -90,14 +94,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 b5c9666..e3eb140 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,7 +346,9 @@ save_governors() { index=0
for cpu in $cpus; do - governors_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_governor) + scaling_gov_value=$(cat $CPU_PATH/$cpu/cpufreq/scaling_governor) + eval $gov_array$index=$scaling_gov_value + eval export $gov_array$index index=$((index + 1)) done } @@ -354,7 +358,7 @@ restore_governors() { index=0
for cpu in $cpus; do - oldgov=${governors_backup[$index]} + oldgov=$(eval echo $$gov_array$index) echo $oldgov > $CPU_PATH/$cpu/cpufreq/scaling_governor index=$((index + 1)) done @@ -365,7 +369,9 @@ save_frequencies() { index=0
for cpu in $cpus; do - frequencies_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq) + freq_value=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq) + eval $freq_array$index=$freq_value + eval export $freq_array$index index=$((index + 1)) done } @@ -375,7 +381,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..3b6cfd3 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,10 +182,14 @@ 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)) + 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,7 +198,9 @@ store_scaling_maxfreq() { index=0
for cpu in $cpus; do - scale_freq[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_max_freq) + 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 index=$((index + 1)) done return 0 @@ -215,11 +223,12 @@ 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,9 +237,9 @@ 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,11 +291,12 @@ 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,9 +305,9 @@ 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_02.sh b/thermal/thermal_02.sh index 0786870..9ec02ab 100755 --- a/thermal/thermal_02.sh +++ b/thermal/thermal_02.sh @@ -31,33 +31,32 @@ CDEV_ATTRIBUTES="cur_state max_state type uevent"
check_cooling_device_attributes() { - - dirpath=$THERMAL_PATH/$1 cdev_name=$1 + cdev_name_dir=$THERMAL_PATH/$cdev_name shift 1
- for i in $CDEV_ATTRIBUTES; do - check_file $i $dirpath || return 1 + for attribute in $CDEV_ATTRIBUTES; do + check_file $attribute $cdev_name_dir || return 1 done
}
check_cooling_device_states() { - dirpath=$THERMAL_PATH/$1 cdev_name=$1 + cdev_name_dir=$THERMAL_PATH/$cdev_name shift 1 - max_state=$(cat $dirpath/max_state) - prev_state_val=$(cat $dirpath/cur_state) + max_state=$(cat $cdev_name_dir/max_state) + prev_state_val=$(cat $cdev_name_dir/cur_state) count=0 cur_state_val=0 while (test $count -le $max_state); do - echo $count > $dirpath/cur_state - cur_state_val=$(cat $dirpath/cur_state) - check "$cdev_name cur_state=$count"\ + echo $count > $cdev_name_dir/cur_state + cur_state_val=$(cat $cdev_name_dir/cur_state) + check "$cdev_name with cur_state=$count"\ "test $cur_state_val -eq $count" || return 1 count=$((count+1)) done - echo $prev_state_val > $dirpath/cur_state + echo $prev_state_val > $cdev_name_dir/cur_state }
set_thermal_governors user_space diff --git a/thermal/thermal_06.sh b/thermal/thermal_06.sh index 9d62a07..b511329 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 + thermal_zone_path=$THERMAL_PATH/$zone_name shift 1
count=0 @@ -58,18 +59,25 @@ 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) + 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 - trip_cross[$index]=$((${trip_cross[$index]} + 1)) + 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))
@@ -77,14 +85,14 @@ check_trip_point_change() { count=$((count + 1)) done index=0 - for trip in $(ls $dirpath | grep "trip_point_['$MAX_ZONE']_temp"); do + for trip in $trip_point_temps; do get_trip_id $trip trip_id=$? - trip_type=$(cat $dirpath/trip_point_$((trip_id))_type) - trip_temp=$(cat $dirpath/$trip) + trip_type=$(cat $thermal_zone_path/trip_point_"$trip_id"_type) + trip_temp=$(cat $thermal_zone_path/$trip)
if [ $trip_type != "critical" ]; then - count=${trip_cross[$index]} + count=$(eval echo $$trip_cross_array$index) check "$trip:$trip_temp crossed" "test $count -gt 0" fi index=$((index + 1))