[libvirt PATCH 0/3] tests: Fix qemucapabilitiestest on macOS

We need to mock the function that probes for HVF support. Andrea Bolognani (3): tests: Use domaincapsmock in qemucapabilitiestest qemu: Make virQEMUCapsProbeHVF() non-static tests: Mock virQEMUCapsProbeHVF() src/qemu/qemu_capabilities.c | 4 ++-- src/qemu/qemu_capabilities.h | 2 ++ tests/domaincapsmock.c | 6 ++++++ tests/qemucapabilitiestest.c | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-) -- 2.37.1

This doesn't change anything at the moment, but is necessary for the upcoming fix. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- tests/qemucapabilitiestest.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/qemucapabilitiestest.c b/tests/qemucapabilitiestest.c index 79dd358ef4..0066ba15fa 100644 --- a/tests/qemucapabilitiestest.c +++ b/tests/qemucapabilitiestest.c @@ -230,4 +230,5 @@ mymain(void) return (data.ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } -VIR_TEST_MAIN(mymain) +VIR_TEST_MAIN_PRELOAD(mymain, + VIR_TEST_MOCK("domaincaps")) -- 2.37.1

We need to do this so that we can mock it in the test suite. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/qemu/qemu_capabilities.c | 4 ++-- src/qemu/qemu_capabilities.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 79ef8b88ef..80a8002f0c 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3259,7 +3259,7 @@ virQEMUCapsProbeQMPKVMState(virQEMUCaps *qemuCaps, } #ifdef __APPLE__ -static int +int virQEMUCapsProbeHVF(virQEMUCaps *qemuCaps) { int hv_support = 0; @@ -3281,7 +3281,7 @@ virQEMUCapsProbeHVF(virQEMUCaps *qemuCaps) return 0; } #else -static int +int virQEMUCapsProbeHVF(virQEMUCaps *qemuCaps G_GNUC_UNUSED) { return 0; diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 20b1034ca5..b172cfb7f1 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -848,5 +848,7 @@ virQEMUCapsGetSEVCapabilities(virQEMUCaps *qemuCaps); bool virQEMUCapsGetKVMSupportsSecureGuest(virQEMUCaps *qemuCaps) G_NO_INLINE; +int virQEMUCapsProbeHVF(virQEMUCaps *qemuCaps) G_NO_INLINE; + virArch virQEMUCapsArchFromString(const char *arch); const char *virQEMUCapsArchToString(virArch arch); -- 2.37.1

Successfully returning without doing anything is what the function already does on non-Apple platforms. When building on macOS, however, the check for HVF availability will be performed. When running on bare metal, that will result in the QEMU_CAPS_HVF flag being added to the virQEMUCaps instance, and a bunch of error messages along the lines of In 'tests/qemucapabilitiesdata/caps_6.2.0.x86_64.xml': Offset 7557 Expect [c] Actual [hvf'/> <flag name=‘c] showing up. Up until now we hadn't noticed because our CI jobs run in VMs, where HVF support is not available. Reported-by: Christophe de Dinechin <cdupontd@redhat.com> Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- tests/domaincapsmock.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/domaincapsmock.c b/tests/domaincapsmock.c index d382d06e27..4d53e48c48 100644 --- a/tests/domaincapsmock.c +++ b/tests/domaincapsmock.c @@ -51,6 +51,12 @@ virQEMUCapsGetKVMSupportsSecureGuest(virQEMUCaps *qemuCaps) return real_virQEMUCapsGetKVMSupportsSecureGuest(qemuCaps); } + +int +virQEMUCapsProbeHVF(virQEMUCaps *qemuCaps G_GNUC_UNUSED) +{ + return 0; +} #endif int -- 2.37.1

On a Wednesday in 2022, Andrea Bolognani wrote:
We need to mock the function that probes for HVF support.
Andrea Bolognani (3): tests: Use domaincapsmock in qemucapabilitiestest qemu: Make virQEMUCapsProbeHVF() non-static tests: Mock virQEMUCapsProbeHVF()
src/qemu/qemu_capabilities.c | 4 ++-- src/qemu/qemu_capabilities.h | 2 ++ tests/domaincapsmock.c | 6 ++++++ tests/qemucapabilitiestest.c | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

On 2022-08-10 at 16:29 +02, Andrea Bolognani <abologna@redhat.com> wrote...
We need to mock the function that probes for HVF support.
Andrea Bolognani (3): tests: Use domaincapsmock in qemucapabilitiestest qemu: Make virQEMUCapsProbeHVF() non-static tests: Mock virQEMUCapsProbeHVF()
src/qemu/qemu_capabilities.c | 4 ++-- src/qemu/qemu_capabilities.h | 2 ++ tests/domaincapsmock.c | 6 ++++++ tests/qemucapabilitiestest.c | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-)
This works. We now have a clean test suite on macOS 12: Ok: 252 Expected Fail: 0 Fail: 0 Unexpected Pass: 0 Skipped: 19 Timeout: 0 For the series: Reviewed-by: Christophe de Dinechin <dinechin@redhat.com> Tested-by: Christophe de Dinechin <dinechin@redhat.com> -- Cheers, Christophe de Dinechin (https://c3d.github.io)

On Wed, Aug 10, 2022 at 05:16:57PM +0200, Christophe de Dinechin wrote:
On 2022-08-10 at 16:29 +02, Andrea Bolognani <abologna@redhat.com> wrote...
We need to mock the function that probes for HVF support.
Andrea Bolognani (3): tests: Use domaincapsmock in qemucapabilitiestest qemu: Make virQEMUCapsProbeHVF() non-static tests: Mock virQEMUCapsProbeHVF()
src/qemu/qemu_capabilities.c | 4 ++-- src/qemu/qemu_capabilities.h | 2 ++ tests/domaincapsmock.c | 6 ++++++ tests/qemucapabilitiestest.c | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-)
This works. We now have a clean test suite on macOS 12:
Ok: 252 Expected Fail: 0 Fail: 0 Unexpected Pass: 0 Skipped: 19 Timeout: 0
For the series:
Reviewed-by: Christophe de Dinechin <dinechin@redhat.com> Tested-by: Christophe de Dinechin <dinechin@redhat.com>
Thanks to both you and Jano! Pushed now. I'll try switching the Cirrus CI configuration to macOS 12 again, but I'm afraid it's still going to hit the qemuxml2argvtest issue that doesn't show up on your machine. We'll see :) -- Andrea Bolognani / Red Hat / Virtualization

On Wed, Aug 10, 2022 at 10:54:16AM -0500, Andrea Bolognani wrote:
On Wed, Aug 10, 2022 at 05:16:57PM +0200, Christophe de Dinechin wrote:
This works. We now have a clean test suite on macOS 12:
Ok: 252 Expected Fail: 0 Fail: 0 Unexpected Pass: 0 Skipped: 19 Timeout: 0
I'll try switching the Cirrus CI configuration to macOS 12 again, but I'm afraid it's still going to hit the qemuxml2argvtest issue that doesn't show up on your machine. We'll see :)
Yeah, that still fails. https://gitlab.com/abologna/libvirt/-/jobs/2843833417 This might be too much to ask but, you could possibly create a macOS VM on your machine and see whether the issue reproduces there? I'm starting to think that virtualization is somehow the issue, even though that doesn't really make any sense to me. And a fresh install would rule out that whatever local configuration changes you're made to your main OS are what's causing the test to pass rather than fail. -- Andrea Bolognani / Red Hat / Virtualization
participants (3)
-
Andrea Bolognani
-
Christophe de Dinechin
-
Ján Tomko