[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 03/10] tests: Break out duplicate schema verification functionality.



All schema tests have identical functionality, so avoid the duplication.

Signed-off-by: Cole Robinson <crobinso redhat com>
---
 tests/Makefile.am           |    1 +
 tests/capabilityschematest  |   34 ++++------------------------------
 tests/domainschematest      |   33 ++++-----------------------------
 tests/interfaceschematest   |   31 +++----------------------------
 tests/networkschematest     |   30 +++---------------------------
 tests/nodedevschematest     |   31 +++----------------------------
 tests/schematestutils.sh    |   39 +++++++++++++++++++++++++++++++++++++++
 tests/storagepoolschematest |   31 +++----------------------------
 tests/storagevolschematest  |   30 +++---------------------------
 9 files changed, 63 insertions(+), 197 deletions(-)
 create mode 100644 tests/schematestutils.sh

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7882e52..b67df5d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -52,6 +52,7 @@ EXTRA_DIST =		\
 	test-lib.sh	\
 	qemuxml2argvdata \
 	nodeinfodata     \
+	schematestutils.sh \
 	capabilityschematest \
 	capabilityschemadata \
 	networkschematest \
diff --git a/tests/capabilityschematest b/tests/capabilityschematest
index a166724..651e23e 100755
--- a/tests/capabilityschematest
+++ b/tests/capabilityschematest
@@ -1,34 +1,8 @@
 #!/bin/sh
 
-test -z "$srcdir" && srcdir=`pwd`
-test -z "$abs_srcdir" && abs_srcdir=`pwd`
+source ./schematestutils.sh
 
-DOMAINDIRS="capabilityschemadata xencapsdata"
+DIRS="capabilityschemadata xencapsdata"
+SCHEMA="capability.rng"
 
-
-n=0
-f=0
-for dir in $DOMAINDIRS
-do
-  XML=`find $abs_srcdir/$dir -name '*.xml'` || exit 1
-
-  for xml in $XML
-  do
-    n=`expr $n + 1`
-    printf "%4d) %.60s  " $n $(basename $(dirname $xml))"/"$(basename $xml)
-    result=`xmllint --relaxng $srcdir/../docs/schemas/capability.rng --noout $xml 2>&1`
-    ret=$?
-    if test $ret = 0; then
-        echo "OK"
-    else
-        echo "FAILED"
-        echo $result
-        f=`expr $f + 1`
-    fi
-  done
-done
-echo "Validated $n files, $f failed"
-
-ret=0
-test $f != 0 && ret=255
-exit $ret
+check_schema "$DIRS" "$SCHEMA"
diff --git a/tests/domainschematest b/tests/domainschematest
index 0a7d4a1..bd58a30 100755
--- a/tests/domainschematest
+++ b/tests/domainschematest
@@ -1,33 +1,8 @@
 #!/bin/sh
 
-test -z "$srcdir" && srcdir=`pwd`
-test -z "$abs_srcdir" && abs_srcdir=`pwd`
+source ./schematestutils.sh
 
-DOMAINDIRS="domainschemadata qemuxml2argvdata sexpr2xmldata xmconfigdata xml2sexprdata"
+DIRS="domainschemadata qemuxml2argvdata sexpr2xmldata xmconfigdata xml2sexprdata"
+SCHEMA="domain.rng"
 
-n=0
-f=0
-for dir in $DOMAINDIRS
-do
-  XML=`find $abs_srcdir/$dir -name '*.xml'` || exit 1
-
-  for xml in $XML
-  do
-    n=`expr $n + 1`
-    printf "%4d) %.60s  " $n $(basename $(dirname $xml))"/"$(basename $xml)
-    result=`xmllint --relaxng $srcdir/../docs/schemas/domain.rng --noout $xml 2>&1`
-    ret=$?
-    if test $ret = 0; then
-        echo "OK"
-    else
-        echo "FAILED"
-        echo $result
-        f=`expr $f + 1`
-    fi
-  done
-done
-echo "Validated $n files, $f failed"
-
-ret=0
-test $f != 0 && ret=255
-exit $ret
+check_schema "$DIRS" "$SCHEMA"
diff --git a/tests/interfaceschematest b/tests/interfaceschematest
index 3e4105c..e7bd4e5 100755
--- a/tests/interfaceschematest
+++ b/tests/interfaceschematest
@@ -1,33 +1,8 @@
 #!/bin/sh
 
