[PATCH 10/10] tests: add some simple libxl XML->XML tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Handle features supported only on xen: driver domains, qemu in
stubdomain.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>
---
 tests/Makefile.am                                  |   9 +-
 tests/domainschematest                             |   2 +-
 tests/xlxml2xmldata/xlxml2xml-hvm-stubdom.xml      |  41 +++++
 tests/xlxml2xmldata/xlxml2xml-hvm.xml              |  40 +++++
 tests/xlxml2xmldata/xlxml2xml-network-bridged.xml  |  38 +++++
 .../xlxml2xml-network-driver-domain.xml            |  38 +++++
 tests/xlxml2xmldata/xlxml2xml-network-routed.xml   |  39 +++++
 tests/xlxml2xmldata/xlxml2xml-pv.xml               |  38 +++++
 tests/xlxml2xmltest.c                              | 189 +++++++++++++++++++++
 9 files changed, 431 insertions(+), 3 deletions(-)
 create mode 100644 tests/xlxml2xmldata/xlxml2xml-hvm-stubdom.xml
 create mode 100644 tests/xlxml2xmldata/xlxml2xml-hvm.xml
 create mode 100644 tests/xlxml2xmldata/xlxml2xml-network-bridged.xml
 create mode 100644 tests/xlxml2xmldata/xlxml2xml-network-driver-domain.xml
 create mode 100644 tests/xlxml2xmldata/xlxml2xml-network-routed.xml
 create mode 100644 tests/xlxml2xmldata/xlxml2xml-pv.xml
 create mode 100644 tests/xlxml2xmltest.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 938270c..48648b9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -85,6 +85,7 @@ EXTRA_DIST =		\
 	domainsnapshotxml2xmlout \
 	fchostdata \
 	interfaceschemadata \
+	xlxml2xmldata \
 	lxcconf2xmldata \
 	lxcxml2xmldata \
 	lxcxml2xmloutdata \
@@ -230,7 +231,7 @@ test_programs += xml2sexprtest sexpr2xmltest \
 endif WITH_XEN
 
 if WITH_LIBXL
-test_programs += xlconfigtest
+test_programs += xlconfigtest xlxml2xmltest
 endif WITH_LIBXL
 
 if WITH_QEMU
@@ -515,8 +516,12 @@ xlconfigtest_SOURCES = \
 	xlconfigtest.c testutilsxen.c testutilsxen.h \
 	testutils.c testutils.h
 xlconfigtest_LDADD =$(libxl_LDADDS)
+xlxml2xmltest_SOURCES = \
+	xlxml2xmltest.c testutilsxen.c testutilsxen.h \
+	testutils.c testutils.h
+xlxml2xmltest_LDADD =$(libxl_LDADDS)
 else ! WITH_LIBXL
-EXTRA_DIST += xlconfigtest.c
+EXTRA_DIST += xlconfigtest.c xlxml2xmltest.c
 endif ! WITH_LIBXL
 
 QEMUMONITORTESTUTILS_SOURCES = \
diff --git a/tests/domainschematest b/tests/domainschematest
index ba90180..18b442b 100755
--- a/tests/domainschematest
+++ b/tests/domainschematest
@@ -8,7 +8,7 @@ DIRS=""
 DIRS="$DIRS domainschemadata qemuxml2argvdata sexpr2xmldata"
 DIRS="$DIRS xmconfigdata xml2sexprdata qemuxml2xmloutdata"
 DIRS="$DIRS lxcxml2xmldata lxcxml2xmloutdata"
-DIRS="$DIRS bhyvexml2argvdata"
+DIRS="$DIRS bhyvexml2argvdata xlxml2xmldata"
 SCHEMA="domain.rng"
 
 check_schema "$DIRS" "$SCHEMA"
