[libvirt PATCH] tests: fix compiling tests with minGW

Pavel Hrdina posted 1 patch 2 years, 9 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/0e69502b1816e50c2ee33155789f7d53d136147d.1626949422.git.phrdina@redhat.com
tests/domaincapsmock.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
[libvirt PATCH] tests: fix compiling tests with minGW
Posted by Pavel Hrdina 2 years, 9 months ago
We need to mock virQEMUCapsGetKVMSupportsSecureGuest only if compiling
with QEMU otherwise compilation will fail with error:

/usr/lib/gcc/i686-w64-mingw32/11.1.1/../../../../i686-w64-mingw32/bin/ld: tests/libdomaincapsmock.dll.p/domaincapsmock.c.obj: in function `virQEMUCapsGetKVMSupportsSecureGuest':
/builds/libvirt/libvirt/build/../tests/domaincapsmock.c:40: undefined reference to `virQEMUCapsGet'
/usr/lib/gcc/i686-w64-mingw32/11.1.1/../../../../i686-w64-mingw32/bin/ld: /builds/libvirt/libvirt/build/../tests/domaincapsmock.c:41: undefined reference to `virQEMUCapsGet'

Fixes: 248a30c0c0ec2610e8fa2bbbc98da6d06978ad2e
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 tests/domaincapsmock.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tests/domaincapsmock.c b/tests/domaincapsmock.c
index 7b02c0e890..0a6c541f77 100644
--- a/tests/domaincapsmock.c
+++ b/tests/domaincapsmock.c
@@ -17,8 +17,11 @@
 #include <config.h>
 
 #include "virhostcpu.h"
-#include "virmock.h"
-#include "qemu/qemu_capabilities.h"
+
+#if WITH_QEMU
+# include "virmock.h"
+# include "qemu/qemu_capabilities.h"
+#endif
 
 int
 virHostCPUGetKVMMaxVCPUs(void)
@@ -32,6 +35,7 @@ virHostCPUGetMicrocodeVersion(virArch hostArch G_GNUC_UNUSED)
     return 0;
 }
 
+#if WITH_QEMU
 static bool (*real_virQEMUCapsGetKVMSupportsSecureGuest)(virQEMUCaps *qemuCaps);
 
 bool
@@ -46,3 +50,4 @@ virQEMUCapsGetKVMSupportsSecureGuest(virQEMUCaps *qemuCaps)
 
     return real_virQEMUCapsGetKVMSupportsSecureGuest(qemuCaps);
 }
+#endif
-- 
2.31.1

Re: [libvirt PATCH] tests: fix compiling tests with minGW
Posted by Michal Prívozník 2 years, 9 months ago
On 7/22/21 12:24 PM, Pavel Hrdina wrote:
> We need to mock virQEMUCapsGetKVMSupportsSecureGuest only if compiling
> with QEMU otherwise compilation will fail with error:
> 
> /usr/lib/gcc/i686-w64-mingw32/11.1.1/../../../../i686-w64-mingw32/bin/ld: tests/libdomaincapsmock.dll.p/domaincapsmock.c.obj: in function `virQEMUCapsGetKVMSupportsSecureGuest':
> /builds/libvirt/libvirt/build/../tests/domaincapsmock.c:40: undefined reference to `virQEMUCapsGet'
> /usr/lib/gcc/i686-w64-mingw32/11.1.1/../../../../i686-w64-mingw32/bin/ld: /builds/libvirt/libvirt/build/../tests/domaincapsmock.c:41: undefined reference to `virQEMUCapsGet'
> 
> Fixes: 248a30c0c0ec2610e8fa2bbbc98da6d06978ad2e
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  tests/domaincapsmock.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/domaincapsmock.c b/tests/domaincapsmock.c
> index 7b02c0e890..0a6c541f77 100644
> --- a/tests/domaincapsmock.c
> +++ b/tests/domaincapsmock.c
> @@ -17,8 +17,11 @@
>  #include <config.h>
>  
>  #include "virhostcpu.h"
> -#include "virmock.h"
> -#include "qemu/qemu_capabilities.h"
> +
> +#if WITH_QEMU
> +# include "virmock.h"
> +# include "qemu/qemu_capabilities.h"
> +#endif
>  
>  int
>  virHostCPUGetKVMMaxVCPUs(void)
> @@ -32,6 +35,7 @@ virHostCPUGetMicrocodeVersion(virArch hostArch G_GNUC_UNUSED)
>      return 0;
>  }
>  
> +#if WITH_QEMU
>  static bool (*real_virQEMUCapsGetKVMSupportsSecureGuest)(virQEMUCaps *qemuCaps);
>  
>  bool
> @@ -46,3 +50,4 @@ virQEMUCapsGetKVMSupportsSecureGuest(virQEMUCaps *qemuCaps)
>  
>      return real_virQEMUCapsGetKVMSupportsSecureGuest(qemuCaps);
>  }
> +#endif
> 

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

However, this same code you're wrapping is in qemuxml2argvmock and I
don't see much reason for that since qemuxml2argtest loads
domaincapsmock too.

Michal