[PATCH 1/4] tests: split out common qemu driver initialization

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

 



From: Pavel Fedin <p.fedin@xxxxxxxxxxx>

Two utility functions are introduced for proper initialization and
cleanup of the driver.

Signed-off-by: Pavel Fedin <p.fedin@xxxxxxxxxxx>
Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 tests/domainsnapshotxml2xmltest.c | 10 +++-------
 tests/qemuagenttest.c             | 11 ++++++-----
 tests/qemuargv2xmltest.c          | 12 ++----------
 tests/qemuhotplugtest.c           |  9 ++-------
 tests/qemuxml2argvtest.c          | 11 ++---------
 tests/qemuxml2xmltest.c           |  8 +++-----
 tests/qemuxmlnstest.c             | 11 +++--------
 tests/testutilsqemu.c             | 30 ++++++++++++++++++++++++++++++
 tests/testutilsqemu.h             |  2 ++
 9 files changed, 53 insertions(+), 51 deletions(-)

diff --git a/tests/domainsnapshotxml2xmltest.c b/tests/domainsnapshotxml2xmltest.c
index 3955a19..b66af3e 100644
--- a/tests/domainsnapshotxml2xmltest.c
+++ b/tests/domainsnapshotxml2xmltest.c
@@ -152,13 +152,10 @@ mymain(void)
 {
     int ret = 0;
 
-    if ((driver.caps = testQemuCapsInit()) == NULL)
+    if (qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
 
-    if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver))) {
-        virObjectUnref(driver.caps);
-        return EXIT_FAILURE;
-    }
+    driver.config->allowDiskFormatProbing = true;
 
     if (VIR_ALLOC(testSnapshotXMLVariableLineRegex) < 0)
         goto cleanup;
@@ -227,8 +224,7 @@ mymain(void)
     if (testSnapshotXMLVariableLineRegex)
         regfree(testSnapshotXMLVariableLineRegex);
     VIR_FREE(testSnapshotXMLVariableLineRegex);
