]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuxml2argvtest: Parse 'arch' from XML early
authorPeter Krempa <pkrempa@redhat.com>
Fri, 9 Apr 2021 13:18:41 +0000 (15:18 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 12 Apr 2021 14:09:42 +0000 (16:09 +0200)
If we want to provide correct (fake) caps already for the XML parser we
need to be able to parse the arch early so that we can properly
initialize the caps cache prior to calling the XML parser.

This patch adds code which parses the arch and updates the caps cache
prior to the parse step.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
tests/qemuxml2argvtest.c

index 60f833d1ac02d229b7f798d31f92ca13a091cb01..317ee3267d7d12b34b7c6a4a399f58f4c31d18da 100644 (file)
@@ -353,13 +353,13 @@ testAddCPUModels(virQEMUCapsPtr caps, bool skipLegacy)
 
 static int
 testUpdateQEMUCaps(const struct testQemuInfo *info,
-                   virDomainObjPtr vm,
+                   virArch arch,
                    virCapsPtr caps)
 {
     if (!caps)
         return -1;
 
-    virQEMUCapsSetArch(info->qemuCaps, vm->def->os.arch);
+    virQEMUCapsSetArch(info->qemuCaps, arch);
 
     virQEMUCapsInitQMPBasicArch(info->qemuCaps);
 
@@ -648,6 +648,8 @@ testCompareXMLToArgv(const void *data)
     g_autoptr(xmlDoc) xml = NULL;
     g_autoptr(xmlXPathContext) ctxt = NULL;
     xmlNodePtr root;
+    g_autofree char *archstr = NULL;
+    virArch arch = VIR_ARCH_NONE;
 
     if (info->arch != VIR_ARCH_NONE && info->arch != VIR_ARCH_X86_64)
         qemuTestSetHostArch(&driver, info->arch);
@@ -686,6 +688,17 @@ testCompareXMLToArgv(const void *data)
 
     ctxt->node = root;
 
+    if ((archstr = virXPathString("string(./os/type[1]/@arch)", ctxt))) {
+        if ((arch = virArchFromString(archstr)) == VIR_ARCH_NONE) {
+            arch = virArchFromHost();
+        }
+    }
+
+    if (!(info->flags & FLAG_REAL_CAPS)) {
+        if (testUpdateQEMUCaps(info, arch, driver.caps) < 0)
+            goto cleanup;
+    }
+
     if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) < 0)
         goto cleanup;
 
@@ -739,7 +752,7 @@ testCompareXMLToArgv(const void *data)
         goto cleanup;
 
     if (!(info->flags & FLAG_REAL_CAPS)) {
-        if (testUpdateQEMUCaps(info, vm, driver.caps) < 0)
+        if (testUpdateQEMUCaps(info, vm->def->os.arch, driver.caps) < 0)
             goto cleanup;
         if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) < 0)
             goto cleanup;