[libvirt PATCH 18/24] tests: qemu: remove pointless labels

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

 



Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 tests/qemuagenttest.c        | 28 ++++++--------------
 tests/qemucapsprobemock.c    |  3 +--
 tests/qemucommandutiltest.c  |  9 +++----
 tests/qemumonitorjsontest.c  | 50 +++++++++++++++---------------------
 tests/qemumonitortestutils.c | 45 ++++++++++----------------------
 tests/qemuxml2argvtest.c     | 21 ++++-----------
 6 files changed, 51 insertions(+), 105 deletions(-)

diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c
index 10d02bd1b4..bef6dfd152 100644
--- a/tests/qemuagenttest.c
+++ b/tests/qemuagenttest.c
@@ -471,51 +471,39 @@ qemuAgentShutdownTestMonitorHandler(qemuMonitorTest *test,
     virJSONValue *args;
     const char *cmdname;
     const char *mode;
-    int ret = -1;
 
     data = qemuMonitorTestItemGetPrivateData(item);
 
     if (!(val = virJSONValueFromString(cmdstr)))
         return -1;
 
-    if (!(cmdname = virJSONValueObjectGetString(val, "execute"))) {
-        ret = qemuMonitorTestAddErrorResponse(test, "Missing command name in %s", cmdstr);
-        goto cleanup;
-    }
+    if (!(cmdname = virJSONValueObjectGetString(val, "execute")))
+        return qemuMonitorTestAddErrorResponse(test, "Missing command name in %s", cmdstr);
 
     if (STRNEQ(cmdname, "guest-shutdown")) {
-        ret = qemuMonitorTestAddInvalidCommandResponse(test, "guest-shutdown",
+        return qemuMonitorTestAddInvalidCommandResponse(test, "guest-shutdown",
                                                        cmdname);
-        goto cleanup;
     }
 
     if (!(args = virJSONValueObjectGet(val, "arguments"))) {
-        ret = qemuMonitorTestAddErrorResponse(test,
+        return qemuMonitorTestAddErrorResponse(test,
                                               "Missing arguments section");
-        goto cleanup;
     }
 
-    if (!(mode = virJSONValueObjectGetString(args, "mode"))) {
-        ret = qemuMonitorTestAddErrorResponse(test, "Missing shutdown mode");
-        goto cleanup;
-    }
+    if (!(mode = virJSONValueObjectGetString(args, "mode")))
+        return qemuMonitorTestAddErrorResponse(test, "Missing shutdown mode");
 
     if (STRNEQ(mode, data->mode)) {
-        ret = qemuMonitorTestAddErrorResponse(test,
+        return qemuMonitorTestAddErrorResponse(test,
                                               "expected shutdown mode '%s' got '%s'",
                                               data->mode, mode);
-        goto cleanup;
     }
 
     /* now don't reply but return a qemu agent event */
     qemuAgentNotifyEvent(qemuMonitorTestGetAgent(test),
                          data->event);
 
-    ret = 0;
-
- cleanup:
-    return ret;
-
+    return 0;
 }
 
 
diff --git a/tests/qemucapsprobemock.c b/tests/qemucapsprobemock.c
index 27539d04a1..915036d178 100644
--- a/tests/qemucapsprobemock.c
+++ b/tests/qemucapsprobemock.c
@@ -104,7 +104,7 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon,
 
         /* Ignore QMP greeting */
         if (virJSONValueObjectHasKey(value, "QMP"))
-            goto cleanup;
+            return 0;
 
         if (first)
             first = false;
@@ -114,6 +114,5 @@ qemuMonitorJSONIOProcessLine(qemuMonitor *mon,
         printLineSkipEmpty(json, stdout);
     }
 
- cleanup:
     return ret;
 }
diff --git a/tests/qemucommandutiltest.c b/tests/qemucommandutiltest.c
index e1cab0be90..ae86ef9ea0 100644
--- a/tests/qemucommandutiltest.c
+++ b/tests/qemucommandutiltest.c
@@ -40,7 +40,6 @@ testQemuCommandBuildFromJSON(const void *opaque)
     g_autoptr(virJSONValue) val = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     g_autofree char *result = NULL;
-    int ret = -1;
 
     if (!(val = virJSONValueFromString(data->props))) {
         fprintf(stderr, "Failed to parse JSON string '%s'", data->props);
@@ -51,7 +50,7 @@ testQemuCommandBuildFromJSON(const void *opaque)
         fprintf(stderr,
                 "\nvirQEMUBuildCommandlineJSON failed process JSON:\n%s\n",
                 data->props);
-        goto cleanup;
+        return -1;
     }
 
     result = virBufferContentAndReset(&buf);
@@ -60,12 +59,10 @@ testQemuCommandBuildFromJSON(const void *opaque)
         fprintf(stderr, "\nFailed to create object string. "
                 "\nExpected:\n'%s'\nGot:\n'%s'",
                 NULLSTR(data->expectprops), NULLSTR(result));
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 static int
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index b68351d9d8..1e4c2fd14e 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -1719,7 +1719,6 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationStats(const void *opaque)
 {
     const testGenericData *data = opaque;
     virDomainXMLOption *xmlopt = data->xmlopt;
-    int ret = -1;
     qemuMonitorMigrationStats stats, expectedStats;
     g_autofree char *error = NULL;
     g_autoptr(qemuMonitorTest) test = NULL;
@@ -1756,33 +1755,31 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationStats(const void *opaque)
                                "    },"
                                "    \"id\": \"libvirt-14\""
                                "}") < 0)
-        goto cleanup;
+        return -1;
 
     if (qemuMonitorJSONGetMigrationStats(qemuMonitorTestGetMonitor(test),
                                          &stats, &error) < 0)
-        goto cleanup;
+        return -1;
 
     if (memcmp(&stats, &expectedStats, sizeof(stats)) != 0 || error) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        "Invalid migration statistics");
