tests/testutilsqemu: properly initialize qemu caps for tests

This removes the hacky extern global variable and modifies the
test code to properly create QEMU capabilities cache for QEMU
binaries used in our tests.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2017-04-11 14:02:06 +02:00
parent e6e26a899d
commit 8d04ea1661
6 changed files with 26 additions and 38 deletions

View File

@ -5209,8 +5209,6 @@ virQEMUCapsCacheValidate(virQEMUCapsCachePtr cache,
}
const char *qemuTestCapsName;
virQEMUCapsPtr
virQEMUCapsCacheLookup(virCapsPtr caps,
virQEMUCapsCachePtr cache,
@ -5218,10 +5216,6 @@ virQEMUCapsCacheLookup(virCapsPtr caps,
{
virQEMUCapsPtr ret = NULL;
/* This is used only by test suite!!! */
if (qemuTestCapsName)
binary = qemuTestCapsName;
virMutexLock(&cache->lock);
ret = virHashLookup(cache->binaries, binary);

View File

@ -58,7 +58,7 @@ static int
qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt,
virDomainObjPtr *vm,
const char *domxml,
bool event, const char *testname)
bool event)
{
int ret = -1;
qemuDomainObjPrivatePtr priv = NULL;
@ -79,8 +79,7 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt,
if (event)
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_DEL_EVENT);
if (qemuTestCapsCacheInsert(driver.qemuCapsCache, testname,
priv->qemuCaps) < 0)
if (qemuTestCapsCacheInsert(driver.qemuCapsCache, priv->qemuCaps) < 0)
goto cleanup;
if (!((*vm)->def = virDomainDefParseString(domxml,
@ -262,8 +261,7 @@ testQemuHotplug(const void *data)
vm = test->vm;
} else {
if (qemuHotplugCreateObjects(driver.xmlopt, &vm, domain_xml,
test->deviceDeletedEvent,
test->domain_filename) < 0)
test->deviceDeletedEvent) < 0)
goto cleanup;
}
@ -415,8 +413,7 @@ testQemuHotplugCpuPrepare(const char *test,
if (virTestLoadFile(data->file_xml_dom, &data->xml_dom) < 0)
goto error;
if (qemuHotplugCreateObjects(driver.xmlopt, &data->vm, data->xml_dom, true,
"cpu-hotplug-test-domain") < 0)
if (qemuHotplugCreateObjects(driver.xmlopt, &data->vm, data->xml_dom, true) < 0)
goto error;
if (!(caps = virQEMUDriverGetCapabilities(&driver, false)))

View File

@ -434,8 +434,7 @@ testCompareXMLToArgv(const void *data)
if (virQEMUCapsGet(info->qemuCaps, QEMU_CAPS_ENABLE_FIPS))
flags |= FLAG_FIPS;
if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->name,
info->qemuCaps) < 0)
if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) < 0)
goto cleanup;
if (virAsprintf(&xml, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",

View File

@ -257,8 +257,7 @@ testInfoSet(struct testInfo *info,
if (testQemuCapsSetGIC(info->qemuCaps, gic) < 0)
goto error;
if (qemuTestCapsCacheInsert(driver.qemuCapsCache, name,
info->qemuCaps) < 0)
if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) < 0)
goto error;
if (virAsprintf(&info->inName, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",

View File

@ -586,34 +586,36 @@ void qemuTestDriverFree(virQEMUDriver *driver)
virObjectUnref(driver->securityManager);
}
int qemuTestCapsCacheInsert(virQEMUCapsCachePtr cache, const char *binary,
int qemuTestCapsCacheInsert(virQEMUCapsCachePtr cache,
virQEMUCapsPtr caps)
{
int ret;
size_t i;
virQEMUCapsPtr tmpCaps;
if (caps) {
/* Our caps were created artificially, so we don't want
* virQEMUCapsCacheFree() to attempt to deallocate them */
virObjectRef(caps);
tmpCaps = caps;
} else {
caps = virQEMUCapsNew();
if (!caps)
if (!(tmpCaps = virQEMUCapsNew()))
return -ENOMEM;
}
/* We can have repeating names for our test data sets,
* so make sure there's no old copy */
virHashRemoveEntry(cache->binaries, binary);
for (i = 0; i < ARRAY_CARDINALITY(QEMUBinList); i++) {
virObjectRef(tmpCaps);
if (virHashUpdateEntry(cache->binaries,
QEMUBinList[i],
tmpCaps) < 0) {
virObjectUnref(tmpCaps);
return -1;
}
}
ret = virHashAddEntry(cache->binaries, binary, caps);
if (ret < 0)
virObjectUnref(caps);
else
qemuTestCapsName = binary;
if (!caps)
virObjectUnref(tmpCaps);
return ret;
return 0;
}
# define STATEDIRTEMPLATE abs_builddir "/qemustatedir-XXXXXX"
# define CONFIGDIRTEMPLATE abs_builddir "/qemuconfigdir-XXXXXX"
@ -678,7 +680,7 @@ int qemuTestDriverInit(virQEMUDriver *driver)
if (!driver->xmlopt)
goto error;
if (qemuTestCapsCacheInsert(driver->qemuCapsCache, "empty", NULL) < 0)
if (qemuTestCapsCacheInsert(driver->qemuCapsCache, NULL) < 0)
goto error;
if (!(mgr = virSecurityManagerNew("none", "qemu",

View File

@ -29,12 +29,9 @@ void qemuTestSetHostCPU(virCapsPtr caps,
int qemuTestDriverInit(virQEMUDriver *driver);
void qemuTestDriverFree(virQEMUDriver *driver);
int qemuTestCapsCacheInsert(virQEMUCapsCachePtr cache, const char *binary,
int qemuTestCapsCacheInsert(virQEMUCapsCachePtr cache,
virQEMUCapsPtr caps);
int testQemuCapsSetGIC(virQEMUCapsPtr qemuCaps,
int gic);
/* This variable is actually defined in src/qemu/qemu_capabilities.c */
extern const char *qemuTestCapsName;
#endif