]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
testutilsqemu: Helpers for changing host CPU and arch
authorJiri Denemark <jdenemar@redhat.com>
Thu, 4 Aug 2016 11:16:55 +0000 (13:16 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 22 Sep 2016 13:40:08 +0000 (15:40 +0200)
Changing a host architecture or a CPU is not as easy as assigning a new
value to the appropriate element in virCaps since there is a relation
between the CPU and host architecture (we don't really want to test
anything on an AArch64 host with core2duo CPU). This patch introduces
qemuTestSetHostArch and qemuTestSetHostCPU helpers which will make sure
the host architecture matches the host CPU.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
tests/testutilsqemu.c
tests/testutilsqemu.h

index 11dd20e2c6c0e4be3f17f97617614bbc9c3d3540..b569e0d5fdf4867fe4709d4aa77421d7ae710c4a 100644 (file)
@@ -334,7 +334,7 @@ virCapsPtr testQemuCapsInit(void)
         !(cpuHaswell = virCPUDefCopy(&cpuHaswellData)))
         goto cleanup;
 
-    caps->host.cpu = cpuDefault;
+    qemuTestSetHostCPU(caps, NULL);
 
     caps->host.nnumaCell_max = 4;
 
@@ -440,15 +440,42 @@ virCapsPtr testQemuCapsInit(void)
 
  cleanup:
     virCapabilitiesFreeMachines(machines, nmachines);
-    if (caps->host.cpu != cpuDefault)
-        virCPUDefFree(cpuDefault);
-    if (caps->host.cpu != cpuHaswell)
-        virCPUDefFree(cpuHaswell);
+    caps->host.cpu = NULL;
+    virCPUDefFree(cpuDefault);
+    virCPUDefFree(cpuHaswell);
     virObjectUnref(caps);
     return NULL;
 }
 
 
+void
+qemuTestSetHostArch(virCapsPtr caps,
+                    virArch arch)
+{
+    if (arch == VIR_ARCH_NONE)
+        arch = VIR_ARCH_X86_64;
+    caps->host.arch = arch;
+    qemuTestSetHostCPU(caps, NULL);
+}
+
+
+void
+qemuTestSetHostCPU(virCapsPtr caps,
+                   virCPUDefPtr cpu)
+{
+    virArch arch = caps->host.arch;
+
+    if (!cpu) {
+        if (ARCH_IS_X86(arch))
+            cpu = cpuDefault;
+    }
+
+    if (cpu)
+        caps->host.arch = cpu->arch;
+    caps->host.cpu = cpu;
+}
+
+
 virQEMUCapsPtr
 qemuTestParseCapabilities(const char *capsFile)
 {
index f2b71e91d899168215954b208f8a5611258c6e5d..7c678c9f017942636a8f95ac92c1caa42b14ddff 100644 (file)
@@ -19,8 +19,11 @@ virQEMUCapsPtr qemuTestParseCapabilities(const char *capsFile);
 
 extern virCPUDefPtr cpuDefault;
 extern virCPUDefPtr cpuHaswell;
-void testQemuCapsSetCPU(virCapsPtr caps,
-                        virCPUDefPtr hostCPU);
+
+void qemuTestSetHostArch(virCapsPtr caps,
+                        virArch arch);
+void qemuTestSetHostCPU(virCapsPtr caps,
+                        virCPUDefPtr cpu);
 
 int qemuTestDriverInit(virQEMUDriver *driver);
 void qemuTestDriverFree(virQEMUDriver *driver);