-    virObjectUnref(driver.caps);
-    virObjectUnref(driver.xmlopt);
+    qemuTestDriverFree(&driver);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c
index 52cc834..1ebc030 100644
--- a/tests/qemuagenttest.c
+++ b/tests/qemuagenttest.c
@@ -31,6 +31,8 @@
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
+static virQEMUDriver driver;
+
 static int
 testQemuAgentFSFreeze(const void *data)
 {
@@ -909,7 +911,6 @@ static int
 mymain(void)
 {
     int ret = 0;
-    virDomainXMLOptionPtr xmlopt;
 
 #if !WITH_YAJL
     fputs("libvirt not compiled with yajl, skipping this test\n", stderr);
@@ -917,13 +918,13 @@ mymain(void)
 #endif
 
     if (virThreadInitialize() < 0 ||
-        !(xmlopt = virQEMUDriverCreateXMLConf(NULL)))
+        qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
 
     virEventRegisterDefaultImpl();
 
-#define DO_TEST(name)                                           \
-    if (virtTestRun(# name, testQemuAgent ## name, xmlopt) < 0) \
+#define DO_TEST(name)                                                  \
+    if (virtTestRun(# name, testQemuAgent ## name, driver.xmlopt) < 0) \
         ret = -1
 
     DO_TEST(FSFreeze);
@@ -938,7 +939,7 @@ mymain(void)
 
     DO_TEST(Timeout); /* Timeout should always be called last */
 
-    virObjectUnref(xmlopt);
+    qemuTestDriverFree(&driver);
 
     return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/qemuargv2xmltest.c b/tests/qemuargv2xmltest.c
index ea85913..96453e5 100644
--- a/tests/qemuargv2xmltest.c
+++ b/tests/qemuargv2xmltest.c
@@ -145,15 +145,9 @@ mymain(void)
 {
     int ret = 0;
 
-    driver.config = virQEMUDriverConfigNew(false);
-    if (driver.config == NULL)
+    if (qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
 
-    if ((driver.caps = testQemuCapsInit()) == NULL)
-        return EXIT_FAILURE;
-
-    if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
-        return EXIT_FAILURE;
 
 # define DO_TEST_FULL(name, flags)                                      \
     do {                                                                \
@@ -298,9 +292,7 @@ mymain(void)
     DO_TEST("machine-deakeywrap-off-argv");
     DO_TEST("machine-keywrap-none-argv");
 
-    virObjectUnref(driver.config);
-    virObjectUnref(driver.caps);
-    virObjectUnref(driver.xmlopt);
+    qemuTestDriverFree(&driver);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index 368a5e7..3cf7f36 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -338,14 +338,11 @@ mymain(void)
 #endif
 
     if (virThreadInitialize() < 0 ||
-        !(driver.caps = testQemuCapsInit()) ||
-        !(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
+        qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
 
     virEventRegisterDefaultImpl();
 
-    if (!(driver.config = virQEMUDriverConfigNew(false)))
-        return EXIT_FAILURE;
     VIR_FREE(driver.config->spiceListen);
     VIR_FREE(driver.config->vncListen);
     /* some dummy values from 'config file' */
@@ -486,9 +483,7 @@ mymain(void)
                    "device_del", QMP_DEVICE_DELETED("scsi0-0-0-5") QMP_OK,
                    "human-monitor-command", HMP(""));
 
-    virObjectUnref(driver.caps);
-    virObjectUnref(driver.xmlopt);
-    virObjectUnref(driver.config);
+    qemuTestDriverFree(&driver);
     return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index d4432df..cd12356 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -483,8 +483,7 @@ mymain(void)
         return EXIT_FAILURE;
     }
 
-    driver.config = virQEMUDriverConfigNew(false);
-    if (driver.config == NULL)
+    if (qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
 
     driver.privileged = true;
@@ -499,10 +498,6 @@ mymain(void)
     if (VIR_STRDUP_QUIET(driver.config->spiceTLSx509certdir, "/etc/pki/libvirt-spice") < 0)
         return EXIT_FAILURE;
 
-    if ((driver.caps = testQemuCapsInit()) == NULL)
-        return EXIT_FAILURE;
-    if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
-        return EXIT_FAILURE;
     VIR_FREE(driver.config->stateDir);
     if (VIR_STRDUP_QUIET(driver.config->stateDir, "/nowhere") < 0)
         return EXIT_FAILURE;
@@ -1761,9 +1756,7 @@ mymain(void)
             QEMU_CAPS_MACHINE_OPT, QEMU_CAPS_DRIVE, QEMU_CAPS_VIRTIO_SCSI,
             QEMU_CAPS_DEVICE, QEMU_CAPS_VIRTIO_CCW, QEMU_CAPS_VIRTIO_S390);
 
-    virObjectUnref(driver.config);
-    virObjectUnref(driver.caps);
-    virObjectUnref(driver.xmlopt);
+    qemuTestDriverFree(&driver);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 5a20ebc..3552309 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -302,11 +302,10 @@ mymain(void)
     int ret = 0;
     struct testInfo info;
 
-    if ((driver.caps = testQemuCapsInit()) == NULL)
+    if (qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
 
-    if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
-        return EXIT_FAILURE;
+    driver.config->allowDiskFormatProbing = true;
 
 # define DO_TEST_FULL(name, is_different, when)                                \
     do {                                                                       \
@@ -631,8 +630,7 @@ mymain(void)
     DO_TEST("memory-hotplug-dimm");
     DO_TEST("net-udp");
 
-    virObjectUnref(driver.caps);
-    virObjectUnref(driver.xmlopt);
+    qemuTestDriverFree(&driver);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/qemuxmlnstest.c b/tests/qemuxmlnstest.c
index a68e762..40e32dc 100644
--- a/tests/qemuxmlnstest.c
+++ b/tests/qemuxmlnstest.c
@@ -201,15 +201,12 @@ mymain(void)
     if (!abs_top_srcdir)
         abs_top_srcdir = abs_srcdir "/..";
 
-    if (!(driver.config = virQEMUDriverConfigNew(false)))
+    if (qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
+
     VIR_FREE(driver.config->libDir);
     if (VIR_STRDUP_QUIET(driver.config->libDir, "/tmp") < 0)
         return EXIT_FAILURE;
-    if ((driver.caps = testQemuCapsInit()) == NULL)
-        return EXIT_FAILURE;
-    if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
-        return EXIT_FAILURE;
 
 # define DO_TEST_FULL(name, migrateFrom, migrateFd, expectError, ...)   \
     do {                                                                \
@@ -251,9 +248,7 @@ mymain(void)
     DO_TEST("qemu-ns-commandline-ns0", false, NONE);
     DO_TEST("qemu-ns-commandline-ns1", false, NONE);
 
-    virObjectUnref(driver.config);
-    virObjectUnref(driver.caps);
-    virObjectUnref(driver.xmlopt);
+    qemuTestDriverFree(&driver);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index a2f4299..84dfa75 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -526,4 +526,34 @@ qemuTestParseCapabilities(const char *capsFile)
     xmlXPathFreeContext(ctxt);
     return NULL;
 }
+
+int qemuTestDriverInit(virQEMUDriver *driver)
+{
+    driver->config = virQEMUDriverConfigNew(false);
+    if (!driver->config)
+        return -ENOMEM;
+
+    driver->caps = testQemuCapsInit();
+    if (!driver->caps)
+        goto error;
+
+    driver->xmlopt = virQEMUDriverCreateXMLConf(driver);
+    if (!driver->xmlopt)
+        goto error;
+
+    return 0;
+
+ error:
+    virObjectUnref(driver->caps);
+    virObjectUnref(driver->config);
+    virObjectUnref(driver->xmlopt);
+    return -ENOMEM;
+}
+
+void qemuTestDriverFree(virQEMUDriver *driver)
+{
+    virObjectUnref(driver->xmlopt);
+    virObjectUnref(driver->caps);
+    virObjectUnref(driver->config);
+}
 #endif
diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h
index 0ec5dad..6c2d3b5 100644
--- a/tests/testutilsqemu.h
+++ b/tests/testutilsqemu.h
@@ -16,4 +16,6 @@ extern virCPUDefPtr cpuHaswell;
 void testQemuCapsSetCPU(virCapsPtr caps,
                         virCPUDefPtr hostCPU);
 
+int qemuTestDriverInit(virQEMUDriver *driver);
+void qemuTestDriverFree(virQEMUDriver *driver);
 #endif
-- 
2.4.6

--
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]