]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: qemu: use g_autoptr where possible
authorJán Tomko <jtomko@redhat.com>
Tue, 28 Jul 2020 19:58:18 +0000 (21:58 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 3 Aug 2020 05:23:46 +0000 (07:23 +0200)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
tests/qemuagenttest.c
tests/qemublocktest.c
tests/qemucapabilitiestest.c
tests/qemucaps2xmltest.c
tests/qemuhotplugtest.c
tests/qemumemlocktest.c
tests/qemumigparamstest.c
tests/qemumonitortestutils.c
tests/qemuxml2argvtest.c
tests/qemuxml2xmltest.c

index 347438c14ae5eee5cd9cae7b2196f985e9a3822e..607bd97b5c1d47d61d5b4f4bc0130277ed645869 100644 (file)
@@ -175,7 +175,7 @@ testQemuAgentGetFSInfoCommon(virDomainXMLOptionPtr xmlopt,
     int ret = -1;
     g_autofree char *domain_filename = NULL;
     qemuMonitorTestPtr ret_test = NULL;
-    virDomainDefPtr ret_def = NULL;
+    g_autoptr(virDomainDef) ret_def = NULL;
 
     if (!test || !def)
         return -1;
@@ -235,8 +235,6 @@ testQemuAgentGetFSInfoCommon(virDomainXMLOptionPtr xmlopt,
  cleanup:
     if (ret_test)
         qemuMonitorTestFree(ret_test);
-    virDomainDefFree(ret_def);
-
     return ret;
 }
 
@@ -400,7 +398,7 @@ qemuAgentShutdownTestMonitorHandler(qemuMonitorTestPtr test,
                                     const char *cmdstr)
 {
     struct qemuAgentShutdownTestData *data;
-    virJSONValuePtr val = NULL;
+    g_autoptr(virJSONValue) val = NULL;
     virJSONValuePtr args;
     const char *cmdname;
     const char *mode;
@@ -447,7 +445,6 @@ qemuAgentShutdownTestMonitorHandler(qemuMonitorTestPtr test,
     ret = 0;
 
  cleanup:
-    virJSONValueFree(val);
     return ret;
 
 }
index 025e96ab4b76f93283a4a91b27e1a5b37160ceb1..fb5319d7bd4468e4664200bbadf403b99c3ad661 100644 (file)
@@ -987,7 +987,7 @@ mymain(void)
     struct testQemuBlockBitmapBlockcopyData blockbitmapblockcopydata;
     struct testQemuBlockBitmapBlockcommitData blockbitmapblockcommitdata;
     char *capslatest_x86_64 = NULL;
-    virQEMUCapsPtr caps_x86_64 = NULL;
+    g_autoptr(virQEMUCaps) caps_x86_64 = NULL;
     g_autoptr(virHashTable) qmp_schema_x86_64 = NULL;
     virJSONValuePtr qmp_schemaroot_x86_64_blockdev_add = NULL;
     g_autoptr(virStorageSource) bitmapSourceChain = NULL;
index be8741dd5f5a4aff140fd53fe57d3688f554d8c1..81f29c6493d816322e6c55105f4d2ec1c724c767 100644 (file)
@@ -74,7 +74,7 @@ testQemuCaps(const void *opaque)
     g_autofree char *repliesFile = NULL;
     g_autofree char *capsFile = NULL;
     qemuMonitorTestPtr mon = NULL;
-    virQEMUCapsPtr capsActual = NULL;
+    g_autoptr(virQEMUCaps) capsActual = NULL;
     g_autofree char *binary = NULL;
     g_autofree char *actual = NULL;
     unsigned int fakeMicrocodeVersion = 0;
@@ -134,7 +134,6 @@ testQemuCaps(const void *opaque)
     ret = 0;
  cleanup:
     qemuMonitorTestFree(mon);
-    virObjectUnref(capsActual);
     return ret;
 }
 
@@ -145,8 +144,8 @@ testQemuCapsCopy(const void *opaque)
     int ret = -1;
     const testQemuData *data = opaque;
     g_autofree char *capsFile = NULL;
-    virQEMUCapsPtr orig = NULL;
-    virQEMUCapsPtr copy = NULL;
+    g_autoptr(virQEMUCaps) orig = NULL;
+    g_autoptr(virQEMUCaps) copy = NULL;
     g_autofree char *actual = NULL;
 
     capsFile = g_strdup_printf("%s/%s_%s.%s.xml",
@@ -169,8 +168,6 @@ testQemuCapsCopy(const void *opaque)
     ret = 0;
 
  cleanup:
-    virObjectUnref(orig);
-    virObjectUnref(copy);
     return ret;
 }
 
index 5ff4374935cbb1be3f3d39c826e625070a471410..5316a221ff3ccb02efdea7c438264bc29771afa4 100644 (file)
@@ -94,7 +94,7 @@ testQemuGetCaps(char *caps)
 static virCapsPtr
 testGetCaps(char *capsData, const testQemuData *data)
 {
-    virQEMUCapsPtr qemuCaps = NULL;
+    g_autoptr(virQEMUCaps) qemuCaps = NULL;
     virCapsPtr caps = NULL;
     virArch arch = virArchFromString(data->archName);
     g_autofree char *binary = NULL;
@@ -119,11 +119,9 @@ testGetCaps(char *capsData, const testQemuData *data)
         goto error;
     }
 
-    virObjectUnref(qemuCaps);
     return caps;
 
  error:
-    virObjectUnref(qemuCaps);
     virObjectUnref(caps);
     return NULL;
 }
@@ -137,7 +135,7 @@ testQemuCapsXML(const void *opaque)
     g_autofree char *xmlFile = NULL;
     g_autofree char *capsData = NULL;
     g_autofree char *capsXml = NULL;
-    virCapsPtr capsProvided = NULL;
+    g_autoptr(virCaps) capsProvided = NULL;
 
     xmlFile = g_strdup_printf("%s/caps.%s.xml", data->outputDir, data->archName);
 
@@ -160,7 +158,6 @@ testQemuCapsXML(const void *opaque)
 
     ret = 0;
  cleanup:
-    virObjectUnref(capsProvided);
     return ret;
 }
 