diff --git a/tests/xlxml2xmldata/xlxml2xml-hvm-stubdom.xml b/tests/xlxml2xmldata/xlxml2xml-hvm-stubdom.xml
new file mode 100644
index 0000000..ed6440c
--- /dev/null
+++ b/tests/xlxml2xmldata/xlxml2xml-hvm-stubdom.xml
@@ -0,0 +1,41 @@
+<domain type='xen'>
+  <name>testhvm</name>
+  <uuid>a3d3fa04-dc23-4136-9eab-b579d2930817</uuid>
+  <memory unit='KiB'>524288</memory>
+  <currentMemory unit='KiB'>524288</currentMemory>
+  <vcpu placement='static'>2</vcpu>
+  <os>
+    <type arch='x86_64' machine='xenfv'>hvm</type>
+    <loader type='rom'>/usr/lib/xen/boot/hvmloader</loader>
+    <boot dev='cdrom'/>
+    <boot dev='hd'/>
+  </os>
+  <features>
+    <acpi/>
+    <apic/>
+    <pae/>
+    <viridian/>
+  </features>
+  <clock offset='variable' adjustment='0' basis='localtime'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>destroy</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator type='stubdom'>/usr/lib/xen/bin/qemu-dm</emulator>
+    <disk type='file' device='disk'>
+      <driver name='file'/>
+      <source file='/var/lib/libvirt/images/testhvm/root.img'/>
+      <target dev='xvda' bus='xen'/>
+    </disk>
+    <disk type='file' device='disk'>
+      <driver name='file'/>
+      <source file='/var/lib/libvirt/images/testhvm/private.img'/>
+      <target dev='xvdb' bus='xen'/>
+    </disk>
+    <interface type='network'>
+      <mac address='00:16:3e:5e:6c:09'/>
+      <source network='default'/>
+    </interface>
+    <input type='tablet' bus='usb'/>
+  </devices>
+</domain>
diff --git a/tests/xlxml2xmldata/xlxml2xml-hvm.xml b/tests/xlxml2xmldata/xlxml2xml-hvm.xml
new file mode 100644
index 0000000..95d9b84
--- /dev/null
+++ b/tests/xlxml2xmldata/xlxml2xml-hvm.xml
@@ -0,0 +1,40 @@
+<domain type='xen'>
+  <name>testhvm</name>
+  <uuid>a3d3fa04-dc23-4136-9eab-b579d2930817</uuid>
+  <memory unit='KiB'>524288</memory>
+  <currentMemory unit='KiB'>524288</currentMemory>
+  <vcpu placement='static'>2</vcpu>
+  <os>
+    <type arch='x86_64' machine='xenfv'>hvm</type>
+    <loader type='rom'>/usr/lib/xen/boot/hvmloader</loader>
+    <boot dev='cdrom'/>
+    <boot dev='hd'/>
+  </os>
+  <features>
+    <acpi/>
+    <apic/>
+    <pae/>
+    <viridian/>
+  </features>
+  <clock offset='variable' adjustment='0' basis='localtime'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>destroy</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='file' device='disk'>
+      <driver name='file'/>
+      <source file='/var/lib/libvirt/images/testhvm/root.img'/>
+      <target dev='xvda' bus='xen'/>
+    </disk>
+    <disk type='file' device='disk'>
+      <driver name='file'/>
+      <source file='/var/lib/libvirt/images/testhvm/private.img'/>
+      <target dev='xvdb' bus='xen'/>
+    </disk>
+    <interface type='network'>
+      <mac address='00:16:3e:5e:6c:09'/>
+      <source network='default'/>
+    </interface>
+    <input type='tablet' bus='usb'/>
+  </devices>
+</domain>
diff --git a/tests/xlxml2xmldata/xlxml2xml-network-bridged.xml b/tests/xlxml2xmldata/xlxml2xml-network-bridged.xml
new file mode 100644
index 0000000..a6b8f59
--- /dev/null
+++ b/tests/xlxml2xmldata/xlxml2xml-network-bridged.xml
@@ -0,0 +1,38 @@
+<domain type='xen'>
+  <name>testvm</name>
+  <uuid>900e3685-4998-41ad-a2c9-e496a5ed40a4</uuid>
+  <memory unit='KiB'>4096000</memory>
+  <currentMemory unit='KiB'>409600</currentMemory>
+  <vcpu placement='static'>2</vcpu>
+  <os>
+    <type arch='x86_64' machine='xenpv'>linux</type>
+    <kernel>/boot/vmlinuz-3.12.37-1</kernel>
+    <initrd>/boot/initramfs-3.12.37-1.img</initrd>
+    <cmdline>root=/dev/xvda ro nomodeset console=hvc0 rd_NO_PLYMOUTH 3</cmdline>
+  </os>
+  <clock offset='utc' adjustment='reset'>
+    <timer name='tsc' mode='native'/>
+  </clock>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>destroy</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='file' device='disk'>
+      <driver name='file'/>
+      <source file='/var/lib/libvirt/images/testvm/root.img'/>
+      <target dev='xvda' bus='xen'/>
+    </disk>
+    <disk type='block' device='disk'>
+      <driver name='file'/>
+      <source dev='/var/lib/libvirt/images/testvm/home.img'/>
+      <target dev='xvdb' bus='xen'/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='00:16:3e:5e:6c:09'/>
+      <source bridge='xenbr0'/>
+    </interface>
+    <console type='pty'>
+      <target type='xen' port='0'/>
+    </console>
+  </devices>
+</domain>
diff --git a/tests/xlxml2xmldata/xlxml2xml-network-driver-domain.xml b/tests/xlxml2xmldata/xlxml2xml-network-driver-domain.xml
new file mode 100644
index 0000000..31c0437
--- /dev/null
+++ b/tests/xlxml2xmldata/xlxml2xml-network-driver-domain.xml
@@ -0,0 +1,38 @@
+<domain type='xen'>
+  <name>testvm</name>
+  <uuid>900e3685-4998-41ad-a2c9-e496a5ed40a4</uuid>
+  <memory unit='KiB'>4096000</memory>
+  <currentMemory unit='KiB'>409600</currentMemory>
+  <vcpu placement='static'>2</vcpu>
+  <os>
+    <type arch='x86_64' machine='xenpv'>linux</type>
+    <kernel>/boot/vmlinuz-3.12.37-1</kernel>
+    <initrd>/boot/initramfs-3.12.37-1.img</initrd>
+    <cmdline>root=/dev/xvda ro nomodeset console=hvc0 rd_NO_PLYMOUTH 3</cmdline>
+  </os>
+  <clock offset='utc' adjustment='reset'>
+    <timer name='tsc' mode='native'/>
+  </clock>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>destroy</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='file' device='disk'>
+      <driver name='file'/>
+      <source file='/var/lib/libvirt/images/testvm/root.img'/>
+      <target dev='xvda' bus='xen'/>
+    </disk>
+    <disk type='block' device='disk'>
+      <driver name='file'/>
+      <source dev='/var/lib/libvirt/images/testvm/home.img'/>
+      <target dev='xvdb' bus='xen'/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='00:16:3e:5e:6c:09'/>
+      <source bridge='xenbr0' domain='netvm'/>
+    </interface>
+    <console type='pty'>
+      <target type='xen' port='0'/>
+    </console>
+  </devices>
+</domain>
diff --git a/tests/xlxml2xmldata/xlxml2xml-network-routed.xml b/tests/xlxml2xmldata/xlxml2xml-network-routed.xml
new file mode 100644
index 0000000..fac9d8d
--- /dev/null
+++ b/tests/xlxml2xmldata/xlxml2xml-network-routed.xml
@@ -0,0 +1,39 @@
+<domain type='xen'>
+  <name>testvm</name>
+  <uuid>900e3685-4998-41ad-a2c9-e496a5ed40a4</uuid>
+  <memory unit='KiB'>4096000</memory>
+  <currentMemory unit='KiB'>409600</currentMemory>
+  <vcpu placement='static'>2</vcpu>
+  <os>
+    <type arch='x86_64' machine='xenpv'>linux</type>
+    <kernel>/boot/vmlinuz-3.12.37-1</kernel>
+    <initrd>/boot/initramfs-3.12.37-1.img</initrd>
+    <cmdline>root=/dev/xvda ro nomodeset console=hvc0 rd_NO_PLYMOUTH 3</cmdline>
+  </os>
+  <clock offset='utc' adjustment='reset'>
+    <timer name='tsc' mode='native'/>
+  </clock>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>destroy</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='file' device='disk'>
+      <driver name='file'/>
+      <source file='/var/lib/libvirt/images/testvm/root.img'/>
+      <target dev='xvda' bus='xen'/>
+    </disk>
+    <disk type='block' device='disk'>
+      <driver name='file'/>
+      <source dev='/var/lib/libvirt/images/testvm/home.img'/>
+      <target dev='xvdb' bus='xen'/>
+    </disk>
+    <interface type='ethernet'>
+      <mac address='00:16:3e:5e:6c:09'/>
+      <ip address='192.168.0.1' family='ipv4'/>
+      <script path='vif-route'/>
+    </interface>
+    <console type='pty'>
+      <target type='xen' port='0'/>
+    </console>
+  </devices>
+</domain>
diff --git a/tests/xlxml2xmldata/xlxml2xml-pv.xml b/tests/xlxml2xmldata/xlxml2xml-pv.xml
new file mode 100644
index 0000000..b937b8b
--- /dev/null
+++ b/tests/xlxml2xmldata/xlxml2xml-pv.xml
@@ -0,0 +1,38 @@
+<domain type='xen'>
+  <name>testvm</name>
+  <uuid>900e3685-4998-41ad-a2c9-e496a5ed40a4</uuid>
+  <memory unit='KiB'>4096000</memory>
+  <currentMemory unit='KiB'>409600</currentMemory>
+  <vcpu placement='static'>2</vcpu>
+  <os>
+    <type arch='x86_64' machine='xenpv'>linux</type>
+    <kernel>/boot/vmlinuz-3.12.37-1</kernel>
+    <initrd>/boot/initramfs-3.12.37-1.img</initrd>
+    <cmdline>root=/dev/xvda ro nomodeset console=hvc0 rd_NO_PLYMOUTH 3</cmdline>
+  </os>
+  <clock offset='utc' adjustment='reset'>
+    <timer name='tsc' mode='native'/>
+  </clock>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>destroy</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='file' device='disk'>
+      <driver name='file'/>
+      <source file='/var/lib/libvirt/images/testvm/root.img'/>
+      <target dev='xvda' bus='xen'/>
+    </disk>
+    <disk type='block' device='disk'>
+      <driver name='file'/>
+      <source dev='/var/lib/libvirt/images/testvm/home.img'/>
+      <target dev='xvdb' bus='xen'/>
+    </disk>
+    <interface type='network'>
+      <mac address='00:16:3e:5e:6c:09'/>
+      <source network='default'/>
+    </interface>
+    <console type='pty'>
+      <target type='xen' port='0'/>
+    </console>
+  </devices>
+</domain>
diff --git a/tests/xlxml2xmltest.c b/tests/xlxml2xmltest.c
new file mode 100644
index 0000000..131e43b
--- /dev/null
+++ b/tests/xlxml2xmltest.c
@@ -0,0 +1,189 @@
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include "testutils.h"
+
+#ifdef WITH_LIBXL
+
+# include "internal.h"
+# include "libxl/libxl_conf.h"
+# include "libxl/libxl_domain.h"
+# include "testutilsxen.h"
+# include "virstring.h"
+
+# define VIR_FROM_THIS VIR_FROM_NONE
+
+static virCapsPtr caps;
+static virDomainXMLOptionPtr xmlopt;
+
+static int
+testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live)
+{
+    char *inXmlData = NULL;
+    char *outXmlData = NULL;
+    char *actual = NULL;
+    int ret = -1;
+    virDomainDefPtr def = NULL;
+    unsigned int parse_flags = live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE;
+    unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE;
+    if (!live)
+        format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE;
+
+    if (virtTestLoadFile(inxml, &inXmlData) < 0)
+        goto fail;
+    if (virtTestLoadFile(outxml, &outXmlData) < 0)
+        goto fail;
+
+    if (!(def = virDomainDefParseString(inXmlData, caps, xmlopt,
+                                        1 << VIR_DOMAIN_VIRT_XEN, parse_flags)))
+        goto fail;
+
+    if (!virDomainDefCheckABIStability(def, def)) {
+        fprintf(stderr, "ABI stability check failed on %s", inxml);
+        goto fail;
+    }
+
+    if (!(actual = virDomainDefFormat(def, format_flags)))
+        goto fail;
+
+    if (STRNEQ(outXmlData, actual)) {
+        virtTestDifferenceFull(stderr, outXmlData, outxml, actual, inxml);
+        goto fail;
+    }
+
+    ret = 0;
+ fail:
+    VIR_FREE(inXmlData);
+    VIR_FREE(outXmlData);
+    VIR_FREE(actual);
+    virDomainDefFree(def);
+    return ret;
+}
+
+enum {
+    WHEN_INACTIVE = 1,
+    WHEN_ACTIVE = 2,
+    WHEN_EITHER = 3,
+};
+
+struct testInfo {
+    const char *name;
+    bool different;
+    int when;
+};
+
+static int
+testCompareXMLToXMLHelper(const void *data)
+{
+    const struct testInfo *info = data;
+    char *xml_in = NULL;
+    char *xml_out = NULL;
+    char *xml_out_active = NULL;
+    char *xml_out_inactive = NULL;
+    int ret = -1;
+
+    if (virAsprintf(&xml_in, "%s/xlxml2xmldata/xlxml2xml-%s.xml",
+                    abs_srcdir, info->name) < 0 ||
+        virAsprintf(&xml_out, "%s/xlxml2xmldata/xlxml2xml-%s-out.xml",
+                    abs_srcdir, info->name) < 0 ||
+        virAsprintf(&xml_out_active,
+                    "%s/xlxml2xmldata/xlxml2xml-%s-active.xml",
+                    abs_srcdir, info->name) < 0 ||
+        virAsprintf(&xml_out_inactive,
+                    "%s/xlxml2xmldata/xlxml2xml-%s-inactive.xml",
+                    abs_srcdir, info->name) < 0)
+        goto cleanup;
+
+    if ((info->when & WHEN_INACTIVE)) {
+        char *out;
+        if (!info->different)
+            out = xml_in;
+        else if (virFileExists(xml_out_inactive))
+            out = xml_out_inactive;
+        else
+            out = xml_out;
+
+        if (testCompareXMLToXMLFiles(xml_in, out, false) < 0)
+            goto cleanup;
+    }
+
+    if ((info->when & WHEN_ACTIVE)) {
+        char *out;
+        if (!info->different)
+            out = xml_in;
+        else if (virFileExists(xml_out_active))
+            out = xml_out_active;
+        else
+            out = xml_out;
+
+        if (testCompareXMLToXMLFiles(xml_in, out, true) < 0)
+            goto cleanup;
+    }
+
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(xml_in);
+    VIR_FREE(xml_out);
+    VIR_FREE(xml_out_active);
+    VIR_FREE(xml_out_inactive);
+    return ret;
+}
+
+
+static int
+mymain(void)
+{
+    int ret = 0;
+
+    if ((caps = testXLInitCaps()) == NULL)
+        return EXIT_FAILURE;
+
+    if (!(xmlopt = libxlCreateXMLConf()))
+        return EXIT_FAILURE;
+
+# define DO_TEST_FULL(name, is_different, when)                         \
+    do {                                                                \
+        const struct testInfo info = {name, is_different, when};        \
+        if (virtTestRun("LibXL XML-2-XML " name,                         \
+                        testCompareXMLToXMLHelper, &info) < 0)          \
+            ret = -1;                                                   \
+    } while (0)
+
+# define DO_TEST(name) \
+    DO_TEST_FULL(name, false, WHEN_EITHER)
+
+# define DO_TEST_DIFFERENT(name) \
+    DO_TEST_FULL(name, true, WHEN_EITHER)
+
+    DO_TEST("hvm");
+    DO_TEST("pv");
+    DO_TEST("hvm-stubdom");
+    DO_TEST("network-bridged");
+    DO_TEST("network-routed");
+    DO_TEST("network-driver-domain");
+
+    virObjectUnref(caps);
+    virObjectUnref(xmlopt);
+
+    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIRT_TEST_MAIN(mymain)
+
+#else
+
+int
+main(void)
+{
+    return EXIT_AM_SKIP;
+}
+
+#endif /* WITH_LIBXL */
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]