From 6d8331fd588d97fb123db470e21e2e64b7372f09 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Fri, 9 Oct 2009 08:47:43 -0400 Subject: [PATCH] tests: Add network XML to XML tests. --- tests/.gitignore | 1 + tests/Makefile.am | 12 ++- tests/networkschematest | 3 +- tests/networkxml2xmlin/isolated-network.xml | 10 ++ tests/networkxml2xmlin/nat-network.xml | 13 +++ .../netboot-network.xml | 4 +- tests/networkxml2xmlin/routed-network.xml | 11 +++ tests/networkxml2xmlout/isolated-network.xml | 10 ++ tests/networkxml2xmlout/nat-network.xml | 13 +++ tests/networkxml2xmlout/netboot-network.xml | 14 +++ tests/networkxml2xmlout/routed-network.xml | 11 +++ tests/networkxml2xmltest.c | 96 +++++++++++++++++++ 12 files changed, 194 insertions(+), 4 deletions(-) create mode 100644 tests/networkxml2xmlin/isolated-network.xml create mode 100644 tests/networkxml2xmlin/nat-network.xml rename tests/{networkschemadata => networkxml2xmlin}/netboot-network.xml (68%) create mode 100644 tests/networkxml2xmlin/routed-network.xml create mode 100644 tests/networkxml2xmlout/isolated-network.xml create mode 100644 tests/networkxml2xmlout/nat-network.xml create mode 100644 tests/networkxml2xmlout/netboot-network.xml create mode 100644 tests/networkxml2xmlout/routed-network.xml create mode 100644 tests/networkxml2xmltest.c diff --git a/tests/.gitignore b/tests/.gitignore index 41f84543f4..c2021412d6 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -13,6 +13,7 @@ qemuxml2xmltest qemuxml2argvtest qemuargv2xmltest qemuhelptest +networkxml2xmltest nodedevxml2xmltest interfacexml2xmltest storagepoolxml2xmltest diff --git a/tests/Makefile.am b/tests/Makefile.am index a62c01bb42..b6acfa4105 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -56,7 +56,8 @@ EXTRA_DIST = \ capabilityschematest \ capabilityschemadata \ networkschematest \ - networkschemadata \ + networkpoolxml2xmlout \ + networkpoolxml2xmlin \ domainschematest \ domainschemadata \ interfaceschemadata \ @@ -96,6 +97,8 @@ if WITH_CIL noinst_PROGRAMS += object-locking endif +noinst_PROGRAMS += networkxml2xmltest + noinst_PROGRAMS += storagepoolxml2xmltest noinst_PROGRAMS += nodedevxml2xmltest @@ -171,6 +174,8 @@ noinst_PROGRAMS += eventtest TESTS += eventtest endif +TESTS += networkxml2xmltest + TESTS += storagepoolxml2xmltest TESTS += nodedevxml2xmltest @@ -269,6 +274,11 @@ else EXTRA_DIST += esxutilstest.c vmx2xmltest.c xml2vmxtest.c endif +networkxml2xmltest_SOURCES = \ + networkxml2xmltest.c \ + testutils.c testutils.h +networkxml2xmltest_LDADD = $(LDADDS) + storagepoolxml2xmltest_SOURCES = \ storagepoolxml2xmltest.c \ testutils.c testutils.h diff --git a/tests/networkschematest b/tests/networkschematest index 8bb24cd091..6305576b98 100755 --- a/tests/networkschematest +++ b/tests/networkschematest @@ -2,8 +2,7 @@ source ./schematestutils.sh -DIRS="../src/network networkschemadata" +DIRS="../src/network networkxml2xmlin networkxml2xmlout" SCHEMA="network.rng" check_schema "$DIRS" "$SCHEMA" - diff --git a/tests/networkxml2xmlin/isolated-network.xml b/tests/networkxml2xmlin/isolated-network.xml new file mode 100644 index 0000000000..507e3bb905 --- /dev/null +++ b/tests/networkxml2xmlin/isolated-network.xml @@ -0,0 +1,10 @@ + + private + 81ff0d90-c91e-6742-64da-4a736edb9a9b + + + + + + + diff --git a/tests/networkxml2xmlin/nat-network.xml b/tests/networkxml2xmlin/nat-network.xml new file mode 100644 index 0000000000..93ab18616f --- /dev/null +++ b/tests/networkxml2xmlin/nat-network.xml @@ -0,0 +1,13 @@ + + default + 81ff0d90-c91e-6742-64da-4a736edb9a9b + + + + + + + + + + diff --git a/tests/networkschemadata/netboot-network.xml b/tests/networkxml2xmlin/netboot-network.xml similarity index 68% rename from tests/networkschemadata/netboot-network.xml rename to tests/networkxml2xmlin/netboot-network.xml index 7274ee6b99..ed75663053 100644 --- a/tests/networkschemadata/netboot-network.xml +++ b/tests/networkxml2xmlin/netboot-network.xml @@ -1,6 +1,8 @@ netboot - + 81ff0d90-c91e-6742-64da-4a736edb9a9b + + diff --git a/tests/networkxml2xmlin/routed-network.xml b/tests/networkxml2xmlin/routed-network.xml new file mode 100644 index 0000000000..824ad75ed5 --- /dev/null +++ b/tests/networkxml2xmlin/routed-network.xml @@ -0,0 +1,11 @@ + + local + 81ff0d90-c91e-6742-64da-4a736edb9a9b + + + + + + + + diff --git a/tests/networkxml2xmlout/isolated-network.xml b/tests/networkxml2xmlout/isolated-network.xml new file mode 100644 index 0000000000..1d06f19bb1 --- /dev/null +++ b/tests/networkxml2xmlout/isolated-network.xml @@ -0,0 +1,10 @@ + + private + 81ff0d90-c91e-6742-64da-4a736edb9a9b + + + + + + + diff --git a/tests/networkxml2xmlout/nat-network.xml b/tests/networkxml2xmlout/nat-network.xml new file mode 100644 index 0000000000..036d4fb616 --- /dev/null +++ b/tests/networkxml2xmlout/nat-network.xml @@ -0,0 +1,13 @@ + + default + 81ff0d90-c91e-6742-64da-4a736edb9a9b + + + + + + + + + + diff --git a/tests/networkxml2xmlout/netboot-network.xml b/tests/networkxml2xmlout/netboot-network.xml new file mode 100644 index 0000000000..b8a4d996fb --- /dev/null +++ b/tests/networkxml2xmlout/netboot-network.xml @@ -0,0 +1,14 @@ + + netboot + 81ff0d90-c91e-6742-64da-4a736edb9a9b + + + + + + + + + + + diff --git a/tests/networkxml2xmlout/routed-network.xml b/tests/networkxml2xmlout/routed-network.xml new file mode 100644 index 0000000000..fa36c08007 --- /dev/null +++ b/tests/networkxml2xmlout/routed-network.xml @@ -0,0 +1,11 @@ + + local + 81ff0d90-c91e-6742-64da-4a736edb9a9b + + + + + + + + diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c new file mode 100644 index 0000000000..b02d735a47 --- /dev/null +++ b/tests/networkxml2xmltest.c @@ -0,0 +1,96 @@ +#include + +#include +#include +#include +#include + +#include +#include + +#include "internal.h" +#include "testutils.h" +#include "network_conf.h" +#include "testutilsqemu.h" + +static char *progname; +static char *abs_srcdir; + +#define MAX_FILE 4096 + + +static int testCompareXMLToXMLFiles(const char *inxml, const char *outxml) { + char inXmlData[MAX_FILE]; + char *inXmlPtr = &(inXmlData[0]); + char outXmlData[MAX_FILE]; + char *outXmlPtr = &(outXmlData[0]); + char *actual = NULL; + int ret = -1; + virNetworkDefPtr dev = NULL; + + if (virtTestLoadFile(inxml, &inXmlPtr, MAX_FILE) < 0) + goto fail; + if (virtTestLoadFile(outxml, &outXmlPtr, MAX_FILE) < 0) + goto fail; + + if (!(dev = virNetworkDefParseString(NULL, inXmlData))) + goto fail; + + if (!(actual = virNetworkDefFormat(NULL, dev))) + goto fail; + + if (STRNEQ(outXmlData, actual)) { + virtTestDifference(stderr, outXmlData, actual); + goto fail; + } + + ret = 0; + + fail: + free(actual); + virNetworkDefFree(dev); + return ret; +} + +static int testCompareXMLToXMLHelper(const void *data) { + char inxml[PATH_MAX]; + char outxml[PATH_MAX]; + snprintf(inxml, PATH_MAX, "%s/networkxml2xmlin/%s.xml", + abs_srcdir, (const char*)data); + snprintf(outxml, PATH_MAX, "%s/networkxml2xmlout/%s.xml", + abs_srcdir, (const char*)data); + return testCompareXMLToXMLFiles(inxml, outxml); +} + + +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("Network XML-2-XML " name, \ + 1, testCompareXMLToXMLHelper, (name)) < 0) \ + ret = -1 + + DO_TEST("isolated-network"); + DO_TEST("routed-network"); + DO_TEST("nat-network"); + DO_TEST("netboot-network"); + + return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); +} + +VIRT_TEST_MAIN(mymain)