Remove bashism in thermal scripts and remove thermal_try_max
variable as it is not used anywhere else nor does its value
changes. Rename variables to something more meaningful and
improve format for readability.

Signed-off-by: Lisa Nguyen <lisa.ngu...@linaro.org>
---
 thermal/thermal_00.sh     |   22 ++++++-----
 thermal/thermal_01.sh     |   39 ++++++++-----------
 thermal/thermal_02.sh     |   36 +++++++++---------
 thermal/thermal_03.sh     |   18 ++++-----
 thermal/thermal_04.sh     |   37 +++++++++---------
 thermal/thermal_05.sh     |   30 +++++++--------
 thermal/thermal_06.sh     |   92 +++++++++++++++++++++++----------------------
 thermal/thermal_sanity.sh |    7 ++--
 8 files changed, 141 insertions(+), 140 deletions(-)

diff --git a/thermal/thermal_00.sh b/thermal/thermal_00.sh
index cdc5a10..9ed1be4 100755
--- a/thermal/thermal_00.sh
+++ b/thermal/thermal_00.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # PM-QA validation test suite for the power management on Linux
 #
@@ -25,24 +25,26 @@
 
 # URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Doc/QA/Scripts#thermal_00
 
-source ../include/functions.sh
-source ../include/thermal_functions.sh
+. ../include/functions.sh
+. ../include/thermal_functions.sh
 
 check_cooling_device_type() {
-    local all_zones=$(ls $THERMAL_PATH | grep "cooling_device['$MAX_CDEV']")
+    all_cdev_zones=$(ls $THERMAL_PATH | grep "cooling_device['$MAX_CDEV']")
+    
     echo "Cooling Device list:"
-    for i in $all_zones; do
-       local type=$(cat $THERMAL_PATH/$i/type)
-       echo "-    $type"
+    for i in $all_cdev_zones; do
+           cooling_type=$(cat $THERMAL_PATH/$i/type)
+           echo "-    $cooling_type"
     done
 }
 
 check_thermal_zone_type() {
-    local all_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']")
+    all_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']")
+    
     echo "Thermal Zone list:"
     for i in $all_zones; do
-       local type=$(cat $THERMAL_PATH/$i/type)
-       echo "-    $type"
+           type=$(cat $THERMAL_PATH/$i/type)
+           echo "-    $type"
     done
 }
 
diff --git a/thermal/thermal_01.sh b/thermal/thermal_01.sh
index dac26d1..dfda2f5 100755
--- a/thermal/thermal_01.sh
+++ b/thermal/thermal_01.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # PM-QA validation test suite for the power management on Linux
 #
@@ -22,38 +22,35 @@
 #     Amit Daniel <amit.kach...@linaro.org> (Samsung Electronics)
 #       - initial API and implementation
 #
-
 # URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#thermal_01
 
