mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
netcf XML validation and input and output tests
* tests/interfaceschematest: test all XML data against the interface schemas * tests/interfacexml2xmltest.c: parse and reserialize all XML data and check the output is identical * tests/Makefile.am: hook up the tests * tests/.gitignore: add ignore test
This commit is contained in:
parent
19e57fd902
commit
788c315165
1
tests/.gitignore
vendored
1
tests/.gitignore
vendored
@ -14,6 +14,7 @@ qemuxml2argvtest
|
|||||||
qemuargv2xmltest
|
qemuargv2xmltest
|
||||||
qemuhelptest
|
qemuhelptest
|
||||||
nodedevxml2xmltest
|
nodedevxml2xmltest
|
||||||
|
interfacexml2xmltest
|
||||||
nodeinfotest
|
nodeinfotest
|
||||||
statstest
|
statstest
|
||||||
qparamtest
|
qparamtest
|
||||||
|
@ -82,8 +82,11 @@ endif
|
|||||||
|
|
||||||
noinst_PROGRAMS += nodedevxml2xmltest
|
noinst_PROGRAMS += nodedevxml2xmltest
|
||||||
|
|
||||||
|
noinst_PROGRAMS += interfacexml2xmltest
|
||||||
|
|
||||||
test_scripts = \
|
test_scripts = \
|
||||||
capabilityschematest \
|
capabilityschematest \
|
||||||
|
interfaceschematest \
|
||||||
networkschematest \
|
networkschematest \
|
||||||
storagepoolschematest \
|
storagepoolschematest \
|
||||||
storagevolschematest \
|
storagevolschematest \
|
||||||
@ -141,6 +144,8 @@ endif
|
|||||||
|
|
||||||
TESTS += nodedevxml2xmltest
|
TESTS += nodedevxml2xmltest
|
||||||
|
|
||||||
|
TESTS += interfacexml2xmltest
|
||||||
|
|
||||||
path_add = $$abs_top_builddir/src$(PATH_SEPARATOR)$$abs_top_builddir/qemud
|
path_add = $$abs_top_builddir/src$(PATH_SEPARATOR)$$abs_top_builddir/qemud
|
||||||
|
|
||||||
# NB, automake < 1.10 does not provide the real
|
# NB, automake < 1.10 does not provide the real
|
||||||
@ -219,6 +224,11 @@ nodedevxml2xmltest_SOURCES = \
|
|||||||
testutils.c testutils.h
|
testutils.c testutils.h
|
||||||
nodedevxml2xmltest_LDADD = $(LDADDS)
|
nodedevxml2xmltest_LDADD = $(LDADDS)
|
||||||
|
|
||||||
|
interfacexml2xmltest_SOURCES = \
|
||||||
|
interfacexml2xmltest.c \
|
||||||
|
testutils.c testutils.h
|
||||||
|
interfacexml2xmltest_LDADD = $(LDADDS)
|
||||||
|
|
||||||
virshtest_SOURCES = \
|
virshtest_SOURCES = \
|
||||||
virshtest.c \
|
virshtest.c \
|
||||||
testutils.c testutils.h
|
testutils.c testutils.h
|
||||||
|
33
tests/interfaceschematest
Executable file
33
tests/interfaceschematest
Executable file
@ -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
|
97
tests/interfacexml2xmltest.c
Normal file
97
tests/interfacexml2xmltest.c
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user