[PATCH 2/2] testutilsqemu: Write getter/setter for CPU def global variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 tests/qemuxml2argvtest.c |  4 ++--
 tests/testutilsqemu.c    | 22 ++++++++++++++++++----
 tests/testutilsqemu.h    | 13 +++++++++----
 3 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 1f080daba7..1a49d2cfb0 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -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,
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 53fb5f656d..d57f982c37 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -18,10 +18,10 @@
 
 # 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)
diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h
index 187f9b7cd3..99897e6b79 100644
--- a/tests/testutilsqemu.h
+++ b/tests/testutilsqemu.h
@@ -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);
-- 
2.35.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux