testutilsqemu: Write getter/setter for CPU def global variables

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>
This commit is contained in:
Michal Privoznik 2022-05-05 16:27:55 +02:00
parent dff4b21585
commit 776e9a6b26
3 changed files with 29 additions and 10 deletions

View 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,

View File

@ -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)

View 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);