diff mbox

[kvm-unit-tests,v2,1/6] run_tests.sh: share run_all as for_each_unittest

Message ID 1436806983-29783-2-git-send-email-drjones@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andrew Jones July 13, 2015, 5:02 p.m. UTC
To avoid duplicating unittests.cfg parsing code in other scripts,
let's put it in a file where it can be shared.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 run_tests.sh           | 46 ++--------------------------------------------
 scripts/functions.bash | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 44 deletions(-)
 create mode 100644 scripts/functions.bash
diff mbox

Patch

diff --git a/run_tests.sh b/run_tests.sh
index e48f1db049f81..ebb7e9fe6fdfc 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -5,6 +5,7 @@  if [ ! -f config.mak ]; then
     exit
 fi
 source config.mak
+source scripts/functions.bash
 
 config=$TEST_DIR/unittests.cfg
 qemu=${QEMU:-qemu-system-$ARCH}
@@ -61,49 +62,6 @@  function run()
     fi
 }
 
-function run_all()
-{
-    local config="$1"
-    local testname
-    local smp
-    local kernel
-    local opts
-    local groups
-    local arch
-    local check
-
-    exec {config_fd}<$config
-
-    while read -u $config_fd line; do
-        if [[ "$line" =~ ^\[(.*)\]$ ]]; then
-            run "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check"
-            testname=${BASH_REMATCH[1]}
-            smp=1
-            kernel=""
-            opts=""
-            groups=""
-            arch=""
-            check=""
-        elif [[ $line =~ ^file\ *=\ *(.*)$ ]]; then
-            kernel=$TEST_DIR/${BASH_REMATCH[1]}
-        elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
-            smp=${BASH_REMATCH[1]}
-        elif [[ $line =~ ^extra_params\ *=\ *(.*)$ ]]; then
-            opts=${BASH_REMATCH[1]}
-        elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
-            groups=${BASH_REMATCH[1]}
-        elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then
-            arch=${BASH_REMATCH[1]}
-        elif [[ $line =~ ^check\ *=\ *(.*)$ ]]; then
-            check=${BASH_REMATCH[1]}
-        fi
-    done
-
-    run "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check"
-
-    exec {config_fd}<&-
-}
-
 function usage()
 {
 cat <<EOF
@@ -139,4 +97,4 @@  while getopts "g:hv" opt; do
     esac
 done
 
-run_all $config
+for_each_unittest $config run
diff --git a/scripts/functions.bash b/scripts/functions.bash
new file mode 100644
index 0000000000000..7ed5a517250bc
--- /dev/null
+++ b/scripts/functions.bash
@@ -0,0 +1,42 @@ 
+
+function for_each_unittest()
+{
+	local unittests="$1"
+	local cmd="$2"
+	local testname
+	local smp
+	local kernel
+	local opts
+	local groups
+	local arch
+	local check
+
+	exec {fd}<"$unittests"
+
+	while read -u $fd line; do
+		if [[ "$line" =~ ^\[(.*)\]$ ]]; then
+			"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check"
+			testname=${BASH_REMATCH[1]}
+			smp=1
+			kernel=""
+			opts=""
+			groups=""
+			arch=""
+			check=""
+		elif [[ $line =~ ^file\ *=\ *(.*)$ ]]; then
+			kernel=$TEST_DIR/${BASH_REMATCH[1]}
+		elif [[ $line =~ ^smp\ *=\ *(.*)$ ]]; then
+			smp=${BASH_REMATCH[1]}
+		elif [[ $line =~ ^extra_params\ *=\ *(.*)$ ]]; then
+			opts=${BASH_REMATCH[1]}
+		elif [[ $line =~ ^groups\ *=\ *(.*)$ ]]; then
+			groups=${BASH_REMATCH[1]}
+		elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then
+			arch=${BASH_REMATCH[1]}
+		elif [[ $line =~ ^check\ *=\ *(.*)$ ]]; then
+			check=${BASH_REMATCH[1]}
+		fi
+	done
+	"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check"
+	exec {fd}<&-
+}