testutils: Write setter for virTestHostArch global variable

As of 47503cc859 we are statically linking libtest_utils.a into
qemuhotplugmock.so (see the original commit for reasoning).
However, this breaks ASAN on older clang because now
qemuhotplugtest has two instances of virTestHostArch global
variable. One that comes from the binary itself (which also links
with libtest_utils.a) and the other from the mock. Resolve this
by making the variable static and introducing getter and setter.
Well, the former already exists (as virArchFromHost()) so only
the latter is needed.

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 15:27:14 +02:00
parent 29ee8c1d2e
commit dff4b21585
3 changed files with 8 additions and 3 deletions

View File

@ -55,7 +55,7 @@ static size_t testCounter;
static virBitmap *testBitmap; static virBitmap *testBitmap;
static virBitmap *failedTests; static virBitmap *failedTests;
virArch virTestHostArch = VIR_ARCH_X86_64; static virArch virTestHostArch = VIR_ARCH_X86_64;
virArch virArch
virArchFromHost(void) virArchFromHost(void)
@ -63,6 +63,11 @@ virArchFromHost(void)
return virTestHostArch; return virTestHostArch;
} }
void
virTestSetHostArch(virArch arch)
{
virTestHostArch = arch;
}
static int virTestUseTerminalColors(void) static int virTestUseTerminalColors(void)
{ {

View File

@ -35,7 +35,7 @@
# error Fix build system # error Fix build system
#endif #endif
extern virArch virTestHostArch; void virTestSetHostArch(virArch arch);
int virTestRun(const char *title, int virTestRun(const char *title,
int (*body)(const void *data), int (*body)(const void *data),

View File

@ -307,7 +307,7 @@ qemuTestSetHostArch(virQEMUDriver *driver,
if (arch == VIR_ARCH_NONE) if (arch == VIR_ARCH_NONE)
arch = VIR_ARCH_X86_64; arch = VIR_ARCH_X86_64;
virTestHostArch = arch; virTestSetHostArch(arch);
driver->hostarch = virArchFromHost(); driver->hostarch = virArchFromHost();
driver->caps->host.arch = virArchFromHost(); driver->caps->host.arch = virArchFromHost();
qemuTestSetHostCPU(driver, arch, NULL); qemuTestSetHostCPU(driver, arch, NULL);