From 767f4e5f72c7ba577e55ace36b98f2fe43b7247a Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 16 Aug 2021 16:42:18 +0200 Subject: [PATCH] testQemuInfoSetArgs: Always allocate 'info->qemuCaps' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Ján Tomko --- tests/testutilsqemu.c | 44 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 9a0666724a..32119e30c2 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -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;