[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/

On Wed, Jul 15, 2009 at 11:20:00AM +0200, Daniel Veillard wrote:
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.
ACK, good stuff.
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);
BTW, you don't need this fprintf when using virtTestDifference. If you set VIR_TEST_DEBUG=2 then it will print out the full XML being compared automatically :-) Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Wed, Jul 15, 2009 at 11:24:59AM +0100, Daniel P. Berrange wrote:
On Wed, Jul 15, 2009 at 11:20:00AM +0200, Daniel Veillard wrote:
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.
ACK, good stuff.
+ fail: + if (ret != 0) + fprintf(stderr, "expected: -------\n%s", actual);
BTW, you don't need this fprintf when using virtTestDifference. If you set VIR_TEST_DEBUG=2 then it will print out the full XML being compared automatically :-)
Oops I knew I had forgotten a debugging output it escaped, good catch ! 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/
participants (2)
-
Daniel P. Berrange
-
Daniel Veillard