-        goto cleanup;
+        return -1;
     }
 
     memset(&stats, 0, sizeof(stats));
     if (qemuMonitorJSONGetMigrationStats(qemuMonitorTestGetMonitor(test),
                                          &stats, &error) < 0)
-        goto cleanup;
+        return -1;
 
     if (stats.status != QEMU_MONITOR_MIGRATION_STATUS_ERROR ||
         STRNEQ_NULLABLE(error, "It's broken")) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        "Invalid failed migration status");
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 static int
@@ -2163,7 +2160,6 @@ testQemuMonitorJSONGetCPUData(const void *opaque)
     g_autofree char *dataFile = NULL;
     g_autofree char *jsonStr = NULL;
     g_autofree char *actual = NULL;
-    int ret = -1;
     g_autoptr(qemuMonitorTest) test = NULL;
 
     if (!(test = qemuMonitorTestNewSchema(data->xmlopt, data->schema)))
@@ -2175,7 +2171,7 @@ testQemuMonitorJSONGetCPUData(const void *opaque)
                                abs_srcdir, data->name);
 
     if (virTestLoadFile(jsonFile, &jsonStr) < 0)
-        goto cleanup;
+        return -1;
 
     if (qemuMonitorTestAddItem(test, "qom-list",
                                "{"
@@ -2191,24 +2187,22 @@ testQemuMonitorJSONGetCPUData(const void *opaque)
                                "    ],"
                                "    \"id\": \"libvirt-19\""
                                "}") < 0)
-        goto cleanup;
+        return -1;
 
     if (qemuMonitorTestAddItem(test, "qom-get", jsonStr) < 0)
-        goto cleanup;
+        return -1;
 
     if (qemuMonitorJSONGetGuestCPUx86(qemuMonitorTestGetMonitor(test),
                                       &cpuData, NULL) < 0)
-        goto cleanup;
+        return -1;
 
     if (!(actual = virCPUDataFormat(cpuData)))
-        goto cleanup;
+        return -1;
 
     if (virTestCompareToFile(actual, dataFile) < 0)