index 9d7d2e44e82bdd4b1fc9724bbfbb2dab61907fff..ba644abe8a8ccaa289efe68143a4fccc166023b9 100644 (file)
@@ -244,7 +244,7 @@ testQemuHotplug(const void *data)
     unsigned int device_parse_flags = 0;
     virDomainObjPtr vm = NULL;
     virDomainDeviceDefPtr dev = NULL;
-    virCapsPtr caps = NULL;
+    g_autoptr(virCaps) caps = NULL;
     qemuMonitorTestPtr test_mon = NULL;
     qemuDomainObjPrivatePtr priv = NULL;
 
@@ -349,7 +349,6 @@ testQemuHotplug(const void *data)
         test->vm = NULL;
     }
     virDomainDeviceDefFree(dev);
-    virObjectUnref(caps);
     qemuMonitorTestFree(test_mon);
     return ((ret < 0 && fail) || (!ret && !fail)) ? 0 : -1;
 }
@@ -555,7 +554,7 @@ testQemuHotplugCpuIndividual(const void *opaque)
 {
     const struct testQemuHotplugCpuParams *params = opaque;
     struct testQemuHotplugCpuData *data = NULL;
-    virBitmapPtr map = NULL;
+    g_autoptr(virBitmap) map = NULL;
     int ret = -1;
     int rc;
 
@@ -584,7 +583,6 @@ testQemuHotplugCpuIndividual(const void *opaque)
     ret = testQemuHotplugCpuFinalize(data);
 
  cleanup:
-    virBitmapFree(map);
     testQemuHotplugCpuDataFree(data);
     return ret;
 }
index 0867e3a255ad3ad73eb3daee38dc73642f3d2afe..68e446ba7b6e533589f2dbd5606a2b08ffc81c50 100644 (file)
@@ -30,7 +30,7 @@ static int
 testCompareMemLock(const void *data)
 {
     const struct testInfo *info = data;
-    virDomainDefPtr def = NULL;
+    g_autoptr(virDomainDef) def = NULL;
     g_autofree char *xml = NULL;
     int ret = -1;
 
@@ -45,7 +45,6 @@ testCompareMemLock(const void *data)
     ret = virTestCompareToULL(info->memlock, qemuDomainGetMemLockLimitBytes(def, false));
 
  cleanup:
-    virDomainDefFree(def);
 
     return ret;
 }
