Remove bashism in cpuhotplug scripts. $RANDOM is an internal BASH
function, so remove it to follow POSIX standards.

Signed-off-by: Lisa Nguyen <lisa.ngu...@linaro.org>
---
 cpuhotplug/1_sanity_check.sh    |    7 +++----
 cpuhotplug/cpuhotplug_01.sh     |    5 ++---
 cpuhotplug/cpuhotplug_02.sh     |   21 ++++++++++-----------
 cpuhotplug/cpuhotplug_03.sh     |   15 +++++++--------
 cpuhotplug/cpuhotplug_04.sh     |   21 ++++++++++-----------
 cpuhotplug/cpuhotplug_05.sh     |   13 ++++++-------
 cpuhotplug/cpuhotplug_06.sh     |   16 +++++++---------
 cpuhotplug/cpuhotplug_07.sh     |   17 ++++++++---------
 cpuhotplug/cpuhotplug_08.sh     |   23 ++++++++++++-----------
 cpuhotplug/cpuhotplug_sanity.sh |    5 ++---
 cpuhotplug/z_sanity_check.sh    |    7 +++----
 11 files changed, 70 insertions(+), 80 deletions(-)

diff --git a/cpuhotplug/1_sanity_check.sh b/cpuhotplug/1_sanity_check.sh
index e091879..d4bc02a 100755
--- a/cpuhotplug/1_sanity_check.sh
+++ b/cpuhotplug/1_sanity_check.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # PM-QA validation test suite for the power management on Linux
 #
@@ -22,13 +22,12 @@
 #     Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation)
 #       - initial API and implementation
 #
-
 # URL :
 
