[PATCH 8/8] tests/testutilsqemu: properly initialize qemu caps for tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/qemu/qemu_capabilities.c |  6 ------
 tests/qemuhotplugtest.c      | 11 ++++-------
 tests/qemuxml2argvtest.c     |  7 +++----
 tests/qemuxml2xmltest.c      | 30 ++++++++++++++++--------------
 tests/testutilsqemu.c        | 36 +++++++++++++++++++-----------------
 tests/testutilsqemu.h        |  5 +----
 6 files changed, 43 insertions(+), 52 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 11fe3e2d9d..2648d46619 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -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);
diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index e835999c72..fe97fd0dc3 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -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)))
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 18ff5ad147..525aa67e02 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -434,16 +434,15 @@ testCompareXMLToArgv(const void *data)
     if (virQEMUCapsGet(info->qemuCaps, QEMU_CAPS_ENABLE_FIPS))
         flags |= FLAG_FIPS;
 
-    if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->name,
-                                info->qemuCaps) < 0)
-        goto cleanup;
-
     if (virAsprintf(&xml, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
                     abs_srcdir, info->name) < 0 ||
         virAsprintf(&args, "%s/qemuxml2argvdata/qemuxml2argv-%s.args",
                     abs_srcdir, info->name) < 0)
         goto cleanup;
 
+    if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) < 0)
+        goto cleanup;
+
     if (info->migrateFrom &&
         !(migrateURI = qemuMigrationIncomingURI(info->migrateFrom,
                                                 info->migrateFd)))
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 579328912a..e1ef9e5b86 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -251,25 +251,26 @@ testInfoSet(struct testInfo *info,
             int when,
             int gic)
 {
+    int ret = -1;
+
     if (!(info->qemuCaps = virQEMUCapsNew()))
-        goto error;
+        goto cleanup;
 
     if (testQemuCapsSetGIC(info->qemuCaps, gic) < 0)
-        goto error;
+        goto cleanup;
 
-    if (qemuTestCapsCacheInsert(driver.qemuCapsCache, name,
-                                info->qemuCaps) < 0)
-        goto error;
+    if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) < 0)
+        goto cleanup;
 
     if (virAsprintf(&info->inName, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml",
                     abs_srcdir, name) < 0)
-        goto error;
+        goto cleanup;
 
     if (when & WHEN_INACTIVE) {
         if (virAsprintf(&info->outInactiveName,
                         "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s-inactive.xml",
                         abs_srcdir, name) < 0)
-            goto error;
+            goto cleanup;
 
         if (!virFileExists(info->outInactiveName)) {
             VIR_FREE(info->outInactiveName);
@@ -277,7 +278,7 @@ testInfoSet(struct testInfo *info,
             if (virAsprintf(&info->outInactiveName,
                             "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s.xml",
                             abs_srcdir, name) < 0)
-                goto error;
+                goto cleanup;
         }
     }
 
@@ -285,7 +286,7 @@ testInfoSet(struct testInfo *info,
         if (virAsprintf(&info->outActiveName,
                         "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s-active.xml",
                         abs_srcdir, name) < 0)
-            goto error;
+            goto cleanup;
 
         if (!virFileExists(info->outActiveName)) {
             VIR_FREE(info->outActiveName);
@@ -293,15 +294,16 @@ testInfoSet(struct testInfo *info,
             if (virAsprintf(&info->outActiveName,
                             "%s/qemuxml2xmloutdata/qemuxml2xmlout-%s.xml",
                             abs_srcdir, name) < 0)
-                goto error;
+                goto cleanup;
         }
     }
 
-    return 0;
+    ret = 0;
 
- error:
-    testInfoFree(info);
-    return -1;
+ cleanup:
+    if (ret < 0)
+        testInfoFree(info);
+    return ret;
 }
 
 
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index d3d62df9d1..709e291bd4 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -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",
diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h
index 047a64d1ac..3393f5eb71 100644
--- a/tests/testutilsqemu.h
+++ b/tests/testutilsqemu.h
@@ -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
-- 
2.12.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux