]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests/testutilsqemu: properly initialize qemu caps for tests
authorPavel Hrdina <phrdina@redhat.com>
Tue, 11 Apr 2017 12:02:06 +0000 (14:02 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 11 Apr 2017 12:06:47 +0000 (14:06 +0200)
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>
src/qemu/qemu_capabilities.c
tests/qemuhotplugtest.c
tests/qemuxml2argvtest.c
tests/qemuxml2xmltest.c
tests/testutilsqemu.c
tests/testutilsqemu.h

index 11fe3e2d9d48285bbfeb3122be9e782a34bb02f7..2648d466194fa06c7cfe14a3e65f2de8e2c51068 100644 (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);
index e835999c722c83469ec9b1b11fff8b1f83825cc6..fe97fd0dc3b0bef9a60012cf666cad755ba5b7b6 100644 (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)))
index 18ff5ad147e6041343a35fe364c30bfe841f46f1..ed99c21abd4c4756d380c7d7e9251ca0083c85fa 100644 (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",
index 579328912a68db109af3c27a0279350e6c7f5a64..e4b510fd31ee5b10a1fe65ce62b5d1d10ff40076 100644 (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",
index d3d62df9d1c8c03822d6534699a3323ee748f6e5..709e291bd4357659aeeddb13a2bb5c2b8e493ebe 100644 (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",
index 047a64d1acf99b96834674f1cbd0fdd71f650a3b..3393f5eb710c2082cb1f4ef1237cfcc1843d8370 100644 (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