[sheepdog] [PATCH v2 1/4] tests/functional: add _requirement() to filter testcases

MORITA Kazutaka morita.kazutaka at gmail.com
Tue Aug 13 06:37:37 CEST 2013


From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

We have several restrictions on which tests can be run.  E.g. 011
cannot be run without a root privilege, 042 cannot be run with -md
option, some cluster tests cannot be passed with shepherd, etc.

This patch generalizes _need_to_be_root() to _requirement() and
enables us to control which tests should be run more flexibly.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 tests/functional/011       |    2 +-
 tests/functional/035       |    2 +-
 tests/functional/042       |    2 +-
 tests/functional/050       |    2 +-
 tests/functional/054       |    2 +-
 tests/functional/063       |    2 +-
 tests/functional/064       |    2 +-
 tests/functional/common.rc |   39 ++++++++++++++++++++++++++++++++-------
 8 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/tests/functional/011 b/tests/functional/011
index 71548f6..91d23c0 100755
--- a/tests/functional/011
+++ b/tests/functional/011
@@ -4,7 +4,7 @@
 
 . ./common
 
-_need_to_be_root
+_requirement root
 
 _make_device 0 $((2 * 1024 ** 3))
 _make_device 1 $((4 * 1024 ** 3))
diff --git a/tests/functional/035 b/tests/functional/035
index c1559e0..fe5731b 100755
--- a/tests/functional/035
+++ b/tests/functional/035
@@ -12,7 +12,7 @@ _uninit()
 	done
 }
 
-_need_to_be_root
+_requirement root
 
 for i in `seq 0 5`; do
 	_start_sheep $i
diff --git a/tests/functional/042 b/tests/functional/042
index 54e8a33..6ceb5f1 100755
--- a/tests/functional/042
+++ b/tests/functional/042
@@ -4,7 +4,7 @@
 
 . ./common
 
-_need_to_be_root
+_requirement root
 
 _make_device 0 $((1024 ** 3))
 _make_device 1 $((1024 ** 3))
diff --git a/tests/functional/050 b/tests/functional/050
index 8a35c59..0868a75 100755
--- a/tests/functional/050
+++ b/tests/functional/050
@@ -12,7 +12,7 @@ _uninit()
 	iptables -D INPUT -p tcp --dport 8001 -j DROP
 }
 
-_need_to_be_root
+_requirement root
 
 for i in `seq 0 2`; do
 	_start_sheep $i "-i host=127.0.0.1,port=$((8000+$i))"
diff --git a/tests/functional/054 b/tests/functional/054
index 3b28bae..9b4cce2 100755
--- a/tests/functional/054
+++ b/tests/functional/054
@@ -3,7 +3,7 @@
 # Test stale objects purging with different disk size.
 . ./common
 
-_need_to_be_root
+_requirement root
 
 _make_device 0 $((1024 ** 3))
 _make_device 1 $((2 * 1024 ** 3))
diff --git a/tests/functional/063 b/tests/functional/063
index 8a648c6..2f817e4 100755
--- a/tests/functional/063
+++ b/tests/functional/063
@@ -3,7 +3,7 @@
 # Test reweight
 . ./common
 
-_need_to_be_root
+_requirement root
 
 _make_device 0 $((100 * 1024 ** 2))
 _make_device 1 $((100 * 1024 ** 2))
diff --git a/tests/functional/064 b/tests/functional/064
index 3a6f168..d712d62 100755
--- a/tests/functional/064
+++ b/tests/functional/064
@@ -3,7 +3,7 @@
 # Test node failure while reweighting
 . ./common
 
-_need_to_be_root
+_requirement root
 
 _make_device 0 $((200 * 1024 ** 2)) # 200 MB
 _make_device 1 $((200 * 1024 ** 2)) # 200 MB
diff --git a/tests/functional/common.rc b/tests/functional/common.rc
index 2a64b53..ae279e5 100644
--- a/tests/functional/common.rc
+++ b/tests/functional/common.rc
@@ -30,15 +30,40 @@ fi
 # make sure we have a standard umask
 umask 022
 
-# check if run as root
-#
-_need_to_be_root()
+_check_root()
 {
     local id=`id | $SED_PROG -e 's/(.*//' -e 's/.*=//'`
-    if [ "$id" -ne 0 ]
-    then
-	_notrun "you need to be root (not uid=$id) to run this test"
-    fi
+    [ "$id" -eq 0 ]
+}
+
+_requirement()
+{
+    local arg
+    local required
+    local feature
+
+    for arg in $*; do
+	if [ $(echo $arg | cut -c 1-4) = "not_" ]; then
+	    required=false
+	    feature=$(echo $arg | cut -c 5-)
+	else
+	    required=true
+	    feature=$arg
+	fi
+
+	local check=_check_$feature
+
+	type $check 1>/dev/null 2>/dev/null
+	if [ $? != 0 ]; then
+	    _die $check is not defined
+	fi
+
+	if $check && ! $required; then
+	    _notrun "cannot run this test with $feature"
+	elif ! $check && $required; then
+	    _notrun "$feature is required to run this test"
+	fi
+    done
 }
 
 # To remove directory successfully always, we have to rename it first
-- 
1.7.9.5




More information about the sheepdog mailing list