mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +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
|
||||
qemuhelptest
|
||||
nodedevxml2xmltest
|
||||
interfacexml2xmltest
|
||||
nodeinfotest
|
||||
statstest
|
||||
qparamtest
|
||||
|
@ -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
|
||||
|
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