[libvirt PATCH 7/7] tests: libxl: do not run the emulator

Ján Tomko posted 7 patches 5 years, 11 months ago
[libvirt PATCH 7/7] tests: libxl: do not run the emulator
Posted by Ján Tomko 5 years, 11 months ago
Ever since commit c5a00350 the libxl parser invokes the emulator
to probe which device model to use.

Commit b90c4b5 introduced a workaround that used a stable path
which was very likely to result in the answer matching the default.
However the test is still affected by the host state and the binary
gets invoked if present.

Mock the libxlDomainGetEmulatorType function to stop wasting CPU
cycles every time a 'make check' is run on a system with xen installed.

For example xlconfigtest gets faster by 90 %

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: b90c4b5f505698d600303c5b4f03f5d229b329dd
---
 src/libxl/libxl_capabilities.h | 3 ++-
 tests/libxlmock.c              | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/libxl/libxl_capabilities.h b/src/libxl/libxl_capabilities.h
index 9a7c8bf636..9efb836429 100644
--- a/src/libxl/libxl_capabilities.h
+++ b/src/libxl/libxl_capabilities.h
@@ -50,4 +50,5 @@ libxlMakeDomainCapabilities(virDomainCapsPtr domCaps,
                             size_t nfirmwares);
 
 int
-libxlDomainGetEmulatorType(const virDomainDef *def);
+libxlDomainGetEmulatorType(const virDomainDef *def)
+    G_GNUC_NO_INLINE;
diff --git a/tests/libxlmock.c b/tests/libxlmock.c
index 60e6b78129..a36ca135f6 100644
--- a/tests/libxlmock.c
+++ b/tests/libxlmock.c
@@ -30,6 +30,7 @@
 
 # include "virfile.h"
 # include "virsocket.h"
+# include "libxl/libxl_capabilities.h"
 
 VIR_MOCK_IMPL_RET_VOID(xs_daemon_open,
                        struct xs_handle *)
@@ -123,4 +124,10 @@ VIR_MOCK_IMPL_RET_ARGS(stat, int,
     return real_stat(path, sb);
 }
 
+int
+libxlDomainGetEmulatorType(const virDomainDef *def G_GNUC_UNUSED)
+{
+    return LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN;
+}
+
 #endif /* WITH_LIBXL && WITH_YAJL */
-- 
2.24.1

Re: [libvirt PATCH 7/7] tests: libxl: do not run the emulator
Posted by Jim Fehlig 5 years, 11 months ago
On 2/22/20 7:25 AM, Ján Tomko wrote:
> Ever since commit c5a00350 the libxl parser invokes the emulator
> to probe which device model to use.
> 
> Commit b90c4b5 introduced a workaround that used a stable path
> which was very likely to result in the answer matching the default.
> However the test is still affected by the host state and the binary
> gets invoked if present.
> 
> Mock the libxlDomainGetEmulatorType function to stop wasting CPU
> cycles every time a 'make check' is run on a system with xen installed.
> 
> For example xlconfigtest gets faster by 90 %
> 
> Signed-off-by: Ján Tomko <jtomko@redhat.com>
> Fixes: b90c4b5f505698d600303c5b4f03f5d229b329dd
> ---
>   src/libxl/libxl_capabilities.h | 3 ++-
>   tests/libxlmock.c              | 7 +++++++
>   2 files changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/src/libxl/libxl_capabilities.h b/src/libxl/libxl_capabilities.h
> index 9a7c8bf636..9efb836429 100644
> --- a/src/libxl/libxl_capabilities.h
> +++ b/src/libxl/libxl_capabilities.h
> @@ -50,4 +50,5 @@ libxlMakeDomainCapabilities(virDomainCapsPtr domCaps,
>                               size_t nfirmwares);
>   
>   int
> -libxlDomainGetEmulatorType(const virDomainDef *def);
> +libxlDomainGetEmulatorType(const virDomainDef *def)
> +    G_GNUC_NO_INLINE;

Ah, I think the lack of this change caused me grief in the past while fiddling 
with the mocking.

Regards,
Jim

> diff --git a/tests/libxlmock.c b/tests/libxlmock.c
> index 60e6b78129..a36ca135f6 100644
> --- a/tests/libxlmock.c
> +++ b/tests/libxlmock.c
> @@ -30,6 +30,7 @@
>   
>   # include "virfile.h"
>   # include "virsocket.h"
> +# include "libxl/libxl_capabilities.h"
>   
>   VIR_MOCK_IMPL_RET_VOID(xs_daemon_open,
>                          struct xs_handle *)
> @@ -123,4 +124,10 @@ VIR_MOCK_IMPL_RET_ARGS(stat, int,
>       return real_stat(path, sb);
>   }
>   
> +int
> +libxlDomainGetEmulatorType(const virDomainDef *def G_GNUC_UNUSED)
> +{
> +    return LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN;
> +}
> +
>   #endif /* WITH_LIBXL && WITH_YAJL */
>