[PATCH 0/3] qemuxml2argvtest: add ARG_CAPS_HOST_CPU_MODEL

Hi, This series attempts to fix a problem I found when converting the "pseries-cpu-compat-power9" to use DO_TEST_CAPS_ARCH_LATEST* macros. More information about the problem per se can be found in patch 02. Patch 03 is where I was able to convert the said test. Patch 01 is a trivial fix I found out when reading code. Daniel Henrique Barboza (3): qemu_capspriv.h: fix identation testutilsqemu: introduce ARG_CAPS_HOST_CPU_MODEL qemuxml2argvtest.c: use CAPS_ARCH_LATEST() with pseries-cpu-compat-power9 src/qemu/qemu_capspriv.h | 4 +- ...eries-cpu-compat-power9.ppc64-latest.args} | 12 +++--- ...series-cpu-compat-power9.ppc64-latest.err} | 0 tests/qemuxml2argvtest.c | 41 ++++++++++++------- tests/testutilsqemu.c | 4 ++ tests/testutilsqemu.h | 18 ++++---- 6 files changed, 49 insertions(+), 30 deletions(-) rename tests/qemuxml2argvdata/{pseries-cpu-compat-power9.args => pseries-cpu-compat-power9.ppc64-latest.args} (60%) rename tests/qemuxml2argvdata/{pseries-cpu-compat-power9.err => pseries-cpu-compat-power9.ppc64-latest.err} (100%) -- 2.32.0

Fix identation of virQEMUCapsUpdateHostCPUModel() params. Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- src/qemu/qemu_capspriv.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h index f4f4a99d32..26bf2d3571 100644 --- a/src/qemu/qemu_capspriv.h +++ b/src/qemu/qemu_capspriv.h @@ -63,8 +63,8 @@ virQEMUCapsInitHostCPUModel(virQEMUCaps *qemuCaps, void virQEMUCapsUpdateHostCPUModel(virQEMUCaps *qemuCaps, - virArch hostArch, - virDomainVirtType type); + virArch hostArch, + virDomainVirtType type); int virQEMUCapsInitCPUModel(virQEMUCaps *qemuCaps, virDomainVirtType type, -- 2.32.0

On Fri, May 20, 2022 at 05:47:02PM -0300, Daniel Henrique Barboza wrote:
Fix identation of virQEMUCapsUpdateHostCPUModel() params.
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
trivial, Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
--- src/qemu/qemu_capspriv.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h index f4f4a99d32..26bf2d3571 100644 --- a/src/qemu/qemu_capspriv.h +++ b/src/qemu/qemu_capspriv.h @@ -63,8 +63,8 @@ virQEMUCapsInitHostCPUModel(virQEMUCaps *qemuCaps,
void virQEMUCapsUpdateHostCPUModel(virQEMUCaps *qemuCaps, - virArch hostArch, - virDomainVirtType type); + virArch hostArch, + virDomainVirtType type); int virQEMUCapsInitCPUModel(virQEMUCaps *qemuCaps, virDomainVirtType type, -- 2.32.0

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()) prevent 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". Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- 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, -- 2.32.0

On Fri, May 20, 2022 at 05:47:03PM -0300, Daniel Henrique Barboza wrote:
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.
I must say the FLAG_REAL_CAPS is a little bit confusing in our tests.
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()) prevent FLAG_REAL_CAPS to
s/prevent/prevents/ </nitpicks>
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".
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com> I hope I understood all the nuances, but it seems reasonable.

