]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
testQemuInfoSetArgs: Always allocate 'info->qemuCaps'
authorPeter Krempa <pkrempa@redhat.com>
Mon, 16 Aug 2021 14:42:18 +0000 (16:42 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 18 Aug 2021 08:20:48 +0000 (10:20 +0200)
Modify the logic so that 'info->qemuCaps' is populated, but empty even
when ARG_QEMU_CAPS was not used. The function still retains the
interlocking of fake caps with real caps.

A lot of the internal code expects qemuCaps to be populated and many
tests work this around by using ARG_QEMU_CAPS with no caps.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/testutilsqemu.c

index 9a0666724a85cba156cb9f97faff6c5547404e57..32119e30c2b8aeb7cb51e3a7107c683ae3c55427 100644 (file)
@@ -684,7 +684,8 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
 {
     va_list argptr;
     testQemuInfoArgName argname;
-    virQEMUCaps *qemuCaps = NULL;
+    g_autoptr(virQEMUCaps) fakeCaps = virQEMUCapsNew();
+    bool fakeCapsUsed = false;
     int gic = GIC_NONE;
     char *capsarch = NULL;
     char *capsver = NULL;
@@ -692,16 +693,18 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
     int flag;
     int ret = -1;
 
+    if (!fakeCaps)
+        abort();
+
     va_start(argptr, capslatest);
     argname = va_arg(argptr, testQemuInfoArgName);
     while (argname != ARG_END) {
         switch (argname) {
         case ARG_QEMU_CAPS:
-            if (qemuCaps || !(qemuCaps = virQEMUCapsNew()))
-                goto cleanup;
+            fakeCapsUsed = true;
 
             while ((flag = va_arg(argptr, int)) < QEMU_CAPS_LAST)
-                virQEMUCapsSet(qemuCaps, flag);
+                virQEMUCapsSet(fakeCaps, flag);
 
             /* Some tests are run with NONE capabilities, which is just
              * another name for QEMU_CAPS_LAST. If that is the case the
@@ -764,16 +767,16 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
         goto cleanup;
     }
 
-    if (qemuCaps && (capsarch || capsver)) {
-        fprintf(stderr, "ARG_QEMU_CAPS can not be combined with ARG_CAPS_ARCH "
-                        "or ARG_CAPS_VER\n");
-        goto cleanup;
-    }
-
-    if (!qemuCaps && capsarch && capsver) {
+    if (capsarch && capsver) {
         bool stripmachinealiases = false;
         virQEMUCaps *cachedcaps = NULL;
 
+        if (fakeCapsUsed) {
+            fprintf(stderr, "ARG_QEMU_CAPS can not be combined with ARG_CAPS_ARCH "
+                    "or ARG_CAPS_VER\n");
+            goto cleanup;
+        }
+
         info->arch = virArchFromString(capsarch);
 
         if (STREQ(capsver, "latest")) {
@@ -785,40 +788,33 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
         }
 
         if (!g_hash_table_lookup_extended(capscache, capsfile, NULL, (void **) &cachedcaps)) {
-            if (!(qemuCaps = qemuTestParseCapabilitiesArch(info->arch, capsfile)))
+            if (!(cachedcaps = qemuTestParseCapabilitiesArch(info->arch, capsfile)))
                 goto cleanup;
 
-            cachedcaps = qemuCaps;
-
-            g_hash_table_insert(capscache, g_strdup(capsfile), g_steal_pointer(&qemuCaps));
+            g_hash_table_insert(capscache, g_strdup(capsfile), cachedcaps);
         }
 
-        if (!(qemuCaps = virQEMUCapsNewCopy(cachedcaps)))
+        if (!(info->qemuCaps = virQEMUCapsNewCopy(cachedcaps)))
             goto cleanup;
 
         if (stripmachinealiases)
-            virQEMUCapsStripMachineAliases(qemuCaps);
+            virQEMUCapsStripMachineAliases(info->qemuCaps);
 
         info->flags |= FLAG_REAL_CAPS;
 
         /* provide path to the replies file for schema testing */
         capsfile[strlen(capsfile) - 3] = '\0';
         info->schemafile = g_strdup_printf("%sreplies", capsfile);
+    } else {
+        info->qemuCaps = g_steal_pointer(&fakeCaps);
     }
 
-    if (!qemuCaps) {
-        fprintf(stderr, "No qemuCaps generated\n");
-        goto cleanup;
-    }
-    info->qemuCaps = g_steal_pointer(&qemuCaps);
-
     if (gic != GIC_NONE && testQemuCapsSetGIC(info->qemuCaps, gic) < 0)
         goto cleanup;
 
     ret = 0;
 
  cleanup:
-    virObjectUnref(qemuCaps);
     va_end(argptr);
 
     return ret;