-        goto cleanup;
+        return -1;
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 static int
@@ -2217,7 +2211,7 @@ testQemuMonitorJSONGetNonExistingCPUData(const void *opaque)
     const testGenericData *data = opaque;
     virDomainXMLOption *xmlopt = data->xmlopt;
     g_autoptr(virCPUData) cpuData = NULL;
-    int rv, ret = -1;
+    int rv;
     g_autoptr(qemuMonitorTest) test = NULL;
 
     if (!(test = qemuMonitorTestNewSchema(xmlopt, data->schema)))
@@ -2231,26 +2225,24 @@ testQemuMonitorJSONGetNonExistingCPUData(const void *opaque)
                                "        \"desc\": \"The command qom-list has not been found\""
                                "    }"
                                "}") < 0)
-        goto cleanup;
+        return -1;
 
     rv = qemuMonitorJSONGetGuestCPUx86(qemuMonitorTestGetMonitor(test),
                                        &cpuData, NULL);
     if (rv != -2) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "Unexpected return value %d, expecting -2", rv);
-        goto cleanup;
+        return -1;
     }
 
     if (cpuData) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "Unexpected allocation of data = %p, expecting NULL",
                        cpuData);
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 static int
@@ -2584,10 +2576,10 @@ testQAPISchemaValidate(const void *opaque)
     int ret = -1;
 
     if (virQEMUQAPISchemaPathGet(data->query, data->schema, &schemaroot) < 0)
-        goto cleanup;
+        return -1;
 
     if (!(json = virJSONValueFromString(data->json)))
-        goto cleanup;
+        return -1;
 
     if ((testQEMUSchemaValidate(json, schemaroot, data->schema, false,
                                 &debug) == 0) != data->success) {
@@ -2604,8 +2596,6 @@ testQAPISchemaValidate(const void *opaque)
         VIR_FREE(debugstr);
     }
 
-
- cleanup:
     return ret;
 }
 
diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c
index 8618e6bbef..71b26c326e 100644
--- a/tests/qemumonitortestutils.c
+++ b/tests/qemumonitortestutils.c
@@ -708,38 +708,25 @@ qemuMonitorTestProcessGuestAgentSync(qemuMonitorTest *test,
     unsigned long long id;
     const char *cmdname;
     g_autofree char *retmsg = NULL;
-    int ret = -1;
 
     if (!(val = virJSONValueFromString(cmdstr)))
         return -1;
 
-    if (!(cmdname = virJSONValueObjectGetString(val, "execute"))) {
-        ret = qemuMonitorTestAddErrorResponse(test, "Missing guest-sync command name");
-        goto cleanup;
-    }
+    if (!(cmdname = virJSONValueObjectGetString(val, "execute")))
+        return qemuMonitorTestAddErrorResponse(test, "Missing guest-sync command name");
 
-    if (STRNEQ(cmdname, "guest-sync")) {
-        ret = qemuMonitorTestAddInvalidCommandResponse(test, "guest-sync", cmdname);
-        goto cleanup;
-    }
+    if (STRNEQ(cmdname, "guest-sync"))
+        return qemuMonitorTestAddInvalidCommandResponse(test, "guest-sync", cmdname);
 
-    if (!(args = virJSONValueObjectGet(val, "arguments"))) {
-        ret = qemuMonitorTestAddErrorResponse(test, "Missing arguments for guest-sync");
-        goto cleanup;
-    }
+    if (!(args = virJSONValueObjectGet(val, "arguments")))
+        return qemuMonitorTestAddErrorResponse(test, "Missing arguments for guest-sync");
 
-    if (virJSONValueObjectGetNumberUlong(args, "id", &id)) {
-        ret = qemuMonitorTestAddErrorResponse(test, "Missing id for guest sync");
-        goto cleanup;
-    }
+    if (virJSONValueObjectGetNumberUlong(args, "id", &id))
+        return qemuMonitorTestAddErrorResponse(test, "Missing id for guest sync");
 
     retmsg = g_strdup_printf("{\"return\":%llu}", id);
 
-
-    ret = qemuMonitorTestAddResponse(test, retmsg);
-
- cleanup:
-    return ret;
+    return qemuMonitorTestAddResponse(test, retmsg);
 }
 
 