Use the newly added ARG_CAPS_HOST_CPU_MODEL to set which host CPU we expect the test to use - the test should fail when using a POWER8 host cpu but complete when using a POWER9 host cpu. Two new macros were added because we will be adding similar tests in the near future when adding support for the Power10 chip. Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> --- ...eries-cpu-compat-power9.ppc64-latest.args} | 12 ++++++---- ...series-cpu-compat-power9.ppc64-latest.err} | 0 tests/qemuxml2argvtest.c | 23 +++++++++++-------- 3 files changed, 20 insertions(+), 15 deletions(-) rename tests/qemuxml2argvdata/{pseries-cpu-compat-power9.args => pseries-cpu-compat-power9.ppc64-latest.args} (60%) rename tests/qemuxml2argvdata/{pseries-cpu-compat-power9.err => pseries-cpu-compat-power9.ppc64-latest.err} (100%) diff --git a/tests/qemuxml2argvdata/pseries-cpu-compat-power9.args b/tests/qemuxml2argvdata/pseries-cpu-compat-power9.ppc64-latest.args similarity index 60% rename from tests/qemuxml2argvdata/pseries-cpu-compat-power9.args rename to tests/qemuxml2argvdata/pseries-cpu-compat-power9.ppc64-latest.args index 233e92f206..f458999291 100644 --- a/tests/qemuxml2argvdata/pseries-cpu-compat-power9.args +++ b/tests/qemuxml2argvdata/pseries-cpu-compat-power9.ppc64-latest.args @@ -6,15 +6,15 @@ LOGNAME=test \ XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \ XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ -QEMU_AUDIO_DRV=none \ /usr/bin/qemu-system-ppc64 \ -name guest=QEMUGuest1,debug-threads=on \ -S \ --object secret,id=masterKey0,format=raw,file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ --machine pseries,usb=off,dump-guest-core=off,max-cpu-compat=power9 \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pseries,usb=off,dump-guest-core=off,max-cpu-compat=power9,memory-backend=ppc_spapr.ram \ -accel kvm \ -cpu host \ -m 256 \ +-object '{"qom-type":"memory-backend-ram","id":"ppc_spapr.ram","size":268435456}' \ -overcommit mem-lock=off \ -smp 4,sockets=4,cores=1,threads=1 \ -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ @@ -26,7 +26,9 @@ QEMU_AUDIO_DRV=none \ -rtc base=utc \ -no-shutdown \ -boot strict=on \ --usb \ +-device '{"driver":"pci-ohci","id":"usb","bus":"pci.0","addr":"0x1"}' \ -chardev pty,id=charserial0 \ --device spapr-vty,chardev=charserial0,id=serial0,reg=805306368 \ +-device '{"driver":"spapr-vty","chardev":"charserial0","id":"serial0","reg":805306368}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ -msg timestamp=on diff --git a/tests/qemuxml2argvdata/pseries-cpu-compat-power9.err b/tests/qemuxml2argvdata/pseries-cpu-compat-power9.ppc64-latest.err similarity index 100% rename from tests/qemuxml2argvdata/pseries-cpu-compat-power9.err rename to tests/qemuxml2argvdata/pseries-cpu-compat-power9.ppc64-latest.err diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 96bc7aadeb..5ae245d254 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -980,6 +980,15 @@ mymain(void) # define DO_TEST_CAPS_LATEST_PPC64(name) \ DO_TEST_CAPS_ARCH_LATEST(name, "ppc64") +# define DO_TEST_CAPS_LATEST_PPC64_HOSTCPU(name, hostcpu) \ + DO_TEST_CAPS_ARCH_LATEST_FULL(name, "ppc64", \ + ARG_CAPS_HOST_CPU_MODEL, hostcpu) + +# define DO_TEST_CAPS_LATEST_PPC64_HOSTCPU_FAILURE(name, hostcpu) \ + DO_TEST_CAPS_ARCH_LATEST_FULL(name, "ppc64", \ + ARG_CAPS_HOST_CPU_MODEL, hostcpu, \ + ARG_FLAGS, FLAG_EXPECT_FAILURE) + # define DO_TEST_CAPS_ARCH_LATEST_FAILURE(name, arch) \ DO_TEST_CAPS_ARCH_LATEST_FULL(name, arch, \ ARG_FLAGS, FLAG_EXPECT_FAILURE) @@ -2226,16 +2235,10 @@ mymain(void) DO_TEST("pseries-cpu-le", QEMU_CAPS_KVM, QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE, QEMU_CAPS_DEVICE_SPAPR_VTY); - DO_TEST_FAILURE("pseries-cpu-compat-power9", - QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE, - QEMU_CAPS_KVM); - - qemuTestSetHostCPU(&driver, driver.hostarch, qemuTestGetCPUDef(QEMU_CPU_DEF_POWER9)); - DO_TEST("pseries-cpu-compat-power9", - QEMU_CAPS_KVM, - QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE, - QEMU_CAPS_DEVICE_SPAPR_VTY); - qemuTestSetHostCPU(&driver, driver.hostarch, NULL); + DO_TEST_CAPS_LATEST_PPC64_HOSTCPU_FAILURE("pseries-cpu-compat-power9", + QEMU_CPU_DEF_POWER8); + DO_TEST_CAPS_LATEST_PPC64_HOSTCPU("pseries-cpu-compat-power9", + QEMU_CPU_DEF_POWER9); qemuTestSetHostArch(&driver, VIR_ARCH_NONE); -- 2.32.0

On Fri, May 20, 2022 at 05:47:04PM -0300, Daniel Henrique Barboza wrote:
Use the newly added ARG_CAPS_HOST_CPU_MODEL to set which host CPU we expect the test to use - the test should fail when using a POWER8 host cpu but complete when using a POWER9 host cpu.
Two new macros were added because we will be adding similar tests in the near future when adding support for the Power10 chip.
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>

Pushed fixing the typo in patch 2. Thanks! Daniel On 5/20/22 17:47, Daniel Henrique Barboza wrote:
Hi,
This series attempts to fix a problem I found when converting the "pseries-cpu-compat-power9" to use DO_TEST_CAPS_ARCH_LATEST* macros. More information about the problem per se can be found in patch 02. Patch 03 is where I was able to convert the said test.
Patch 01 is a trivial fix I found out when reading code.
Daniel Henrique Barboza (3): qemu_capspriv.h: fix identation testutilsqemu: introduce ARG_CAPS_HOST_CPU_MODEL qemuxml2argvtest.c: use CAPS_ARCH_LATEST() with pseries-cpu-compat-power9
src/qemu/qemu_capspriv.h | 4 +- ...eries-cpu-compat-power9.ppc64-latest.args} | 12 +++--- ...series-cpu-compat-power9.ppc64-latest.err} | 0 tests/qemuxml2argvtest.c | 41 ++++++++++++------- tests/testutilsqemu.c | 4 ++ tests/testutilsqemu.h | 18 ++++---- 6 files changed, 49 insertions(+), 30 deletions(-) rename tests/qemuxml2argvdata/{pseries-cpu-compat-power9.args => pseries-cpu-compat-power9.ppc64-latest.args} (60%) rename tests/qemuxml2argvdata/{pseries-cpu-compat-power9.err => pseries-cpu-compat-power9.ppc64-latest.err} (100%)
participants (2)
-
Daniel Henrique Barboza
-
Martin Kletzander