Remove bashisms such as bash arrays and local keywords in all function scripts. Replace bash arrays with POSIX-compliant ones to store a series of values. Some variables are renamed to be clear of what values are assigned to them. Formatting has been changed to make the scripts more readable.
However, suspend_functions.sh has not been fully tested since the suspend test module is currently disabled by default in PM-QA.
Signed-off-by: Lisa Nguyen lisa.nguyen@linaro.org --- include/functions.sh | 248 ++++++++++++++++++++---------------------- include/suspend_functions.sh | 4 +- include/thermal_functions.sh | 219 +++++++++++++++++++------------------ 3 files changed, 233 insertions(+), 238 deletions(-)
diff --git a/include/functions.sh b/include/functions.sh index ebe96ad..1de7ab3 100644 --- a/include/functions.sh +++ b/include/functions.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # PM-QA validation test suite for the power management on Linux # @@ -23,13 +23,12 @@ # - initial API and implementation #
-source ../Switches.sh +. ../Switches.sh
CPU_PATH="/sys/devices/system/cpu" TEST_NAME=$(basename ${0%.sh}) PREFIX=$TEST_NAME INC=0 -CPU= cpus=$(ls $CPU_PATH | grep "cpu[0-9].*") pass_count=0 fail_count=0 @@ -50,9 +49,9 @@ test_status_show() { fi
echo " " - if [[ "$test_script_status" == "fail" ]]; then + if [ "$test_script_status" = "fail" ]; then echo "$TEST_NAME: fail" - elif [[ "$test_script_status" == "skip" ]]; then + elif [ "$test_script_status" = "skip" ]; then echo "$TEST_NAME: skip" else echo "$TEST_NAME: pass" @@ -77,11 +76,11 @@ log_begin() { }
log_end() { - printf "$*\n" + echo "$*"
- if [[ "$*" == "Err" ]]; then + if [ "$*" = "Err" ]; then fail_count=$((fail_count + 1)) - elif [[ "$*" == "skip" ]]; then + elif [ "$*" = "skip" ]; then skip_count=$((skip_count + 1)) else pass_count=$((pass_count + 1)) @@ -94,114 +93,107 @@ log_skip() { }
for_each_cpu() { - - local func=$1 + cpu_func=$1 shift 1
for cpu in $cpus; do - INC=0 - CPU=/$cpu - $func $cpu $@ + INC=0 + CPU=/$cpu + $cpu_func $cpu $@ done
return 0 }
for_each_governor() { - - local cpu=$1 - local func=$2 - local dirpath=$CPU_PATH/$cpu/cpufreq - local governors=$(cat $dirpath/scaling_available_governors) + cpu=$1 + gov_func=$2 + cpufreq_dirpath=$CPU_PATH/$cpu/cpufreq + governors=$(cat $cpufreq_dirpath/scaling_available_governors) shift 2
for governor in $governors; do - $func $cpu $governor $@ + $gov_func $cpu $governor $@ done
return 0 }
for_each_frequency() { - - local cpu=$1 - local func=$2 - local dirpath=$CPU_PATH/$cpu/cpufreq - local frequencies=$(cat $dirpath/scaling_available_frequencies) + cpu=$1 + freq_func=$2 + cpufreq_dirpath=$CPU_PATH/$cpu/cpufreq + frequencies=$(cat $cpufreq_dirpath/scaling_available_frequencies) shift 2
for frequency in $frequencies; do - $func $cpu $frequency $@ + $freq_func $cpu $frequency $@ done
return 0 }
set_governor() { + cpu=$1 + scaling_gov_dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor + newgov=$2
- local cpu=$1 - local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor - local newgov=$2 - - echo $newgov > $dirpath + echo $newgov > $scaling_gov_dirpath }
get_governor() { + cpu=$1 + scaling_gov_dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor
- local cpu=$1 - local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_governor - - cat $dirpath + cat $scaling_gov_dirpath }
wait_latency() { - local cpu=$1 - local dirpath=$CPU_PATH/$cpu/cpufreq - local latency= - local nrfreq= - local sampling_rate= - local sleep_time= - local gov=$(cat $dirpath/scaling_governor) + cpu=$1 + cpufreq_dirpath=$CPU_PATH/$cpu/cpufreq + scaling_gov=$(cat $cpufreq_dirpath/scaling_governor) + nanosleep="../utils/nanosleep"
# consider per-policy governor case - if [ -e $CPU_PATH/$cpu/cpufreq/$gov ]; then - sampling_rate=$(cat $CPU_PATH/$cpu/cpufreq/$gov/sampling_rate) + if [ -e $cpufreq_dirpath/$scaling_gov ]; then + sampling_rate=$(cat $cpufreq_dirpath/$scaling_gov/sampling_rate) + elif [ -e $CPU_PATH/cpufreq/$scaling_gov/sampling_rate ]; then + sampling_rate=0 else - sampling_rate=$(cat $CPU_PATH/cpufreq/$gov/sampling_rate) + sampling_rate=$(cat $CPU_PATH/cpufreq/$scaling_gov/sampling_rate) fi + sampling_rate=$((sampling_rate * 1000)) # unit nsec
- latency=$(cat $dirpath/cpuinfo_transition_latency) + latency=$(cat $cpufreq_dirpath/cpuinfo_transition_latency) if [ $? -ne 0 ]; then - return 1 + return 1 fi
- nrfreq=$(cat $dirpath/scaling_available_frequencies | wc -w) + nrfreq=$(cat $cpufreq_dirpath/scaling_available_frequencies | wc -w) if [ $? -ne 0 ]; then - return 1 + return 1 fi
nrfreq=$((nrfreq + 1)) - sleep_time=$(($latency + $sampling_rate)) - - ../utils/nanosleep $(($nrfreq * $sleep_time)) + $nanosleep $(($nrfreq * $sleep_time)) }
frequnit() { - local freq=$1 - local ghz=$(echo "scale=1;($freq / 1000000)" | bc -l) - local mhz=$(echo "scale=1;($freq / 1000)" | bc -l) + freq=$1 + ghz=$(echo "scale=1;($freq / 1000000)" | bc -l) + mhz=$(echo "scale=1;($freq / 1000)" | bc -l)
res=$(echo "($ghz > 1.0)" | bc -l) if [ "$res" = "1" ]; then - echo $ghz GHz + echo $ghz GHz return 0 fi
res=$(echo "($mhz > 1.0)" | bc -l) if [ "$res" = "1" ];then - echo $mhz MHz + echo $mhz MHz return 0 fi
@@ -209,75 +201,73 @@ frequnit() { }
set_frequency() { - - local cpu=$1 - local dirpath=$CPU_PATH/$cpu/cpufreq - local newfreq=$2 - local setfreqpath=$dirpath/scaling_setspeed + cpu=$1 + cpufreq_dirpath=$CPU_PATH/$cpu/cpufreq + newfreq=$2 + setfreqpath=$cpufreq_dirpath/scaling_setspeed
echo $newfreq > $setfreqpath wait_latency $cpu }
get_frequency() { - local cpu=$1 - local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_cur_freq - cat $dirpath + cpu=$1 + scaling_cur_freq=$CPU_PATH/$cpu/cpufreq/scaling_cur_freq + cat $scaling_cur_freq }
get_max_frequency() { - local cpu=$1 - local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_max_freq - cat $dirpath + cpu=$1 + scaling_max_freq=$CPU_PATH/$cpu/cpufreq/scaling_max_freq + cat $scaling_max_freq }
get_min_frequency() { - local cpu=$1 - local dirpath=$CPU_PATH/$cpu/cpufreq/scaling_min_freq - cat $dirpath + cpu=$1 + scaling_min_freq=$CPU_PATH/$cpu/cpufreq/scaling_min_freq + cat $scaling_min_freq }
set_online() { - local cpu=$1 - local dirpath=$CPU_PATH/$cpu + cpu=$1 + current_cpu=$CPU_PATH/$cpu
if [ "$cpu" = "cpu0" ]; then - return 0 + return 0 fi
- echo 1 > $dirpath/online + echo 1 > $current_cpu/online }
set_offline() { - local cpu=$1 - local dirpath=$CPU_PATH/$cpu + cpu=$1 + current_cpu=$CPU_PATH/$cpu
if [ "$cpu" = "cpu0" ]; then - return 0 + return 0 fi
- echo 0 > $dirpath/online + echo 0 > $current_cpu/online }
get_online() { - local cpu=$1 - local dirpath=$CPU_PATH/$cpu + cpu=$1 + current_cpu=$CPU_PATH/$cpu
- cat $dirpath/online + cat $current_cpu/online }
check() { - - local descr=$1 - local func=$2 + description=$1 + function=$2 shift 2;
- log_begin "checking $descr" + log_begin "checking $description"
- $func $@ + $function $@ if [ $? -ne 0 ]; then - log_end "Err" - return 1 + log_end "Err" + return 1 fi
log_end "Ok" @@ -286,108 +276,100 @@ check() { }
check_file() { - local file=$1 - local dir=$2 + file=$1 + dir=$2
check "'$file' exists in '$dir'" "test -f" $dir/$file }
check_cpufreq_files() { - - local dirpath=$CPU_PATH/$1/cpufreq + dirpath=$CPU_PATH/$1/cpufreq shift 1
for i in $@; do - check_file $i $dirpath || return 1 + check_file $i $dirpath || return 1 done
return 0 }
check_sched_mc_files() { - - local dirpath=$CPU_PATH - for i in $@; do - check_file $i $dirpath || return 1 + check_file $i $CPU_PATH || return 1 done
return 0 }
check_topology_files() { - - local dirpath=$CPU_PATH/$1/topology + dirpath=$CPU_PATH/$1/topology shift 1
for i in $@; do - check_file $i $dirpath || return 1 + check_file $i $dirpath || return 1 done
return 0 }
check_cpuhotplug_files() { - - local dirpath=$CPU_PATH/$1 + dirpath=$CPU_PATH/$1 shift 1
for i in $@; do - if [ `echo $dirpath | grep -c "cpu0"` -eq 1 ]; then - if [ $hotplug_allow_cpu0 -eq 0 ]; then - continue - fi - fi + if [ `echo $dirpath | grep -c "cpu0"` -eq 1 ]; then + if [ $hotplug_allow_cpu0 -eq 0 ]; then + continue + fi + fi
- check_file $i $dirpath || return 1 + check_file $i $dirpath || return 1 done
return 0 }
save_governors() { - - governors_backup= - local index=0 + gov_array_name="governors_backup" + index=0
for cpu in $cpus; do - governors_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_governor) - index=$((index + 1)) + scaling_gov=$(cat $CPU_PATH/$cpu/cpufreq/scaling_governor) + eval $gov_array_name$index=$scaling_gov + eval export $gov_array_name$index + index=$((index + 1)) done }
restore_governors() { - - local index=0 - local oldgov= + 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_name$index) + echo $oldgov > $CPU_PATH/$cpu/cpufreq/scaling_governor + index=$((index + 1)) done }
save_frequencies() { - - frequencies_backup= - local index=0 + freq_array_name="frequencies_backup" + index=0
for cpu in $cpus; do - frequencies_backup[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq) - index=$((index + 1)) + freq=$(cat $CPU_PATH/$cpu/cpufreq/scaling_cur_freq) + eval $freq_array_name$index=$freq + eval export $freq_array_name$index + index=$((index + 1)) done }
restore_frequencies() { - - local index=0 - local oldfreq= + index=0
for cpu in $cpus; do - oldfreq=${frequencies_backup[$index]} - echo $oldfreq > $CPU_PATH/$cpu/cpufreq/scaling_setspeed - index=$((index + 1)) + oldfreq=$(eval echo $$freq_array_name$index) + echo $oldfreq > $CPU_PATH/$cpu/cpufreq/scaling_setspeed + index=$((index + 1)) done }
@@ -421,11 +403,11 @@ is_root() { }
is_cpu0_hotplug_allowed() { - local status=$1 + status=$1
if [ $status -eq 1 ]; then - return 0 + return 0 else - return 1 + return 1 fi } diff --git a/include/suspend_functions.sh b/include/suspend_functions.sh index 3be29f5..d5c8e2b 100644 --- a/include/suspend_functions.sh +++ b/include/suspend_functions.sh @@ -113,6 +113,7 @@ suspend_system () # Wait on the machine coming back up -- pulling the dmesg over. echo "v---" >>"$LOGFILE" retry=30 + while [ "$retry" -gt 0 ]; do let "retry=$retry-1"
@@ -131,6 +132,7 @@ suspend_system () fi sleep 1 done + echo "^---" >>"$LOGFILE" rm -f "$LOGFILE.dmesg"* if [ "$retry" -eq 0 ]; then @@ -242,6 +244,7 @@ ac_check() ECHO "*** WARNING: AC power not in expected state" \ "($ac_becomes) after test" fi + ac_is="$ac_becomes" }
@@ -293,4 +296,3 @@ if [ "$pm_trace" -eq 1 ]; then else disable_trace fi - diff --git a/include/thermal_functions.sh b/include/thermal_functions.sh index bfc6620..b66aeef 100644 --- a/include/thermal_functions.sh +++ b/include/thermal_functions.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # PM-QA validation test suite for the power management on Linux # @@ -26,20 +26,22 @@ THERMAL_PATH="/sys/devices/virtual/thermal" MAX_ZONE=0-12 MAX_CDEV=0-50 -ALL_ZONE= -ALL_CDEV= +thermal_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") +scale_freq_array="scale_freq" +mode_list_array="mode_list" +thermal_gov_array="thermal_gov_backup"
check_valid_temp() { - local file=$1 - local zone_name=$2 - local dir=$THERMAL_PATH/$2 + file=$1 + zone_name=$2 + dir=$THERMAL_PATH/$2
- local temp_file=$dir/$1 - local func=cat + temp_file=$dir/$1 + func=cat shift 2;
- local temp_val=$($func $temp_file) - local descr="'$zone_name'/'$file' ='$temp_val'" + temp_val=$($func $temp_file) + descr="'$zone_name'/'$file' ='$temp_val'" log_begin "checking $descr"
if [ $temp_val -gt 0 ]; then @@ -53,74 +55,72 @@ check_valid_temp() { }
for_each_thermal_zone() { - - local func=$1 + thermal_zone_func=$1 shift 1
- zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']") - - ALL_ZONE=$zone - for zone in $zones; do - INC=0 - $func $zone $@ + for zone in $thermal_zones; do + INC=0 + $thermal_zone_func $zone $@ done
return 0 }
get_total_trip_point_of_zone() { - - local zone_path=$THERMAL_PATH/$1 - local count=0 + zone_path=$THERMAL_PATH/$1 + count=0 shift 1 + trips=$(ls $zone_path | grep "trip_point_['$MAX_ZONE']_temp") for trip in $trips; do - count=$((count + 1)) + count=$((count + 1)) done + return $count }
for_each_trip_point_of_zone() { - - local zone_path=$THERMAL_PATH/$1 - local count=0 - local func=$2 - local zone_name=$1 + zone_path=$THERMAL_PATH/$1 + count=0 + trip_pt_func=$2 + zone_name=$1 shift 2 + trips=$(ls $zone_path | grep "trip_point_['$MAX_ZONE']_temp") for trip in $trips; do - $func $zone_name $count - count=$((count + 1)) + $trip_pt_func $zone_name $count + count=$((count + 1)) done + return 0 }
for_each_binding_of_zone() { - - local zone_path=$THERMAL_PATH/$1 - local count=0 - local func=$2 - local zone_name=$1 + zone_path=$THERMAL_PATH/$1 + count=0 + binding_zone_func=$2 + zone_name=$1 shift 2 + trips=$(ls $zone_path | grep "cdev['$MAX_CDEV']_trip_point") for trip in $trips; do - $func $zone_name $count - count=$((count + 1)) + $binding_zone_func $zone_name $count + count=$((count + 1)) done
return 0 - }
check_valid_binding() { - local trip_point=$1 - local zone_name=$2 - local dirpath=$THERMAL_PATH/$2 - local temp_file=$2/$1 - local trip_point_val=$(cat $dirpath/$trip_point) + trip_point=$1 + zone_name=$2 + dirpath=$THERMAL_PATH/$2 + temp_file=$2/$1 + trip_point_val=$(cat $dirpath/$trip_point) + get_total_trip_point_of_zone $zone_name - local trip_point_max=$? - local descr="'$temp_file' valid binding" + trip_point_max=$? + descr="'$temp_file' valid binding" shift 2
log_begin "checking $descr" @@ -134,10 +134,10 @@ check_valid_binding() { }
validate_trip_bindings() { - local zone_name=$1 - local bind_no=$2 - local dirpath=$THERMAL_PATH/$1 - local trip_point=cdev$2_trip_point + zone_name=$1 + bind_no=$2 + dirpath=$THERMAL_PATH/$1 + trip_point=cdev$2_trip_point shift 2
check_file $trip_point $dirpath || return 1 @@ -145,11 +145,11 @@ validate_trip_bindings() { }
validate_trip_level() { - local zone_name=$1 - local trip_no=$2 - local dirpath=$THERMAL_PATH/$1 - local trip_temp=trip_point_$2_temp - local trip_type=trip_point_$2_type + zone_name=$1 + trip_no=$2 + dirpath=$THERMAL_PATH/$1 + trip_temp=trip_point_$2_temp + trip_type=trip_point_$2_type shift 2
check_file $trip_temp $dirpath || return 1 @@ -158,88 +158,97 @@ validate_trip_level() { }
for_each_cooling_device() { - - local func=$1 + cooling_device_func=$1 shift 1
- devices=$(ls $THERMAL_PATH | grep "cooling_device['$MAX_CDEV']") - if [ "$devices" == "" ]; then - log_skip "no cooling devices" - return 0 + cooling_devices=$(ls $THERMAL_PATH | grep "cooling_device['$MAX_CDEV']") + if [ "$cooling_devices" = "" ]; then + log_skip "no cooling devices" + return 0 fi
- ALL_DEVICE=$devices - for device in $devices; do - INC=0 - $func $device $@ + for device in $cooling_devices; do + INC=0 + $cooling_device_func $device $@ done
return 0 } -check_scaling_freq() {
- local before_freq_list=$1 - local after_freq_list=$2 +# double check the values of this function +check_scaling_freq() { + before_freq_list=$1 + after_freq_list=$2 shift 2 - local index=0 + index=0
- local flag=0 + flag=0 for cpu in $cpus; do - if [ ${before_freq_list[$index]} -ne ${after_freq_list[$index]} ] ; then - flag=1 - fi + eval export $before_freq_list$index + eval export $after_freq_list$index + + bfreq=$(eval echo $$before_freq_list$index) + afreq=$(eval echo $$after_freq_list$index) + + if [ "$bfreq" -ne "$afreq" ]; then + flag=1 + fi + index=$((index + 1)) done + return $flag }
store_scaling_maxfreq() { - scale_freq= - local index=0 + index=0
for cpu in $cpus; do - scale_freq[$index]=$(cat $CPU_PATH/$cpu/cpufreq/scaling_max_freq) + scaling_max_freq=$(cat $CPU_PATH/$cpu/cpufreq/scaling_max_freq) + eval $scaling_freq_array$index=$scaling_max_freq + eval export $scaling_freq_array$index index=$((index + 1)) done + return 0 }
get_trip_id() { - - local trip_name=$1 + trip_name=$1 shift 1
- local id1=$(echo $trip_name|cut -c12) - local id2=$(echo $trip_name|cut -c13) + id1=$(echo $trip_name|cut -c12) + id2=$(echo $trip_name|cut -c13) if [ $id2 != "_" ]; then - id1=$(($id2 + 10*$id1)) + id1=$(($id2 + 10*$id1)) fi + return $id1 }
disable_all_thermal_zones() { + index=0
- mode_list= - local index=0 - - local 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 zone in $thermal_zones; do + mode=$(cat $THERMAL_PATH/$zone/mode) + eval $mode_list_array$index=$mode + eval export $mode_list_array$index index=$((index + 1)) - echo -n "disabled" > $THERMAL_PATH/$zone/mode + echo -n "disabled" > $THERMAL_PATH/$zone/mode done + return 0 }
enable_all_thermal_zones() { + index=0
- local index=0 - - local 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 zone in $thermal_zones; do + mode=$(eval echo $$mode_list_array$index) + echo $mode > $THERMAL_PATH/$zone/mode index=$((index + 1)) done + return 0 }
@@ -255,6 +264,7 @@ start_glmark2() { if [ -x $GPU_HEAT_BIN ]; then $GPU_HEAT_BIN & gpu_pid=$(pidof $GPU_HEAT_BIN) + # Starting X application from serial console needs this if [ -z "$gpu_pid" ]; then cp /etc/lightdm/lightdm.conf /etc/lightdm/lightdm.conf.bk @@ -266,6 +276,7 @@ start_glmark2() { $GPU_HEAT_BIN & gpu_pid=$(pidof $GPU_HEAT_BIN) fi + test -z "$gpu_pid" && cpu_pid=0 echo "start gpu heat binary $gpu_pid" else @@ -280,33 +291,33 @@ kill_glmark2() { fi
if [ "$gpu_pid" -ne 0 ]; then - kill -9 $gpu_pid + kill -9 $gpu_pid fi }
set_thermal_governors() { + gov=$1 + index=0
- local gov=$1 - local index=0 - thermal_governor_backup[MAX_ZONE]= - - local 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 zone in $thermal_zones; do + policy=$(cat $THERMAL_PATH/$zone/policy) + eval $thermal_gov_array$index=$policy + eval export $thermal_gov_array$index index=$((index + 1)) echo $gov > $THERMAL_PATH/$zone/policy done + return 0 }
restore_thermal_governors() { + index=0
- local index=0 - - local 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 zone in $thermal_zones; do + policy=$(eval echo $$thermal_gov_array$index) + echo $policy > $THERMAL_PATH/$zone/policy index=$((index + 1)) done + return 0 }