]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
testutils: Write setter for virTestHostArch global variable
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 5 May 2022 13:27:14 +0000 (15:27 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 6 May 2022 10:16:15 +0000 (12:16 +0200)
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>
tests/testutils.c
tests/testutils.h
tests/testutilsqemu.c

index 2b37c1965d3a885e4a2d03723d746dd68782310c..9d454c23bc8b9589302575d9a3c1a98ef2a2c771 100644 (file)
@@ -55,7 +55,7 @@ static size_t testCounter;
 static virBitmap *testBitmap;
 static virBitmap *failedTests;
 
-virArch virTestHostArch = VIR_ARCH_X86_64;
+static virArch virTestHostArch = VIR_ARCH_X86_64;
 
 virArch
 virArchFromHost(void)
@@ -63,6 +63,11 @@ virArchFromHost(void)
     return virTestHostArch;
 }
 
+void
+virTestSetHostArch(virArch arch)
+{
+    virTestHostArch = arch;
+}
 
 static int virTestUseTerminalColors(void)
 {
index 13a154a5af2ccfa3ed49cd7cbc0e9dd7ab236436..ff5661bb3f2f93dcc9811b70499f452891092ffe 100644 (file)
@@ -35,7 +35,7 @@
 # error Fix build system
 #endif
 
-extern virArch virTestHostArch;
+void virTestSetHostArch(virArch arch);
 
 int virTestRun(const char *title,
                int (*body)(const void *data),
index 105b41cbeb2801328f35308582111d2c65414f4c..53fb5f656d5ca58af5fa7099696bef12a4cc2c2c 100644 (file)
@@ -307,7 +307,7 @@ qemuTestSetHostArch(virQEMUDriver *driver,
     if (arch == VIR_ARCH_NONE)
         arch = VIR_ARCH_X86_64;
 
-    virTestHostArch = arch;
+    virTestSetHostArch(arch);
     driver->hostarch = virArchFromHost();
     driver->caps->host.arch = virArchFromHost();
     qemuTestSetHostCPU(driver, arch, NULL);