@@ -57,7 +56,7 @@ mymain(void)
 {
     int ret = 0;
     g_autofree char *fakerootdir = NULL;
-    virQEMUCapsPtr qemuCaps = NULL;
+    g_autoptr(virQEMUCaps) qemuCaps = NULL;
 
     fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
 
@@ -145,8 +144,6 @@ mymain(void)
     DO_TEST("pseries-locked+hostdev", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
 
  cleanup:
-    virObjectUnref(qemuCaps);
-
     if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
         virFileDeleteTree(fakerootdir);
 
index f4357e0f53d9c35c58be9cf408453ef56b2ff34c..e6e6bf7138b23d278db3696c73b6a87135779ffb 100644 (file)
@@ -60,9 +60,9 @@ qemuMigParamsTestXML2XML(const void *opaque)
     const qemuMigParamsData *data = opaque;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     g_autofree char *xmlFile = NULL;
-    xmlDocPtr doc = NULL;
-    xmlXPathContextPtr ctxt = NULL;
-    qemuMigrationParamsPtr migParams = NULL;
+    g_autoptr(xmlDoc) doc = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
+    g_autoptr(qemuMigrationParams) migParams = NULL;
     g_autofree char *actualXML = NULL;
     int ret = -1;
 
@@ -86,9 +86,6 @@ qemuMigParamsTestXML2XML(const void *opaque)
     ret = 0;
 
  cleanup:
-    qemuMigrationParamsFree(migParams);
-    xmlXPathFreeContext(ctxt);
-    xmlFreeDoc(doc);
     return ret;
 }
 
@@ -101,8 +98,8 @@ qemuMigParamsTestXML(const void *opaque)
     g_autofree char *replyFile = NULL;
     g_autofree char *xmlFile = NULL;
     qemuMonitorTestPtr mon = NULL;
-    virJSONValuePtr params = NULL;
-    qemuMigrationParamsPtr migParams = NULL;
+    g_autoptr(virJSONValue) params = NULL;
+    g_autoptr(qemuMigrationParams) migParams = NULL;
     g_autofree char *actualXML = NULL;
     int ret = -1;
 
@@ -132,8 +129,6 @@ qemuMigParamsTestXML(const void *opaque)
     ret = 0;
 
  cleanup:
-    virJSONValueFree(params);
-    qemuMigrationParamsFree(migParams);
     qemuMonitorTestFree(mon);
     return ret;
 }
@@ -146,9 +141,9 @@ qemuMigParamsTestJSON(const void *opaque)
     g_autofree char *replyFile = NULL;
     g_autofree char *jsonFile = NULL;
     qemuMonitorTestPtr mon = NULL;
-    virJSONValuePtr paramsIn = NULL;
-    virJSONValuePtr paramsOut = NULL;
-    qemuMigrationParamsPtr migParams = NULL;
+    g_autoptr(virJSONValue) paramsIn = NULL;
+    g_autoptr(virJSONValue) paramsOut = NULL;
+    g_autoptr(qemuMigrationParams) migParams = NULL;
     g_autofree char *actualJSON = NULL;
     int ret = -1;
 
@@ -177,9 +172,6 @@ qemuMigParamsTestJSON(const void *opaque)
     ret = 0;
 
  cleanup:
-    virJSONValueFree(paramsIn);
-    virJSONValueFree(paramsOut);
-    qemuMigrationParamsFree(migParams);
     qemuMonitorTestFree(mon);
     return ret;
 }