-source ../include/functions.sh
+. ../include/functions.sh
 
 sanity_check() {
-       local ret=$(cat $CPU_PATH/offline)
+       ret=$(cat $CPU_PATH/offline)
        if [ -z "$ret" ]; then
                return 0
        else
diff --git a/cpuhotplug/cpuhotplug_01.sh b/cpuhotplug/cpuhotplug_01.sh
index 8804df7..8591a21 100755
--- a/cpuhotplug/cpuhotplug_01.sh
+++ b/cpuhotplug/cpuhotplug_01.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#cpuhotplug_01
 
-source ../include/functions.sh
+. ../include/functions.sh
 
 FILES="online offline possible present"
 
diff --git a/cpuhotplug/cpuhotplug_02.sh b/cpuhotplug/cpuhotplug_02.sh
index d2bb5b4..e304484 100755
--- a/cpuhotplug/cpuhotplug_02.sh
+++ b/cpuhotplug/cpuhotplug_02.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # PM-QA validation test suite for the power management on Linux
 #
@@ -22,19 +22,18 @@
 #     Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation)
 #       - initial API and implementation
 #
-
 # URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpuhotplug_02
 
-source ../include/functions.sh
+. ../include/functions.sh
 
 check_state() {
-    local cpu=$1
-    local dirpath=$CPU_PATH/$1
-    local state=
+    cpu=$1
+    dirpath=$CPU_PATH/$1
+    state=
     shift 1
 
-    if [ "$cpu" == "cpu0" ]; then
-       is_cpu0_hotplug_allowed $hotplug_allow_cpu0 || return 0
+    if [ "$cpu" = "cpu0" ]; then
+           is_cpu0_hotplug_allowed $hotplug_allow_cpu0 || return 0
     fi
 
     set_offline $cpu
@@ -42,8 +41,8 @@ check_state() {
 
     check "cpu is offline" "test $state -eq 0"
     if [ $? -ne 0 ]; then
-       set_online $cpu
-       return 1
+           set_online $cpu
+           return 1
     fi
 
     set_online $cpu
@@ -51,7 +50,7 @@ check_state() {
 
     check "cpu is online" "test $state -eq 1"
     if [ $? -ne 0 ]; then
-       return 1
+           return 1
     fi
 
     return 0
diff --git a/cpuhotplug/cpuhotplug_03.sh b/cpuhotplug/cpuhotplug_03.sh
index 2a5ae48..176269e 100755
--- a/cpuhotplug/cpuhotplug_03.sh
+++ b/cpuhotplug/cpuhotplug_03.sh
@@ -25,16 +25,15 @@
 
 # URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpuhotplug_03
 
-source ../include/functions.sh
+. ../include/functions.sh
 
 check_affinity_fails() {
-    local cpu=$1
-    local cpuid=${cpu:3}
-    local dirpath=$CPU_PATH/$1
-    local ret=
-
-    if [ "$cpu" == "cpu0" ]; then
-       is_cpu0_hotplug_allowed $hotplug_allow_cpu0 || return 0
+    cpu=$1
+    cpuid=$(echo $cpu | awk '{print substr($0,4)}')
+    dirpath=$CPU_PATH/$1
+    
+    if [ "$cpu" = "cpu0" ]; then
+       is_cpu0_hotplug_allowed $hotplug_allow_cpu0 || return 0
     fi
 
     set_offline $cpu
diff --git a/cpuhotplug/cpuhotplug_04.sh b/cpuhotplug/cpuhotplug_04.sh
index 7938e7d..570e097 100755
--- a/cpuhotplug/cpuhotplug_04.sh
+++ b/cpuhotplug/cpuhotplug_04.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # PM-QA validation test suite for the power management on Linux
 #
@@ -22,22 +22,21 @@
 #     Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation)
 #       - initial API and implementation
 #
-
 # URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpuhotplug_04
 
 CPUBURN=../utils/cpuburn
-source ../include/functions.sh
+. ../include/functions.sh
 
 check_task_migrate() {
-    local cpu=$1
-    local cpuid=${cpu:3}
-    local cpumask=$((1 << cpuid))
-    local dirpath=$CPU_PATH/$1
-    local pid=
-    local ret=
+    cpu=$1
+    cpuid=$(echo $cpu | awk '{print substr($0,4)}')
+    cpumask=$((1 << cpuid))
+    dirpath=$CPU_PATH/$1
+    pid=
+    ret=
 
-    if [ "$cpu" == "cpu0" ]; then
-       is_cpu0_hotplug_allowed $hotplug_allow_cpu0 || return 0
+    if [ "$cpu" = "cpu0" ]; then
+           is_cpu0_hotplug_allowed $hotplug_allow_cpu0 || return 0
     fi
 
     taskset 0x$cpumask $CPUBURN $cpu &
diff --git a/cpuhotplug/cpuhotplug_05.sh b/cpuhotplug/cpuhotplug_05.sh
index 4042f2c..53bc48e 100755
--- a/cpuhotplug/cpuhotplug_05.sh
+++ b/cpuhotplug/cpuhotplug_05.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # PM-QA validation test suite for the power management on Linux
 #
@@ -25,15 +25,14 @@
 
 # URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpuhotplug_05
 
-source ../include/functions.sh
+. ../include/functions.sh
 
 check_procinfo() {
-    local cpu=$1
-    local cpuid=${cpu:3}
-    local ret=
+    cpu=$1
+    cpuid=$(echo $cpu | awk '{print substr($0,4)}')
 
-    if [ "$cpu" == "cpu0" ]; then
-       is_cpu0_hotplug_allowed $hotplug_allow_cpu0 || return 0
+    if [ "$cpu" = "cpu0" ]; then
+           is_cpu0_hotplug_allowed $hotplug_allow_cpu0 || return 0
     fi
 
     set_offline $cpu
diff --git a/cpuhotplug/cpuhotplug_06.sh b/cpuhotplug/cpuhotplug_06.sh
index 0461e37..29870c2 100755
--- a/cpuhotplug/cpuhotplug_06.sh
+++ b/cpuhotplug/cpuhotplug_06.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # PM-QA validation test suite for the power management on Linux
 #
@@ -22,18 +22,16 @@
 #     Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation)
 #       - initial API and implementation
 #
-
 # URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpuhotplug_06
 
-source ../include/functions.sh
+. ../include/functions.sh
 
 check_procinfo() {
-    local cpu=$1
-    local cpuid=${cpu:3}
-    local ret=
-
-    if [ "$cpu" == "cpu0" ]; then
-       is_cpu0_hotplug_allowed $hotplug_allow_cpu0 || return 0
+    cpu=$1
+    cpuid=$(echo $cpu | awk '{print substr($0,4)}')
+    
+    if [ "$cpu" = "cpu0" ]; then
+           is_cpu0_hotplug_allowed $hotplug_allow_cpu0 || return 0
     fi
 
     set_offline $cpu
diff --git a/cpuhotplug/cpuhotplug_07.sh b/cpuhotplug/cpuhotplug_07.sh
index a3526be..3668871 100755
--- a/cpuhotplug/cpuhotplug_07.sh
+++ b/cpuhotplug/cpuhotplug_07.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # PM-QA validation test suite for the power management on Linux
 #
@@ -22,20 +22,19 @@
 #     Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation)
 #       - initial API and implementation
 #
-
 # URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpuhotplug_07
 
-source ../include/functions.sh
+. ../include/functions.sh
 TMPFILE=cpuhotplug_07.tmp
 
 check_notification() {
-    local cpu=$1
-    local cpuid=${cpu:3}
-    local pid=
-    local ret=
+    cpu=$1
+    cpuid=$(echo $cpu | awk '{print substr($0,4)}')
+    pid=
+    ret=
 
-    if [ "$cpu" == "cpu0" ]; then
-       is_cpu0_hotplug_allowed $hotplug_allow_cpu0 || return 0
+    if [ "$cpu" = "cpu0" ]; then
+           is_cpu0_hotplug_allowed $hotplug_allow_cpu0 || return 0
     fi
 
     # damn ! udevadm is buffering the output, we have to use a temp file
diff --git a/cpuhotplug/cpuhotplug_08.sh b/cpuhotplug/cpuhotplug_08.sh
index c6ef477..71164d6 100755
--- a/cpuhotplug/cpuhotplug_08.sh
+++ b/cpuhotplug/cpuhotplug_08.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # PM-QA validation test suite for the power management on Linux
 #
@@ -22,23 +22,24 @@
 #     Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation)
 #       - initial API and implementation
 #
-
 # URL : 
https://wiki.linaro.org/WorkingGroups/PowerManagement/Resources/TestSuite/PmQaSpecification#cpuhotplug_08
 
-source ../include/functions.sh
+. ../include/functions.sh
+
+randomize() {
+    random=$(od -A n -N 2 -t u2 /dev/urandom)
+    number=$(echo $random % $1)
 
-function randomize() {
     if [ $hotplug_allow_cpu0 -eq 0 ]; then
-       echo $[ ( $RANDOM % $1 )  + 1 ]
-    else
-       echo $[ ( $RANDOM % $1 ) ]
+        number=$(($number + 1))
     fi
+
+    echo $number
 }
 
 random_stress() {
-    local cpu_present=$(cat /sys/devices/system/cpu/present | cut -d '-' -f 2)
-    local cpurand=$(randomize $cpu_present)
-    local ret=
+    cpu_present=$(cat /sys/devices/system/cpu/present | cut -d '-' -f 2)
+    cpurand=$(randomize $cpu_present)
 
     # randomize will in range "1-$cpu_present) so cpu0 is ignored
     set_offline cpu$cpurand
@@ -50,5 +51,5 @@ random_stress() {
     check "cpu$cpurand is online" "test $ret -eq 0"
 }
 
-for i in $(seq 1 100); do random_stress ; done
+for i in $(seq 1 100); do random_stress; done
 test_status_show
diff --git a/cpuhotplug/cpuhotplug_sanity.sh b/cpuhotplug/cpuhotplug_sanity.sh
index 9a9df25..aa1fb91 100755
--- a/cpuhotplug/cpuhotplug_sanity.sh
+++ b/cpuhotplug/cpuhotplug_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,7 +32,6 @@ if [ $? -ne 0 ]; then
 fi
 
 check_cpuhotplug_sysfs_entry() {
-
     cpunum=$(ls $CPU_PATH | grep "cpu[0-9].*" -c)
 
     if [ $cpunum -eq 1 ]; then
diff --git a/cpuhotplug/z_sanity_check.sh b/cpuhotplug/z_sanity_check.sh
index c39413e..98115a3 100755
--- a/cpuhotplug/z_sanity_check.sh
+++ b/cpuhotplug/z_sanity_check.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 #
 # PM-QA validation test suite for the power management on Linux
 #
@@ -22,13 +22,12 @@
 #     Daniel Lezcano <daniel.lezc...@linaro.org> (IBM Corporation)
 #       - initial API and implementation
 #
-
 # URL :
 
-source ../include/functions.sh
+. ../include/functions.sh
 
 sanity_check() {
-       local ret=$(cat $CPU_PATH/offline)
+       ret=$(cat $CPU_PATH/offline)
        if [ -z "$ret" ]; then
                return 0
        else
-- 
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