From a678430492eeff2f5b696217e0b8ea68139cfa4a Mon Sep 17 00:00:00 2001 From: Daniel Henrique Barboza Date: Fri, 20 May 2022 10:58:23 -0300 Subject: [PATCH] testutilsqemu: introduce ARG_CAPS_HOST_CPU_MODEL When loading a latest caps for an arch for the first time the following occurs in testQemuInfoInitArgs(): - the caps file is located. It's not in the cache since it's the first time it's being read; - the cachecaps are retrieved using qemuTestParseCapabilitiesArch() and stored in the capscache; - FLAG_REAL_CAPS is set and regular flow continues. Loading the same latest caps for the second time the caps are loaded from the cache, skipping qemuTestParseCapabilitiesArch(). By skipping this function it means that it also skips virQEMUCapsLoadCache() and, more relevant to our case, virQEMUCapsInitHostCPUModel(). This function will use the current arch and cpuModel settings to write the qemuCaps that are being stored in the cache. And we're also setting FLAG_REAL_CAPS, meaning that we won't be updating the qemucaps host model via testUpdateQEMUCaps() as well. This has side-effects such as: - the first time the latest caps for an arch is loaded determines the cpuModel it'll use during the current qemuxml2argvtest run. For example, when running all tests, the first time the latest ppc64 caps are read is on "disk-floppy-pseries" test. Since the current host arch at this point is x86_64, the cpuModel that will be set for this capability is "core2duo"; - every other latest arch test will use the same hostCPU as the first one set since we read it from the cache after the first run. qemuTestSetHostCPU() makes no difference because we won't update the host model due to FLAG_REAL_CAPS being set. Using the previous example, every other latest ppc64 test that will be run will be using the "core2duo" cpuModel. Using fake capabilities (e.g. using DO_TEST()) prevents FLAG_REAL_CAPS to be set, meaning that the cpuModel will be updated using the current settings the test is being ran due to testUpdateQEMUCaps(). Note that not all latest caps arch tests care about the cpuModel being set to an unexpected default cpuModel. But some tests will care, e.g. "pseries-cpu-compat-power9", and changing it from DO_TEST() to DO_TEST_CAPS_ARCH_LATEST() will make it fail every time the "disk-floppy-pseries" is being ran first. One way of fixing it is to rethink all the existing logic, for example not setting FLAG_REAL_CAPS for latest arch tests. Another way is presented here. ARGS_CAPS_HOST_CPU_MODEL is a new testQemuInfo arg that allow us to set any specific host CPU model we want when running latest arch caps tests. This new arg can then be used when converting existing DO_TEST() testcases to DO_TEST_CAPS_ARCH_LATEST() that requires a specific host CPU setting to be successful, which we're going to do in the next patch with "pseries-cpu-compat-power9". Reviewed-by: Martin Kletzander Signed-off-by: Daniel Henrique Barboza --- tests/qemuxml2argvtest.c | 18 ++++++++++++++---- tests/testutilsqemu.c | 4 ++++ tests/testutilsqemu.h | 18 +++++++++--------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index aadfaddc17..96bc7aadeb 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -336,6 +336,12 @@ testAddCPUModels(virQEMUCaps *caps, bool skipLegacy) return 0; } +static void +testUpdateQEMUCapsHostCPUModel(virQEMUCaps *qemuCaps, virArch hostArch) +{ + virQEMUCapsUpdateHostCPUModel(qemuCaps, hostArch, VIR_DOMAIN_VIRT_KVM); + virQEMUCapsUpdateHostCPUModel(qemuCaps, hostArch, VIR_DOMAIN_VIRT_QEMU); +} static int testUpdateQEMUCaps(const struct testQemuInfo *info, @@ -353,10 +359,7 @@ testUpdateQEMUCaps(const struct testQemuInfo *info, !!(info->flags & FLAG_SKIP_LEGACY_CPUS)) < 0) return -1; - virQEMUCapsUpdateHostCPUModel(info->qemuCaps, caps->host.arch, - VIR_DOMAIN_VIRT_KVM); - virQEMUCapsUpdateHostCPUModel(info->qemuCaps, caps->host.arch, - VIR_DOMAIN_VIRT_QEMU); + testUpdateQEMUCapsHostCPUModel(info->qemuCaps, caps->host.arch); return 0; } @@ -650,6 +653,13 @@ testCompareXMLToArgv(const void *data) if (info->arch != VIR_ARCH_NONE && info->arch != VIR_ARCH_X86_64) qemuTestSetHostArch(&driver, info->arch); + if (info->args.capsHostCPUModel) { + virCPUDef *hostCPUModel = qemuTestGetCPUDef(info->args.capsHostCPUModel); + + qemuTestSetHostCPU(&driver, driver.hostarch, hostCPUModel); + testUpdateQEMUCapsHostCPUModel(info->qemuCaps, driver.hostarch); + } + if (!(conn = virGetConnect())) goto cleanup; diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 004c7cf1d6..7e4e5d28b7 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -886,6 +886,10 @@ testQemuInfoSetArgs(struct testQemuInfo *info, info->args.capsver = va_arg(argptr, char *); break; + case ARG_CAPS_HOST_CPU_MODEL: + info->args.capsHostCPUModel = va_arg(argptr, int); + break; + case ARG_HOST_OS: info->args.hostOS = va_arg(argptr, int); break; diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index 99897e6b79..5419b813ea 100644 --- a/tests/testutilsqemu.h +++ b/tests/testutilsqemu.h @@ -47,6 +47,7 @@ typedef enum { ARG_PARSEFLAGS, ARG_CAPS_ARCH, ARG_CAPS_VER, + ARG_CAPS_HOST_CPU_MODEL, ARG_HOST_OS, ARG_END, } testQemuInfoArgName; @@ -66,12 +67,20 @@ struct testQemuConf { GHashTable *qapiSchemaCache; }; +typedef enum { + QEMU_CPU_DEF_DEFAULT, + QEMU_CPU_DEF_HASWELL, + QEMU_CPU_DEF_POWER8, + QEMU_CPU_DEF_POWER9, +} qemuTestCPUDef; + struct testQemuArgs { bool newargs; virQEMUCaps *fakeCaps; bool fakeCapsUsed; char *capsver; char *capsarch; + qemuTestCPUDef capsHostCPUModel; int gic; testQemuHostOS hostOS; bool invalidarg; @@ -101,15 +110,6 @@ virDomainXMLOption *testQemuXMLConfInit(void); virQEMUCaps *qemuTestParseCapabilitiesArch(virArch arch, const char *capsFile); - - -typedef enum { - QEMU_CPU_DEF_DEFAULT, - QEMU_CPU_DEF_HASWELL, - QEMU_CPU_DEF_POWER8, - QEMU_CPU_DEF_POWER9, -} qemuTestCPUDef; - virCPUDef *qemuTestGetCPUDef(qemuTestCPUDef d); void qemuTestSetHostArch(virQEMUDriver *driver,