testQemuInfoSetArgs: Always allocate 'info->qemuCaps'

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>
This commit is contained in:
Peter Krempa 2021-08-16 16:42:18 +02:00
parent e817d1938a
commit 767f4e5f72

View File

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