提交 788c3151 编写于 作者: D Daniel Veillard

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
上级 19e57fd9
......@@ -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
......
#!/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
#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)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册