[RFC PATCH 18/43] qemuxml2argvtest: Parse 'arch' from XML early

Peter Krempa pkrempa at redhat.com
Fri Apr 9 14:56:54 UTC 2021


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 at redhat.com>
---
 tests/qemuxml2argvtest.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index aa6ae9bb4b..eb1bec88f2 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -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;
-- 
2.30.2




More information about the libvir-list mailing list