From: Peter Krempa Date: Fri, 3 Mar 2023 12:07:41 +0000 (+0100) Subject: testutilsqemu: Rework setting of fake capabilities X-Git-Tag: v9.2.0-rc1~163 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce79cf6ab4edf16aad47e7d50388679b61393e34;p=thirdparty%2Flibvirt.git testutilsqemu: Rework setting of fake capabilities 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 Reviewed-by: Ján Tomko --- diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 7dd7caf509..d3b5067f64 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -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); } diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index 51c072cb13..f272e6d41d 100644 --- a/tests/testutilsqemu.h +++ b/tests/testutilsqemu.h @@ -81,8 +81,7 @@ typedef enum { struct testQemuArgs { bool newargs; - virQEMUCaps *fakeCaps; - bool fakeCapsUsed; + virBitmap *fakeCapsAdd; char *capsver; char *capsarch; qemuTestCPUDef capsHostCPUModel;