index 08e90757b1c996cb3dc1dd29bf7b4d5045c6e02f..7fa5ad6a9aadc55d1119132d2418bc3b48f88083 100644 (file)
@@ -720,7 +720,7 @@ qemuMonitorTestProcessGuestAgentSync(qemuMonitorTestPtr test,
                                      qemuMonitorTestItemPtr item G_GNUC_UNUSED,
                                      const char *cmdstr)
 {
-    virJSONValuePtr val = NULL;
+    g_autoptr(virJSONValue) val = NULL;
     virJSONValuePtr args;
     unsigned long long id;
     const char *cmdname;
@@ -756,7 +756,6 @@ qemuMonitorTestProcessGuestAgentSync(qemuMonitorTestPtr test,
     ret = qemuMonitorTestAddResponse(test, retmsg);
 
  cleanup:
-    virJSONValueFree(val);
     return ret;
 }
 
@@ -783,7 +782,7 @@ qemuMonitorTestProcessCommandWithArgs(qemuMonitorTestPtr test,
                                       const char *cmdstr)
 {
     struct qemuMonitorTestHandlerData *data = item->opaque;
-    virJSONValuePtr val = NULL;
+    g_autoptr(virJSONValue) val = NULL;
     virJSONValuePtr args;
     virJSONValuePtr argobj;
     const char *cmdname;
@@ -841,7 +840,6 @@ qemuMonitorTestProcessCommandWithArgs(qemuMonitorTestPtr test,
     ret = qemuMonitorTestAddResponse(test, data->response);
 
  cleanup:
-    virJSONValueFree(val);
     return ret;
 }
 
@@ -905,7 +903,7 @@ qemuMonitorTestProcessCommandWithArgStr(qemuMonitorTestPtr test,
                                         const char *cmdstr)
 {
     struct qemuMonitorTestHandlerData *data = item->opaque;
-    virJSONValuePtr val = NULL;
+    g_autoptr(virJSONValue) val = NULL;
     virJSONValuePtr args;
     g_autofree char *argstr = NULL;
     const char *cmdname;
@@ -946,7 +944,6 @@ qemuMonitorTestProcessCommandWithArgStr(qemuMonitorTestPtr test,
     ret = qemuMonitorTestAddResponse(test, data->response);
 
  cleanup:
-    virJSONValueFree(val);
     return ret;
 }
 
index dcbe3b77a2af33ce92d1710c4ca6fa997994ce48..f28e88b6e5fe70c91e38a8e88190a3c6243116a8 100644 (file)
@@ -565,9 +565,9 @@ testCompareXMLToArgv(const void *data)
     int ret = -1;
     virDomainObjPtr vm = NULL;
     virDomainChrSourceDef monitor_chr;
-    virConnectPtr conn;
+    g_autoptr(virConnect) conn = NULL;
     char *log = NULL;
-    virCommandPtr cmd = NULL;
+    g_autoptr(virCommand) cmd = NULL;
     qemuDomainObjPrivatePtr priv = NULL;
 
     if (info->arch != VIR_ARCH_NONE && info->arch != VIR_ARCH_X86_64)
@@ -688,11 +688,9 @@ testCompareXMLToArgv(const void *data)
  cleanup:
     VIR_FREE(log);
     virDomainChrSourceDefClear(&monitor_chr);
-    virCommandFree(cmd);
     virObjectUnref(vm);
     virSetConnectSecret(NULL);
     virSetConnectStorage(NULL);
-    virObjectUnref(conn);
     if (info->arch != VIR_ARCH_NONE && info->arch != VIR_ARCH_X86_64)
         qemuTestSetHostArch(&driver, VIR_ARCH_NONE);
 
@@ -716,7 +714,7 @@ mymain(void)
 {
     int ret = 0;
     g_autofree char *fakerootdir = NULL;
-    virHashTablePtr capslatest = NULL;
+    g_autoptr(virHashTable) capslatest = NULL;
 
     fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
 
@@ -3362,7 +3360,6 @@ mymain(void)
 
     VIR_FREE(driver.config->nbdTLSx509certdir);
     qemuTestDriverFree(&driver);
-    virHashFree(capslatest);
     virFileWrapperClearPrefixes();
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
index 018077a64a2ace4a9f325254c63ab77b94740756..74b69594089a12f8a8c132c99bf5f26527ebc5e7 100644 (file)
@@ -133,7 +133,7 @@ mymain(void)
     int ret = 0;
     g_autofree char *fakerootdir = NULL;
     virQEMUDriverConfigPtr cfg = NULL;
-    virHashTablePtr capslatest = NULL;
+    g_autoptr(virHashTable) capslatest = NULL;
     g_autoptr(virConnect) conn = NULL;
 
     capslatest = testQemuGetLatestCaps();
@@ -1499,7 +1499,6 @@ mymain(void)
     if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
         virFileDeleteTree(fakerootdir);
 
-    virHashFree(capslatest);
     qemuTestDriverFree(&driver);
     virFileWrapperClearPrefixes();