[PATCH 13/14] tests: qemuxml2argv: Allow testing of config processed at startup

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

 



Add a new kind of XML output test for the files in qemuxml2argvtest
where we can validate setup and defaults applied when starting up the
VM.

This is achieved by formatting of the definition processed by the
qemuxml2argvtest into a XML and it's compared against files in
qemuxml2startupxmloutdata. This test is automatically executed if the
output file is present and it's skipped otherwise.

The first example test case is created from 'disk-drive-shared' test
case.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 tests/Makefile.am                                  |  1 +
 tests/qemuxml2argvtest.c                           | 42 +++++++++++++++-
 .../disk-drive-shared.xml                          | 56 ++++++++++++++++++++++
 3 files changed, 97 insertions(+), 2 deletions(-)
 create mode 100644 tests/qemuxml2startupxmloutdata/disk-drive-shared.xml

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 289ef35bdd..f2f5caed4f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -127,6 +127,7 @@ EXTRA_DIST = \
 	qemuhotplugtestdomains \
 	qemumonitorjsondata \
 	qemuxml2argvdata \
+	qemuxml2startupxmloutdata \
 	qemuxml2xmloutdata \
 	qemustatusxml2xmldata \
 	qemuqapischema.json \
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 896d104593..7e7a937c8d 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -277,6 +277,7 @@ struct testInfo {
     unsigned int flags;
     unsigned int parseFlags;
     bool skipLegacyCPUs;
+    virDomainObjPtr vm;
 };


@@ -402,9 +403,39 @@ testUpdateQEMUCaps(const struct testInfo *info,


 static int
-testCompareXMLToArgv(const void *data)
+testCompareXMLToStartupXML(const void *data)
 {
     const struct testInfo *info = data;
+    unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE;
+    char *xml = NULL;
+    char *actual = NULL;
+    int ret = -1;
+
+    if (virAsprintf(&xml, "%s/qemuxml2startupxmloutdata/%s.xml",
+                    abs_srcdir, info->name) < 0)
+        goto cleanup;
+
+    if (!virFileExists(xml)) {
+        ret = EXIT_AM_SKIP;
+        goto cleanup;
+    }
+
+    if (!(actual = virDomainDefFormat(info->vm->def, NULL, format_flags)))
+        goto cleanup;
+
+    ret =  virTestCompareToFile(actual, xml);
+
+ cleanup:
+    VIR_FREE(xml);
+    VIR_FREE(actual);
+    return ret;
+}
+
+
+static int
+testCompareXMLToArgv(const void *data)
+{
+    struct testInfo *info = (void *) data;
     char *xml = NULL;
     char *args = NULL;
     char *migrateURI = NULL;
@@ -532,6 +563,9 @@ testCompareXMLToArgv(const void *data)
         ret = 0;
     }

+    if (!(flags & FLAG_EXPECT_FAILURE) && ret == 0)
+        VIR_STEAL_PTR(info->vm, vm);
+
  cleanup:
     VIR_FREE(log);
     VIR_FREE(actualargv);
@@ -625,7 +659,7 @@ mymain(void)
     do { \
         static struct testInfo info = { \
             name, NULL, migrateFrom, migrateFd, (flags), parseFlags, \
-            false \
+            false, NULL \
         }; \
         info.skipLegacyCPUs = skipLegacyCPUs; \
         if (testInitQEMUCaps(&info, gic) < 0) \
@@ -634,7 +668,11 @@ mymain(void)
         if (virTestRun("QEMU XML-2-ARGV " name, \
                        testCompareXMLToArgv, &info) < 0) \
             ret = -1; \
+        if (info.vm && virTestRun("QEMU XML-2-startup-XML " name, \
+                                  testCompareXMLToStartupXML, &info) < 0) \
+            ret = -1; \
         virObjectUnref(info.qemuCaps); \
+        virObjectUnref(info.vm); \
     } while (0)

 # define DO_TEST(name, ...) \
diff --git a/tests/qemuxml2startupxmloutdata/disk-drive-shared.xml b/tests/qemuxml2startupxmloutdata/disk-drive-shared.xml
new file mode 100644
index 0000000000..f4d2871ae7
--- /dev/null
+++ b/tests/qemuxml2startupxmloutdata/disk-drive-shared.xml
@@ -0,0 +1,56 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <emulator>/usr/bin/qemu-system-i686</emulator>
+    <disk type='block' device='disk'>
+      <driver name='qemu' type='raw'/>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+      <shareable/>
+      <serial>XYZXYZXYZYXXYZYZYXYZY</serial>
+      <alias name='ide0-0-0'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <disk type='block' device='cdrom'>
+      <driver name='qemu' type='raw'/>
+      <source dev='/dev/HostVG/QEMUGuest2'/>
+      <target dev='hdc' bus='ide'/>
+      <readonly/>
+      <alias name='ide0-1-0'/>
+      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
+    </disk>
+    <controller type='usb' index='0'>
+      <alias name='usb'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+    </controller>
+    <controller type='ide' index='0'>
+      <alias name='ide'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+    </controller>
+    <controller type='pci' index='0' model='pci-root'>
+      <alias name='pci.0'/>
+    </controller>
+    <input type='mouse' bus='ps2'>
+      <alias name='input0'/>
+    </input>
+    <input type='keyboard' bus='ps2'>
+      <alias name='input1'/>
+    </input>
+    <memballoon model='virtio'>
+      <alias name='balloon0'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </memballoon>
+  </devices>
+</domain>
-- 
2.16.2

--
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]

  Powered by Linux