Some parts of qemuCaps depend on guest architecture, machine type, and
possibly other things that we know only once the domain XML has been
parsed. Let's move all these updates into a dedicated function.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
tests/qemuxml2argvtest.c | 48 +++++++++++++++++++++++++++++++-----------------
1 file changed, 31 insertions(+), 17 deletions(-)
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 82926db..9e9db6e 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -272,6 +272,7 @@ struct testInfo {
int migrateFd;
unsigned int flags;
unsigned int parseFlags;
+ bool skipLegacyCPUs;
};
@@ -305,17 +306,15 @@ testAddCPUModels(virQEMUCapsPtr caps, bool skipLegacy)
static int
-testPrepareExtraFlags(struct testInfo *info,
- bool skipLegacyCPUs,
- int gic)
+testInitQEMUCaps(struct testInfo *info,
+ int gic)
{
int ret = -1;
if (!(info->qemuCaps = virQEMUCapsNew()))
goto cleanup;
- if (testAddCPUModels(info->qemuCaps, skipLegacyCPUs) < 0)
- goto cleanup;
+ virQEMUCapsSet(info->qemuCaps, QEMU_CAPS_NO_ACPI);
if (testQemuCapsSetGIC(info->qemuCaps, gic) < 0)
goto cleanup;
@@ -328,6 +327,27 @@ testPrepareExtraFlags(struct testInfo *info,
static int
+testUpdateQEMUCaps(const struct testInfo *info,
+ virDomainObjPtr vm)
+{
+ int ret = -1;
+
+ if (testAddCPUModels(info->qemuCaps, info->skipLegacyCPUs) < 0)
+ goto cleanup;
+
+ virQEMUCapsFilterByMachineType(info->qemuCaps, vm->def->os.machine);
+
+ if (ARCH_IS_X86(vm->def->os.arch))
+ virQEMUCapsSet(info->qemuCaps, QEMU_CAPS_PCI_MULTIBUS);
+
+ ret = 0;
+
+ cleanup:
+ return ret;
+}
+
+
+static int
testCompareXMLToArgv(const void *data)
{
const struct testInfo *info = data;
@@ -400,10 +420,6 @@ testCompareXMLToArgv(const void *data)
if (qemuProcessPrepareMonitorChr(&monitor_chr, priv->libDir) < 0)
goto cleanup;
- virQEMUCapsSetList(info->qemuCaps,
- QEMU_CAPS_NO_ACPI,
- QEMU_CAPS_LAST);
-
if (STREQ(vm->def->os.machine, "pc") &&
STREQ(vm->def->emulator, "/usr/bin/qemu-system-x86_64")) {
VIR_FREE(vm->def->os.machine);
@@ -411,17 +427,13 @@ testCompareXMLToArgv(const void *data)
goto cleanup;
}
- virQEMUCapsFilterByMachineType(info->qemuCaps, vm->def->os.machine);
+ if (testUpdateQEMUCaps(info, vm) < 0)
+ goto cleanup;
log = virTestLogContentAndReset();
VIR_FREE(log);
virResetLastError();
- if (vm->def->os.arch == VIR_ARCH_X86_64 ||
- vm->def->os.arch == VIR_ARCH_I686) {
- virQEMUCapsSet(info->qemuCaps, QEMU_CAPS_PCI_MULTIBUS);
- }
-
for (i = 0; i < vm->def->nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = vm->def->hostdevs[i];
@@ -530,9 +542,11 @@ mymain(void)
parseFlags, gic, ...) \
do { \
static struct testInfo info = { \
- name, NULL, migrateFrom, migrateFd, (flags), parseFlags \
+ name, NULL, migrateFrom, migrateFd, (flags), parseFlags, \
+ false \
}; \
- if (testPrepareExtraFlags(&info, skipLegacyCPUs, gic) < 0) \
+ info.skipLegacyCPUs = skipLegacyCPUs; \
+ if (testInitQEMUCaps(&info, gic) < 0) \
return EXIT_FAILURE; \
virQEMUCapsSetList(info.qemuCaps, __VA_ARGS__, QEMU_CAPS_LAST); \
if (virTestRun("QEMU XML-2-ARGV " name, \
--
2.9.2