]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
testutilsqemu: introduce ARG_CAPS_HOST_CPU_MODEL
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Fri, 20 May 2022 13:58:23 +0000 (10:58 -0300)
committerDaniel Henrique Barboza <danielhb413@gmail.com>
Mon, 23 May 2022 22:24:42 +0000 (19:24 -0300)
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 <mkletzan@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
tests/qemuxml2argvtest.c
tests/testutilsqemu.c
tests/testutilsqemu.h

index aadfaddc1749476c91b256f3fff22e7ec2e1ddd7..96bc7aadeb3b1d13becbb8fed05fd86c54b3d8b6 100644 (file)
@@ -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;
 
index 004c7cf1d6bf4d5b132abc97194ea676ed54029d..7e4e5d28b72cec848cd2b04cb745800959616576 100644 (file)
@@ -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;
index 99897e6b798a2f503f3be93d040f01c9a82c6973..5419b813eafcfd22d02c204a2f12ca30c9171ddf 100644 (file)
@@ -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,