testutilsqemu: Helpers for changing host CPU and arch

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>
This commit is contained in:
Jiri Denemark 2016-08-04 13:16:55 +02:00
parent 6bb5f0b218
commit 127e0b53ec
2 changed files with 37 additions and 7 deletions

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

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