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

[libvirt] [PATCH] 3/3 Add netcf XML validation and input and output tests



  Basic stuff similar to other tests, first we verify the input tests
all conform to the provided schemas, then for each test we parse and
reserialize verifying the output is identical.

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/
diff --git a/tests/.gitignore b/tests/.gitignore
index 7a4d44f..466ec13 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -14,6 +14,7 @@ qemuxml2argvtest
 qemuargv2xmltest
 qemuhelptest
 nodedevxml2xmltest
+interfacexml2xmltest
 nodeinfotest
 statstest
 qparamtest
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f8bde34..efd7c6e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -82,8 +82,11 @@ endif
 
 noinst_PROGRAMS += nodedevxml2xmltest
 
+noinst_PROGRAMS += interfacexml2xmltest
+
 test_scripts = \
 	capabilityschematest \
+	interfaceschematest \
 	networkschematest \
 	storagepoolschematest \
 	storagevolschematest \
@@ -141,6 +144,8 @@ endif
 
 TESTS += nodedevxml2xmltest
 
+TESTS += interfacexml2xmltest
+
 path_add = $$abs_top_builddir/src$(PATH_SEPARATOR)$$abs_top_builddir/qemud
 
 # NB, automake < 1.10 does not provide the real
@@ -219,6 +224,11 @@ nodedevxml2xmltest_SOURCES = \
 	testutils.c testutils.h
 nodedevxml2xmltest_LDADD = $(LDADDS)
 
+interfacexml2xmltest_SOURCES = \
+	interfacexml2xmltest.c \
+	testutils.c testutils.h
+interfacexml2xmltest_LDADD = $(LDADDS)
+
 virshtest_SOURCES = \
 	virshtest.c \
 	testutils.c testutils.h
diff --git a/tests/interfaceschematest b/tests/interfaceschematest
new file mode 100755
index 0000000..3e4105c
--- /dev/null
+++ b/tests/interfaceschematest
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+test -z "$srcdir" && srcdir=`pwd`
+test -z "$abs_srcdir" && abs_srcdir=`pwd`
+
+DIRS="interfaceschemadata"
+
+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
diff --git a/tests/interfacexml2xmltest.c b/tests/interfacexml2xmltest.c
new file mode 100644
index 0000000..6e6c5e8
--- /dev/null
+++ b/tests/interfacexml2xmltest.c
@@ -0,0 +1,97 @@
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include "internal.h"
+#include "testutils.h"
+#include "interface_conf.h"
+#include "testutilsqemu.h"
+
+static char *progname;
+static char *abs_srcdir;
+
+#define MAX_FILE 4096
+
+
+static int testCompareXMLToXMLFiles(const char *xml) {
+    char xmlData[MAX_FILE];
+    char *xmlPtr = &(xmlData[0]);
+    char *actual = NULL;
+    int ret = -1;
+    virInterfaceDefPtr dev = NULL;
+
+    if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
+        goto fail;
+
+    if (!(dev = virInterfaceDefParseString(NULL, xmlData)))
+        goto fail;
+
+    if (!(actual = virInterfaceDefFormat(NULL, dev)))
+        goto fail;
+
+    if (STRNEQ(xmlData, actual)) {
+        virtTestDifference(stderr, xmlData, actual);
+        goto fail;
+    }
+
+    ret = 0;
+
+ fail:
+    if (ret != 0)
+        fprintf(stderr, "expected: -------\n%s", actual);
+    free(actual);
+    virInterfaceDefFree(dev);
+    return ret;
+}
+
+static int testCompareXMLToXMLHelper(const void *data) {
+    char xml[PATH_MAX];
+    snprintf(xml, PATH_MAX, "%s/interfaceschemadata/%s.xml",
+             abs_srcdir, (const char*)data);
+    return testCompareXMLToXMLFiles(xml);
+}
+
+
+static int
+mymain(int argc, char **argv)
+{
+    int ret = 0;
+    char cwd[PATH_MAX];
+
+    progname = argv[0];
+
+    if (argc > 1) {
+        fprintf(stderr, "Usage: %s\n", progname);
+        return (EXIT_FAILURE);
+    }
+
+    abs_srcdir = getenv("abs_srcdir");
+    if (!abs_srcdir)
+        abs_srcdir = getcwd(cwd, sizeof(cwd));
+
+#define DO_TEST(name) \
+    if (virtTestRun("Node device XML-2-XML " name, \
+                    1, testCompareXMLToXMLHelper, (name)) < 0) \
+        ret = -1
+
+    DO_TEST("ethernet-dhcp");
+    DO_TEST("ethernet-static");
+    DO_TEST("ethernet-static-no-prefix");
+    DO_TEST("bridge");
+    DO_TEST("bridge42");
+    DO_TEST("bridge-vlan");
+    DO_TEST("bridge-no-address");
+    DO_TEST("vlan");
+    DO_TEST("bond");
+    DO_TEST("bond-arp");
+
+    return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
+}
+
+VIRT_TEST_MAIN(mymain)

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