-test -z "$srcdir" && srcdir=`pwd`
-test -z "$abs_srcdir" && abs_srcdir=`pwd`
+source ./schematestutils.sh
 
 DIRS="interfaceschemadata"
+SCHEMA="interface.rng"
 
-n=0
-f=0
-for dir in $DIRS
-do
-  XML=`find $abs_srcdir/$dir -name '*.xml'` || exit 1
-
-  for xml in $XML
-  do
-    n=`expr $n + 1`
-    printf "%4d) %.60s  " $n $(basename $(dirname $xml))"/"$(basename $xml)
-    result=`xmllint --relaxng $srcdir/../docs/schemas/interface.rng --noout $xml 2>&1`
-    ret=$?
-    if test $ret = 0; then
-        echo "OK"
-    else
-        echo "FAILED"
-        echo $result
-        f=`expr $f + 1`
-    fi
-  done
-done
-echo "Validated $n files, $f failed"
-
-ret=0
-test $f != 0 && ret=255
-exit $ret
+check_schema "$DIRS" "$SCHEMA"
diff --git a/tests/networkschematest b/tests/networkschematest
index 3fc0f27..8bb24cd 100755
--- a/tests/networkschematest
+++ b/tests/networkschematest
@@ -1,33 +1,9 @@
 #!/bin/sh
 
-test -z "$srcdir" && srcdir=`pwd`
-test -z "$abs_srcdir" && abs_srcdir=`pwd`
+source ./schematestutils.sh
 
 DIRS="../src/network networkschemadata"
+SCHEMA="network.rng"
 
-n=0
-f=0
-for dir in $DIRS
-do
-  XML=`find $abs_srcdir/$dir -name '*.xml'` || exit 1
+check_schema "$DIRS" "$SCHEMA"
 
-  for xml in $XML
-  do
-    n=`expr $n + 1`
-    printf "%4d) %.60s  " $n $(basename $(dirname $xml))"/"$(basename $xml)
-    result=`xmllint --relaxng $srcdir/../docs/schemas/network.rng --noout $xml 2>&1`
-    ret=$?
-    if test $ret = 0; then
-        echo "OK"
-    else
-        echo "FAILED"
-        echo $result
-        f=`expr $f + 1`
-    fi
-  done
-done
-echo "Validated $n files, $f failed"
-
-ret=0
-test $f != 0 && ret=255
-exit $ret
diff --git a/tests/nodedevschematest b/tests/nodedevschematest
index 23e9e57..e676660 100755
--- a/tests/nodedevschematest
+++ b/tests/nodedevschematest
@@ -1,33 +1,8 @@
 #!/bin/sh
 
-test -z "$srcdir" && srcdir=`pwd`
-test -z "$abs_srcdir" && abs_srcdir=`pwd`
+source ./schematestutils.sh
 
 DIRS="nodedevschemadata"
+SCHEMA="nodedev.rng"
 
