]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
testutilsqemu: Write getter/setter for CPU def global variables
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 5 May 2022 14:27:55 +0000 (16:27 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 6 May 2022 10:19:34 +0000 (12:19 +0200)
As of 47503cc859 we are statically linking libtest_utils_qemu.a
into qemuhotplugmock.so (see the original commit for reasoning).
However, this breaks ASAN on older clang because now
qemuhotplugtest has two instances of virCPUDef global variables
(cpuDefault, cpuHaswell, cpuPower8, cpuPower9). One that comes
from the binary itself (which also links with
libtest_utils_qemu.a) and the other from the mock. Resolve this
by making the variables static and introducing getter and setter.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
tests/qemuxml2argvtest.c
tests/testutilsqemu.c
tests/testutilsqemu.h

index 1f080daba765735b8336b07913c7c6c65ed16169..1a49d2cfb026d00d3364fbf598cc7405af460c50 100644 (file)
@@ -2068,7 +2068,7 @@ mymain(void)
     DO_TEST_FAILURE("cpu-s390-features", QEMU_CAPS_KVM);
     qemuTestSetHostArch(&driver, VIR_ARCH_NONE);
 
-    qemuTestSetHostCPU(&driver, driver.hostarch, cpuHaswell);
+    qemuTestSetHostCPU(&driver, driver.hostarch, qemuTestGetCPUDef(QEMU_CPU_DEF_HASWELL));
     DO_TEST("cpu-Haswell", QEMU_CAPS_KVM);
     DO_TEST("cpu-Haswell2", QEMU_CAPS_KVM);
     DO_TEST("cpu-Haswell3", QEMU_CAPS_KVM);
@@ -2202,7 +2202,7 @@ mymain(void)
                     QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE,
                     QEMU_CAPS_KVM);
 
-    qemuTestSetHostCPU(&driver, driver.hostarch, cpuPower9);
+    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,
index 53fb5f656d5ca58af5fa7099696bef12a4cc2c2c..d57f982c37f1ca7567ad3505fd9b37f88254667c 100644 (file)
 
 # define VIR_FROM_THIS VIR_FROM_QEMU
 
-virCPUDef *cpuDefault;
-virCPUDef *cpuHaswell;
-virCPUDef *cpuPower8;
-virCPUDef *cpuPower9;
+static virCPUDef *cpuDefault;
+static virCPUDef *cpuHaswell;
+static virCPUDef *cpuPower8;
+static virCPUDef *cpuPower9;
 
 
 static const char *qemu_emulators[VIR_ARCH_LAST] = {
@@ -300,6 +300,20 @@ testQemuCapsInitMacOS(void)
 }
 
 
+virCPUDef *
+qemuTestGetCPUDef(qemuTestCPUDef d)
+{
+    switch (d) {
+    case QEMU_CPU_DEF_DEFAULT: return cpuDefault;
+    case QEMU_CPU_DEF_HASWELL: return cpuHaswell;
+    case QEMU_CPU_DEF_POWER8: return cpuPower8;
+    case QEMU_CPU_DEF_POWER9: return cpuPower9;
+    }
+
+    return NULL;
+}
+
+
 void
 qemuTestSetHostArch(virQEMUDriver *driver,
                     virArch arch)
index 187f9b7cd3e54e8ac0dd0fa8b0f06cfcd1fd3b72..99897e6b798a2f503f3be93d040f01c9a82c6973 100644 (file)
@@ -102,10 +102,15 @@ virDomainXMLOption *testQemuXMLConfInit(void);
 virQEMUCaps *qemuTestParseCapabilitiesArch(virArch arch,
                                              const char *capsFile);
 
-extern virCPUDef *cpuDefault;
-extern virCPUDef *cpuHaswell;
-extern virCPUDef *cpuPower8;
-extern virCPUDef *cpuPower9;
+
+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,
                          virArch arch);