-source ../include/functions.sh
-source ../include/thermal_functions.sh
+. ../include/functions.sh
+. ../include/thermal_functions.sh
 
 ATTRIBUTES="mode temp type uevent"
 
 check_thermal_zone_attributes() {
-
-    local dirpath=$THERMAL_PATH/$1
-    local zone_name=$1
+    dirpath=$THERMAL_PATH/$1
+    zone_name=$1
     shift 1
     for i in $ATTRIBUTES; do
-       check_file $i $dirpath || return 1
+           check_file $i $dirpath || return 1
     done
 
     check_valid_temp "temp" $zone_name || return 1
 }
 
 check_thermal_zone_mode() {
-
-    local dirpath=$THERMAL_PATH/$1
-    local zone_name=$1
+    dirpath=$THERMAL_PATH/$1
+    zone_name=$1
     shift 1
-    local prev_mode=$(cat $dirpath/mode)
+    prev_mode=$(cat $dirpath/mode)
     echo -n enabled > $dirpath/mode
-    local cur_mode=$(cat $dirpath/mode)
+    cur_mode=$(cat $dirpath/mode)
     check "$zone_name cur_mode=$cur_mode"\
                         "test $cur_mode = enabled" || return 1
     echo -n disabled > $dirpath/mode
-    local cur_mode=$(cat $dirpath/mode)
+    cur_mode=$(cat $dirpath/mode)
     check "$zone_name cur_mode=$cur_mode"\
                        "test $cur_mode = disabled" || return 1
 
@@ -61,26 +58,22 @@ check_thermal_zone_mode() {
 }
 
 check_thermal_zone_trip_level() {
-
-    local all_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']")
+    all_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']")
+    
     for i in $all_zones; do
-       for_each_trip_point_of_zone $i "validate_trip_level" || return 1
+           for_each_trip_point_of_zone $i "validate_trip_level" || return 1
     done
 }
 
 check_thermal_zone_bindings() {
-
-    local all_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']")
+    all_zones=$(ls $THERMAL_PATH | grep "thermal_zone['$MAX_ZONE']")
     for i in $all_zones; do
-       for_each_binding_of_zone $i "validate_trip_bindings" || return 1
+           for_each_binding_of_zone $i "validate_trip_bindings" || return 1
     done
 }
 
 for_each_thermal_zone check_thermal_zone_attributes
-
 for_each_thermal_zone check_thermal_zone_mode
-
 check_thermal_zone_trip_level
-
 check_thermal_zone_bindings
 test_status_show
diff --git a/thermal/thermal_02.sh b/thermal/thermal_02.sh
index 1f53612..ef5b86c 100755
--- a/thermal/thermal_02.sh
+++ b/thermal/thermal_02.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # PM-QA validation test suite for the power management on Linux
 #
@@ -25,38 +25,40 @@
 
 # URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#thermal_02
 
-source ../include/functions.sh
-source ../include/thermal_functions.sh
+. ../include/functions.sh
+. ../include/thermal_functions.sh
 
 CDEV_ATTRIBUTES="cur_state max_state type uevent"
 
 check_cooling_device_attributes() {
 
-    local dirpath=$THERMAL_PATH/$1
-    local cdev_name=$1
+    dirpath=$THERMAL_PATH/$1
+    cdev_name=$1
     shift 1
 
     for i in $CDEV_ATTRIBUTES; do
-       check_file $i $dirpath || return 1
+           check_file $i $dirpath || return 1
     done
 
 }
 
 check_cooling_device_states() {
-    local dirpath=$THERMAL_PATH/$1
-    local cdev_name=$1
+    dirpath=$THERMAL_PATH/$1
+    cdev_name=$1
     shift 1
-    local max_state=$(cat $dirpath/max_state)
-    local prev_state_val=$(cat $dirpath/cur_state)
-    local count=0
-    local cur_state_val=0
+    max_state=$(cat $dirpath/max_state)
+    prev_state_val=$(cat $dirpath/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"\
-                               "test $cur_state_val -eq $count" || return 1
-       count=$((count+1))
+           echo $count > $dirpath/cur_state
+           cur_state_val=$(cat $dirpath/cur_state)
+           check "$cdev_name cur_state=$count"\
+                                   "test $cur_state_val -eq $count" || return 1
+           count=$((count+1))
     done
+
     echo $prev_state_val > $dirpath/cur_state
 }
 
diff --git a/thermal/thermal_03.sh b/thermal/thermal_03.sh
index cf53a1a..2b3f9d7 100755
--- a/thermal/thermal_03.sh
+++ b/thermal/thermal_03.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # PM-QA validation test suite for the power management on Linux
 #
@@ -25,25 +25,25 @@
 
 # URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#thermal_03
 
-source ../include/functions.sh
-source ../include/thermal_functions.sh
+. ../include/functions.sh
+. ../include/thermal_functions.sh
 
 CPU_HEAT_BIN=../utils/heat_cpu
 cpu_pid=0
 
 heater_kill() {
     if [ $cpu_pid -ne 0 ]; then
-       kill -9 $cpu_pid
+       kill -9 $cpu_pid
     fi
     kill_glmark2
 }
 
 check_temperature_change() {
-    local dirpath=$THERMAL_PATH/$1
-    local zone_name=$1
+    dirpath=$THERMAL_PATH/$1
+    zone_name=$1
     shift 1
 
-    local init_temp=$(cat $dirpath/temp)
+    init_temp=$(cat $dirpath/temp)
     $CPU_HEAT_BIN &
     cpu_pid=$(ps | grep heat_cpu| awk '{print $1}')
     test -z $cpu_pid && cpu_pid=0
@@ -53,12 +53,12 @@ check_temperature_change() {
     start_glmark2
 
     sleep 5
-    local final_temp=$(cat $dirpath/temp)
+    final_temp=$(cat $dirpath/temp)
     heater_kill
     check "temperature variation with load" "test $final_temp -gt $init_temp"
 }
 
-trap "heater_kill; sigtrap" SIGHUP SIGINT SIGTERM
+trap "heater_kill; sigtrap" HUP INT TERM
 
 for_each_thermal_zone check_temperature_change
 test_status_show
diff --git a/thermal/thermal_04.sh b/thermal/thermal_04.sh
index 8bf3799..def1740 100755
--- a/thermal/thermal_04.sh
+++ b/thermal/thermal_04.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # PM-QA validation test suite for the power management on Linux
 #
@@ -25,8 +25,8 @@
 
 # URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#thermal_04
 
-source ../include/functions.sh
-source ../include/thermal_functions.sh
+. ../include/functions.sh
+. ../include/thermal_functions.sh
 HEAT_CPU_MODERATE=../utils/heat_cpu
 pid=0
 
@@ -37,30 +37,31 @@ heater_kill() {
 }
 
 verify_cooling_device_temp_change() {
-    local dirpath=$THERMAL_PATH/$1
-    local cdev_name=$1
+    dirpath=$THERMAL_PATH/$1
+    dev_name=$1
     shift 1
-    local tzonepath=$THERMAL_PATH/thermal_zone0
+    tzonepath=$THERMAL_PATH/thermal_zone0
     test -d $tzonepath
+    
     if [ $? -ne 0 ] ; then
-       echo "No thermal zone present"
-       return 1;
+           echo "No thermal zone present"
+           return 1
     fi
-    local max_state=$(cat $dirpath/max_state)
-    local prev_state_val=$(cat $dirpath/cur_state)
+    max_state=$(cat $dirpath/max_state)
+    prev_state_val=$(cat $dirpath/cur_state)
 
-    local count=1
-    local cur_state_val=0
-    local init_temp=0
-    local final_temp=0
-    local cool_temp=0
+    count=1
+    cur_state_val=0
+    init_temp=0
+    final_temp=0
+    cool_temp=0
     ./$HEAT_CPU_MODERATE moderate &
     pid=$!
     test $pid -eq 0 && return
 
     while (test $count -le $max_state); do
-       echo 0 > $dirpath/cur_state
-       sleep 5
+           echo 0 > $dirpath/cur_state
+           sleep 5
        init_temp=$(cat $tzonepath/temp)
 
        echo $count > $dirpath/cur_state
@@ -75,7 +76,7 @@ verify_cooling_device_temp_change() {
     echo $prev_state_val > $dirpath/cur_state
 }
 
-trap "heater_kill; sigtrap" SIGHUP SIGINT SIGTERM
+trap "heater_kill; sigtrap" HUP INT TERM
 
 set_thermal_governors user_space
 
diff --git a/thermal/thermal_05.sh b/thermal/thermal_05.sh
index 52a0ac2..828a75e 100755
--- a/thermal/thermal_05.sh
+++ b/thermal/thermal_05.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # PM-QA validation test suite for the power management on Linux
 #
@@ -25,42 +25,42 @@
 
 # URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#thermal_05
 
-source ../include/functions.sh
-source ../include/thermal_functions.sh
+. ../include/functions.sh
+. ../include/thermal_functions.sh
 
 verify_cpufreq_cooling_device_action() {
-    local dirpath=$THERMAL_PATH/$1
-    local cdev_name=$1
+    dirpath=$THERMAL_PATH/$1
+    cdev_name=$1
     shift 1
 
-    local cpufreq_cdev=$(cat $dirpath/type)
+    cpufreq_cdev=$(cat $dirpath/type)
     cat $dirpath/type | grep cpufreq
     if [ $? -ne 0  ] ; then
         log_skip "Cannot find cpufreq in $cdev_name..."
            return 0
     fi
 
-    local max_state=$(cat $dirpath/max_state)
-    local prev_state_val=$(cat $dirpath/cur_state)
+    max_state=$(cat $dirpath/max_state)
+    prev_state_val=$(cat $dirpath/cur_state)
     disable_all_thermal_zones
 
-    local count=1
-    local before_scale_max=0
-    local after_scale_max=0
-    local change=0
+    count=1
+    before_scale_max=0
+    after_scale_max=0
+    change=0
 
     while (test $count -le $max_state); do
-       echo 0 > $dirpath/cur_state
+           echo 0 > $dirpath/cur_state
        sleep 1
 
        store_scaling_maxfreq
-       before_scale_max=$scale_freq
+       before_scale_max=$scale_freq_array
 
        echo $count > $dirpath/cur_state
        sleep 1
 
        store_scaling_maxfreq
-       after_scale_max=$scale_freq
+       after_scale_max=$scale_freq_array
 
        check_scaling_freq $before_scale_max $after_scale_max
        change=$?
diff --git a/thermal/thermal_06.sh b/thermal/thermal_06.sh
index d8877f0..1d6943c 100755
--- a/thermal/thermal_06.sh
+++ b/thermal/thermal_06.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # PM-QA validation test suite for the power management on Linux
 #
@@ -25,37 +25,33 @@
 
 # URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#thermal_06
 
-source ../include/functions.sh
-source ../include/thermal_functions.sh
-
-if [ "$thermal_try_max" -eq 0 ]; then
-    log_skip "test of trip points being crossed"
-    return 0
-fi
+. ../include/functions.sh
+. ../include/thermal_functions.sh
 
 TEST_LOOP=100
 CPU_HEAT_BIN=../utils/heat_cpu
 cpu_pid=0
+trip_point_array_name="trip_point_list"
 
 heater_kill() {
     if [ $cpu_pid -ne 0 ]; then
-       kill -9 $cpu_pid
+        kill -9 $cpu_pid
     fi
     kill_glmark2
 }
 
 check_trip_point_change() {
-    local dirpath=$THERMAL_PATH/$1
-    local zone_name=$1
+    dirpath=$THERMAL_PATH/$1
+    zone_name=$1
     shift 1
 
-    local count=0
-    local cur_temp=0
-    local trip_temp=0
-    local trip_cross=
-    local trip_id=
-    local trip_type=0
-    local trip_type_path=0
+    count=0
+    cur_temp=0
+    trip_temp=0
+    trip_cross=
+    trip_id=
+    trip_type=0
+    trip_type_path=0
     $CPU_HEAT_BIN &
     cpu_pid=$(ps | grep heat_cpu| awk '{print $1}')
     test -z $cpu_pid && cpu_pid=0
@@ -64,43 +60,51 @@ check_trip_point_change() {
 
     start_glmark2
 
-    local index=0
-    for trip in $(ls $dirpath | grep "trip_point_['$MAX_ZONE']_temp"); do
-       trip_cross[$index]=0
-       index=$((index + 1))
+    index=0
+
+    for trip in $(ls $dirpath/thermal_zone0 | grep 
"trip_point_['$MAX_ZONE']_temp")
+    do
+        value=0
+        eval $trip_point_array_name$index=$value
+        eval export $trip_point_array_name$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))
+        index=0
+        sleep 1
 
-       done
-       count=$((count + 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
+                 value=$(eval echo \$$trip_point_array_name$index)
+                 eval $trip_point_array_name$index=$((value + 1))
+            fi
+            index=$((index + 1))
+        done
+
+        count=$((index + 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))
+           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=$(eval echo \$$trip_point_array_name$index)
+               check "$trip:$trip_temp crossed" "test $count -gt 0"
+           fi
+           index=$((index + 1))
     done
 
     heater_kill
 }
 
-trap "heater_kill; sigtrap" SIGHUP SIGINT SIGTERM
+trap "heater_kill; sigtrap" HUP INT TERM
 
 for_each_thermal_zone check_trip_point_change
 test_status_show
diff --git a/thermal/thermal_sanity.sh b/thermal/thermal_sanity.sh
index c9149c0..4b76c88 100755
--- a/thermal/thermal_sanity.sh
+++ b/thermal/thermal_sanity.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # PM-QA validation test suite for the power management on Linux
 #
@@ -23,8 +23,8 @@
 #       - initial API and implementation
 #
 
-source ../include/functions.sh
-source ../include/thermal_functions.sh
+. ../include/functions.sh
+. ../include/thermal_functions.sh
 
 is_root
 if [ $? -ne 0 ]; then
@@ -33,7 +33,6 @@ if [ $? -ne 0 ]; then
 fi
 
 check_thermal_zone() {
-
     test -d $THERMAL_PATH
     if [ $? -ne 0 ]; then
         echo "thermal zone is not available. Skipping all tests"
-- 
1.7.9.5


_______________________________________________
linaro-dev mailing list
linaro-dev@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/linaro-dev

Reply via email to