@@ -1194,10 +1181,10 @@ qemuMonitorTestNewFromFile(const char *fileName,
     char *singleReply;
 
     if (virTestLoadFile(fileName, &json) < 0)
-        goto cleanup;
+        return NULL;
 
     if (simple && !(test = qemuMonitorTestNewSimple(xmlopt)))
-        goto cleanup;
+        return NULL;
 
     /* Our JSON parser expects replies to be separated by a newline character.
      * Hence we must preprocess the file a bit. */
@@ -1237,13 +1224,11 @@ qemuMonitorTestNewFromFile(const char *fileName,
     if (test && qemuMonitorTestAddItem(test, NULL, singleReply) < 0)
         goto error;
 
- cleanup:
     return test;
 
  error:
     qemuMonitorTestFree(test);
-    test = NULL;
-    goto cleanup;
+    return NULL;
 }
 
 
@@ -1341,7 +1326,7 @@ qemuMonitorTestNewFromFileFull(const char *fileName,
 
     if (!(ret = qemuMonitorTestNew(driver->xmlopt, vm, driver, NULL,
                                    qmpschema)))
-        goto cleanup;
+        return NULL;
 
     tmp = jsonstr;
     command = tmp;
@@ -1393,13 +1378,11 @@ qemuMonitorTestNewFromFileFull(const char *fileName,
             goto error;
     }
 
- cleanup:
     return ret;
 
  error:
     qemuMonitorTestFree(ret);
-    ret = NULL;
-    goto cleanup;
+    return NULL;
 }
 
 
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 90b7da8055..4cc9fccd4f 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -107,7 +107,6 @@ fakeStoragePoolLookupByName(virConnectPtr conn,
                             const char *name)
 {
     g_autofree char *xmlpath = NULL;
-    virStoragePoolPtr ret = NULL;
 
     if (STRNEQ(name, "inactive")) {
         xmlpath = g_strdup_printf("%s/%s%s.xml", abs_srcdir,
@@ -116,14 +115,11 @@ fakeStoragePoolLookupByName(virConnectPtr conn,
         if (!virFileExists(xmlpath)) {
             virReportError(VIR_ERR_NO_STORAGE_POOL,
                            "File '%s' not found", xmlpath);
-            goto cleanup;
+            return NULL;
         }
     }
 
-    ret = virGetStoragePool(conn, name, fakeUUID, NULL, NULL);
-
- cleanup:
-    return ret;
+    return virGetStoragePool(conn, name, fakeUUID, NULL, NULL);
 }
 
 
@@ -132,7 +128,6 @@ fakeStorageVolLookupByName(virStoragePoolPtr pool,
                            const char *name)
 {
     g_auto(GStrv) volinfo = NULL;
-    virStorageVolPtr ret = NULL;
 
     if (STREQ(pool->name, "inactive")) {
         virReportError(VIR_ERR_OPERATION_INVALID,
@@ -155,15 +150,11 @@ fakeStorageVolLookupByName(virStoragePoolPtr pool,
     if (!volinfo[1])
         goto fallback;
 
-    ret = virGetStorageVol(pool->conn, pool->name, volinfo[1], volinfo[0],
+    return virGetStorageVol(pool->conn, pool->name, volinfo[1], volinfo[0],
                            NULL, NULL);
 
- cleanup:
-    return ret;
-
  fallback:
-    ret = virGetStorageVol(pool->conn, pool->name, name, "block", NULL, NULL);
-    goto cleanup;
+    return virGetStorageVol(pool->conn, pool->name, name, "block", NULL, NULL);
 }
 
 static int
@@ -210,11 +201,9 @@ fakeStoragePoolGetXMLDesc(virStoragePoolPtr pool,
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "failed to load XML file '%s'",
                        xmlpath);
-        goto cleanup;
+        return NULL;
     }
 
- cleanup:
-
     return xmlbuf;
 }
 
-- 
2.31.1




[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