diff mbox

[kvm-unit-tests] scripts: add test runner filter

Message ID 20170420233234.119643-1-dmatlack@google.com (mailing list archive)
State New, archived
Headers show

Commit Message

David Matlack April 20, 2017, 11:32 p.m. UTC
From: Peter Feiner <pfeiner@google.com>

Add -t <name> option to run_tests.sh. Only test with the given name is
run. It's an error if there's no matching test.

Signed-off-by: Peter Feiner <pfeiner@google.com>
Signed-off-by: David Matlack <dmatlack@google.com>
---
 run_tests.sh        |  6 +++++-
 scripts/common.bash | 19 +++++++++++++++++--
 2 files changed, 22 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/run_tests.sh b/run_tests.sh
index c35a05802346..9c914a3678ca 100755
--- a/run_tests.sh
+++ b/run_tests.sh
@@ -16,6 +16,7 @@  cat <<EOF
 
 Usage: $0 [-h] [-v] [-a] [-g group] [-j NUM-TASKS]
 
+    -t: Only execute this test
     -h: Output this help text
     -v: Enables verbose mode
     -a: Run all tests, including those flagged as 'nodefault'
@@ -31,10 +32,13 @@  EOF
 RUNTIME_arch_run="./$TEST_DIR/run"
 source scripts/runtime.bash
 
-while getopts "ag:hj:v" opt; do
+while getopts "t:ag:hj:v" opt; do
     case $opt in
         a)
             run_all_tests="yes"
+	    ;;
+        t)
+            only_test=$OPTARG
             ;;
         g)
             only_group=$OPTARG
diff --git a/scripts/common.bash b/scripts/common.bash
index ee9143c5d630..3c4e2ecdd603 100644
--- a/scripts/common.bash
+++ b/scripts/common.bash
@@ -12,12 +12,16 @@  function for_each_unittest()
 	local check
 	local accel
 	local timeout
+	local found=0
 
 	exec {fd}<"$unittests"
 
 	while read -u $fd line; do
 		if [[ "$line" =~ ^\[(.*)\]$ ]]; then
-			"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout"
+			if [[ -z "$only_test" || "$testname" == "$only_test" ]]; then
+				"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout"
+				found=$((found + 1))
+			fi
 			testname=${BASH_REMATCH[1]}
 			smp=1
 			kernel=""
@@ -45,6 +49,17 @@  function for_each_unittest()
 			timeout=${BASH_REMATCH[1]}
 		fi
 	done
-	"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout"
+	if [[ -z "$only_test" || "$testname" == "$only_test" ]]; then
+		"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout"
+		found=$((found + 1))
+	fi
+
 	exec {fd}<&-
+
+	if [[ $found -eq 0 ]]; then
+		echo "Didn't run any tests."
+		return 1
+	fi
+
+	echo "Ran $found test(s)."
 }