]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: qemuxml2argv: Allow testing of config processed at startup
authorPeter Krempa <pkrempa@redhat.com>
Tue, 27 Mar 2018 09:11:01 +0000 (11:11 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 3 Apr 2018 13:48:38 +0000 (15:48 +0200)
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@redhat.com>
tests/Makefile.am
tests/qemuxml2argvtest.c
tests/qemuxml2startupxmloutdata/disk-drive-shared.xml [new file with mode: 0644]

index 289ef35bddaa435e009ab914265c297b5703b576..f2f5caed4f3357cc8b39de74fa31261b34c7b82e 100644 (file)
@@ -127,6 +127,7 @@ EXTRA_DIST = \
        qemuhotplugtestdomains \
        qemumonitorjsondata \
        qemuxml2argvdata \
+       qemuxml2startupxmloutdata \
        qemuxml2xmloutdata \
        qemustatusxml2xmldata \
        qemuqapischema.json \
index 896d104593cf4c700e0f4493f2d60c1d5086dc2d..d79913dd0aac64125d4fddbc685d00152fab5eda 100644 (file)
@@ -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 (file)
index 0000000..f4d2871
--- /dev/null
@@ -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>