]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
testutilsqemu: Rework setting of fake capabilities
authorPeter Krempa <pkrempa@redhat.com>
Fri, 3 Mar 2023 12:07:41 +0000 (13:07 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 6 Mar 2023 19:55:50 +0000 (20:55 +0100)
Rather that populate a virQEMUCaps object we now populate a bitmap with
the fake capabilities and transfer it into the virQEMUCaps later.

This unifies the code paths between the fully fake caps tests and real
caps + fake flags.

Also the same approach will be used in upcomming patch to add
possibility to mask out flags from real capabilities.

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

index 7dd7caf5096d2c0e0c028912f122a1400a505704..d3b5067f64799faa0bab75524573fa52cfe122da 100644 (file)
@@ -889,8 +889,6 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
     testQemuInfoArgName argname;
     int flag;
 
-    info->args.fakeCaps = virQEMUCapsNew();
-
     info->conf = conf;
     info->args.newargs = true;
 
@@ -898,10 +896,11 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
     while ((argname = va_arg(argptr, testQemuInfoArgName)) != ARG_END) {
         switch (argname) {
         case ARG_QEMU_CAPS:
-            info->args.fakeCapsUsed = true;
+            if (!(info->args.fakeCapsAdd))
+                info->args.fakeCapsAdd = virBitmapNew(QEMU_CAPS_LAST);
 
             while ((flag = va_arg(argptr, int)) < QEMU_CAPS_LAST)
-                virQEMUCapsSet(info->args.fakeCaps, flag);
+                ignore_value(virBitmapSetBit(info->args.fakeCapsAdd, flag));
             break;
 
         case ARG_GIC:
@@ -990,6 +989,7 @@ int
 testQemuInfoInitArgs(struct testQemuInfo *info)
 {
     g_autofree char *capsfile = NULL;
+    ssize_t cap;
 
     if (!info->args.newargs)
         return 0;
@@ -1037,16 +1037,6 @@ testQemuInfoInitArgs(struct testQemuInfo *info)
 
         info->qemuCaps = virQEMUCapsNewCopy(cachedcaps);
 
-        if (info->args.fakeCapsUsed) {
-            size_t i;
-            for (i = 0; i < QEMU_CAPS_LAST; i++) {
-                if (virQEMUCapsGet(info->args.fakeCaps, i)) {
-                    virQEMUCapsSet(info->qemuCaps, i);
-                }
-            }
-        }
-
-
         if (stripmachinealiases)
             virQEMUCapsStripMachineAliases(info->qemuCaps);
 
@@ -1056,9 +1046,12 @@ testQemuInfoInitArgs(struct testQemuInfo *info)
         capsfile[strlen(capsfile) - 3] = '\0';
         info->schemafile = g_strdup_printf("%sreplies", capsfile);
     } else {
-        info->qemuCaps = g_steal_pointer(&info->args.fakeCaps);
+        info->qemuCaps = virQEMUCapsNew();
     }
 
+    for (cap = -1; (cap = virBitmapNextSetBit(info->args.fakeCapsAdd, cap)) >= 0;)
+        virQEMUCapsSet(info->qemuCaps, cap);
+
     if (info->args.gic != GIC_NONE &&
         testQemuCapsSetGIC(info->qemuCaps, info->args.gic) < 0)
         return -1;
@@ -1075,7 +1068,7 @@ testQemuInfoClear(struct testQemuInfo *info)
     VIR_FREE(info->schemafile);
     VIR_FREE(info->errfile);
     virObjectUnref(info->qemuCaps);
-    g_clear_pointer(&info->args.fakeCaps, virObjectUnref);
+    g_clear_pointer(&info->args.fakeCapsAdd, virBitmapFree);
     g_clear_pointer(&info->args.fds, g_hash_table_unref);
 }
 
index 51c072cb13795f20e18b622fcbc0b3342155d0d6..f272e6d41d4bc03a85fafbe7cb5ccee279411bec 100644 (file)
@@ -81,8 +81,7 @@ typedef enum {
 
 struct testQemuArgs {
     bool newargs;
-    virQEMUCaps *fakeCaps;
-    bool fakeCapsUsed;
+    virBitmap *fakeCapsAdd;
     char *capsver;
     char *capsarch;
     qemuTestCPUDef capsHostCPUModel;