-n=0
-f=0
-for dir in $DIRS
-do
-  XML=`find $abs_srcdir/$dir -name '*.xml'` || exit 1
-
-  for xml in $XML
-  do
-    n=`expr $n + 1`
-    printf "%4d) %.60s  " $n $(basename $(dirname $xml))"/"$(basename $xml)
-    result=`xmllint --relaxng $srcdir/../docs/schemas/nodedev.rng --noout $xml 2>&1`
-    ret=$?
-    if test $ret = 0; then
-        echo "OK"
-    else
-        echo "FAILED"
-        echo $result
-        f=`expr $f + 1`
-    fi
-  done
-done
-echo "Validated $n files, $f failed"
-
-ret=0
-test $f != 0 && ret=255
-exit $ret
+check_schema "$DIRS" "$SCHEMA"
diff --git a/tests/schematestutils.sh b/tests/schematestutils.sh
new file mode 100644
index 0000000..4b5f266
--- /dev/null
+++ b/tests/schematestutils.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+test -z "$srcdir" && srcdir=`pwd`
+test -z "$abs_srcdir" && abs_srcdir=`pwd`
+
+function check_schema {
+
+DIRS=$1
+SCHEMA="$srcdir/../docs/schemas/$2"
+
+n=0
+f=0
+for dir in $DIRS
+do
+  XML=`find $abs_srcdir/$dir -name '*.xml'` || exit 1
+
+  for xml in $XML
+  do
+    n=`expr $n + 1`
+    printf "%4d) %.60s  " $n $(basename $(dirname $xml))"/"$(basename $xml)
+    cmd="xmllint --relaxng $SCHEMA --noout $xml"
+    result=`$cmd 2>&1`
+    ret=$?
+    if test $ret = 0; then
+        echo "OK"
+    else
+        echo "FAILED"
+        echo -e "$cmd\n$result"
+        f=`expr $f + 1`
+    fi
+  done
+done
+echo "Validated $n files, $f failed"
+
+ret=0
+test $f != 0 && ret=255
+exit $ret
+
+}
diff --git a/tests/storagepoolschematest b/tests/storagepoolschematest
index f6a973d..d04b83b 100755
--- a/tests/storagepoolschematest
+++ b/tests/storagepoolschematest
@@ -1,33 +1,8 @@
 #!/bin/sh
 
-test -z "$srcdir" && srcdir=`pwd`
-test -z "$abs_srcdir" && abs_srcdir=`pwd`
+source ./schematestutils.sh
 
 DIRS="storagepoolschemadata"
+SCHEMA="storagepool.rng"
 
-n=0
-f=0
-for dir in $DIRS
-do
-  XML=`find $abs_srcdir/$dir -name '*.xml'` || exit 1
-
-  for xml in $XML
-  do
-    n=`expr $n + 1`
-    printf "%4d) %.60s  " $n $(basename $(dirname $xml))"/"$(basename $xml)
-    result=`xmllint --relaxng $srcdir/../docs/schemas/storagepool.rng --noout $xml 2>&1`
-    ret=$?
-    if test $ret = 0; then
-        echo "OK"
-    else
-        echo "FAILED"
-        echo $result
-        f=`expr $f + 1`
-    fi
-  done
-done
-echo "Validated $n files, $f failed"
-
-ret=0
-test $f != 0 && ret=255
-exit $ret
+check_schema "$DIRS" "$SCHEMA"
diff --git a/tests/storagevolschematest b/tests/storagevolschematest
index 7865102..8b5559a 100755
--- a/tests/storagevolschematest
+++ b/tests/storagevolschematest
@@ -1,33 +1,9 @@
 #!/bin/sh
 
-test -z "$srcdir" && srcdir=`pwd`
-test -z "$abs_srcdir" && abs_srcdir=`pwd`
+source ./schematestutils.sh
 
 DIRS="storagevolschemadata"
+SCHEMA="storagevol.rng"
 
-n=0
-f=0
-for dir in $DIRS
-do
-  XML=`find $abs_srcdir/$dir -name '*.xml'` || exit 1
+check_schema "$DIRS" "$SCHEMA"
 
-  for xml in $XML
-  do
-    n=`expr $n + 1`
-    printf "%4d) %.60s  " $n $(basename $(dirname $xml))"/"$(basename $xml)
-    result=`xmllint --relaxng $srcdir/../docs/schemas/storagevol.rng --noout $xml 2>&1`
-    ret=$?
-    if test $ret = 0; then
-        echo "OK"
-    else
-        echo "FAILED"
-        echo $result
-        f=`expr $f + 1`
-    fi
-  done
-done
-echo "Validated $n files, $f failed"
-
-ret=0
-test $f != 0 && ret=255
-exit $ret
-- 
1.6.5.rc2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]