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

[libvirt] [PATCH v1 36/37] Adapt to VIR_ALLOC and virAsprintf in tests/*



---
 tests/commandtest.c              |  8 ++------
 tests/libvirtdconftest.c         |  4 +---
 tests/qemumonitortestutils.c     | 17 +++++------------
 tests/securityselinuxlabeltest.c | 21 +++++----------------
 tests/securityselinuxtest.c      |  8 +++-----
 tests/virnetmessagetest.c        | 20 +++++---------------
 tests/virstoragetest.c           |  5 +----
 7 files changed, 22 insertions(+), 61 deletions(-)

diff --git a/tests/commandtest.c b/tests/commandtest.c
index ec69dbd..62f0277 100644
--- a/tests/commandtest.c
+++ b/tests/commandtest.c
@@ -820,10 +820,8 @@ static int test20(const void *unused ATTRIBUTE_UNUSED)
 
     sigaction(SIGPIPE, &sig_action, NULL);
 
-    if (virAsprintf(&buf, "1\n%100000d\n", 2) < 0) {
-        virReportOOMError();
+    if (virAsprintf(&buf, "1\n%100000d\n", 2) < 0)
         goto cleanup;
-    }
     virCommandSetInputBuffer(cmd, buf);
 
     if (virCommandRun(cmd, NULL) < 0) {
@@ -996,10 +994,8 @@ mymain(void)
         return EXIT_FAILURE;
 
     virEventRegisterDefaultImpl();
-    if (VIR_ALLOC(test) < 0) {
-        virReportOOMError();
+    if (VIR_ALLOC(test) < 0)
         goto cleanup;
-    }
 
     if (virMutexInit(&test->lock) < 0) {
         printf("Unable to init mutex: %d\n", errno);
diff --git a/tests/libvirtdconftest.c b/tests/libvirtdconftest.c
index d45c31a..ba61a0f 100644
--- a/tests/libvirtdconftest.c
+++ b/tests/libvirtdconftest.c
@@ -78,10 +78,8 @@ munge_param(const char *datain,
         strlen(replace) +
         strlen(eol) + 1;
 
-    if (VIR_ALLOC_N(dataout, dataoutlen) < 0) {
-        virReportOOMError();
+    if (VIR_ALLOC_N(dataout, dataoutlen) < 0)
         return NULL;
-    }
     memcpy(dataout, datain, (eq - datain) + 1);
     memcpy(dataout + (eq - datain) + 1,
            replace, strlen(replace));
diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c
index 1a4bb88..56368a2 100644
--- a/tests/qemumonitortestutils.c
+++ b/tests/qemumonitortestutils.c
@@ -87,10 +87,8 @@ static int qemuMonitorTestAddReponse(qemuMonitorTestPtr test,
 
     if (have < want) {
         size_t need = want - have;
-        if (VIR_EXPAND_N(test->outgoing, test->outgoingCapacity, need) < 0) {
-            virReportOOMError();
+        if (VIR_EXPAND_N(test->outgoing, test->outgoingCapacity, need) < 0)
             return -1;
-        }
     }
 
     want -= 2;
@@ -403,7 +401,7 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test,
     qemuMonitorTestItemPtr item;
 
     if (VIR_ALLOC(item) < 0)
-        goto no_memory;
+        goto error;
 
     if (VIR_STRDUP(item->command_name, command_name) < 0 ||
         VIR_STRDUP(item->response, response) < 0)
@@ -412,7 +410,7 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test,
     virMutexLock(&test->lock);
     if (VIR_EXPAND_N(test->items, test->nitems, 1) < 0) {
         virMutexUnlock(&test->lock);
-        goto no_memory;
+        goto error;
     }
     test->items[test->nitems - 1] = item;
 
@@ -420,8 +418,6 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test,
 
     return 0;
 
-no_memory:
-    virReportOOMError();
 error:
     qemuMonitorTestItemFree(item);
     return -1;
@@ -457,7 +453,7 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt)
     char *tmpdir_template = NULL;
 
     if (VIR_ALLOC(test) < 0)
-        goto no_memory;
+        goto error;
 
     if (virMutexInit(&test->lock) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -478,7 +474,7 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt)
     tmpdir_template = NULL;
 
     if (virAsprintf(&path, "%s/qemumonitorjsontest.sock", test->tmpdir) < 0)
-        goto no_memory;
+        goto error;
 
     test->json = json;
     if (!(test->vm = virDomainObjNew(xmlopt)))
@@ -538,9 +534,6 @@ cleanup:
     VIR_FREE(path);
     return test;
 
-no_memory:
-    virReportOOMError();
-
 error:
     VIR_FREE(tmpdir_template);
     qemuMonitorTestFree(test);
diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c
index 5ae4f57..8a492ba 100644
--- a/tests/securityselinuxlabeltest.c
+++ b/tests/securityselinuxlabeltest.c
@@ -61,10 +61,8 @@ testSELinuxMungePath(char **path)
     char *tmp;
 
     if (virAsprintf(&tmp, "%s/securityselinuxlabeldata%s",
-                    abs_builddir, *path) < 0) {
-        virReportOOMError();
+                    abs_builddir, *path) < 0)
         return -1;
-    }
 
     VIR_FREE(*path);
     *path = tmp;
@@ -84,10 +82,8 @@ testSELinuxLoadFileList(const char *testname,
     *nfiles = 0;
 
     if (virAsprintf(&path, "%s/securityselinuxlabeldata/%s.txt",
-                    abs_srcdir, testname) < 0) {
-        virReportOOMError();
+                    abs_srcdir, testname) < 0)
         goto cleanup;
-    }
 
     if (!(fp = fopen(path, "r"))) {
         goto cleanup;
@@ -96,10 +92,8 @@ testSELinuxLoadFileList(const char *testname,
     while (!feof(fp)) {
         char *line;
         char *file, *context;
-        if (VIR_ALLOC_N(line, 1024) < 0) {
-            virReportOOMError();
+        if (VIR_ALLOC_N(line, 1024) < 0)
             goto cleanup;
-        }
         if (!fgets(line, 1024, fp)) {
             if (!feof(fp))
                 goto cleanup;
@@ -112,7 +106,6 @@ testSELinuxLoadFileList(const char *testname,
 
         if (virAsprintf(&file, "%s/securityselinuxlabeldata%s", abs_builddir, line) < 0) {
             VIR_FREE(line);
-            virReportOOMError();
             goto cleanup;
         }
         if (*tmp != '\0' && *tmp != '\n') {
@@ -128,10 +121,8 @@ testSELinuxLoadFileList(const char *testname,
             context = NULL;
         }
 
-        if (VIR_EXPAND_N(*files, *nfiles, 1) < 0) {
-            virReportOOMError();
+        if (VIR_EXPAND_N(*files, *nfiles, 1) < 0)
             goto cleanup;
-        }
 
         (*files)[(*nfiles)-1].file = file;
         (*files)[(*nfiles)-1].context = context;
@@ -155,10 +146,8 @@ testSELinuxLoadDef(const char *testname)
     size_t i;
 
     if (virAsprintf(&xmlfile, "%s/securityselinuxlabeldata/%s.xml",
-                    abs_srcdir, testname) < 0) {
-        virReportOOMError();
+                    abs_srcdir, testname) < 0)
         goto cleanup;
-    }
 
     if (virFileReadAll(xmlfile, 1024*1024, &xmlstr) < 0) {
         goto cleanup;
diff --git a/tests/securityselinuxtest.c b/tests/securityselinuxtest.c
index 8d85c68..e2806c1 100644
--- a/tests/securityselinuxtest.c
+++ b/tests/securityselinuxtest.c
@@ -69,13 +69,13 @@ testBuildDomainDef(bool dynamic,
     virSecurityLabelDefPtr secdef;
 
     if (VIR_ALLOC(def) < 0)
-        goto no_memory;
+        goto error;
 
     if (VIR_ALLOC_N(def->seclabels, 1) < 0)
-        goto no_memory;
+        goto error;
 
     if (VIR_ALLOC(secdef) < 0)
-        goto no_memory;
+        goto error;
 
     def->virtType = VIR_DOMAIN_VIRT_KVM;
     def->seclabels[0] = secdef;
@@ -91,8 +91,6 @@ testBuildDomainDef(bool dynamic,
 
     return def;
 
-no_memory:
-    virReportOOMError();
 error:
     virDomainDefFree(def);
     return NULL;
diff --git a/tests/virnetmessagetest.c b/tests/virnetmessagetest.c
index 062c3ff..1aa4c25 100644
--- a/tests/virnetmessagetest.c
+++ b/tests/virnetmessagetest.c
@@ -49,10 +49,8 @@ static int testMessageHeaderEncode(const void *args ATTRIBUTE_UNUSED)
     unsigned long msg_buf_size = VIR_NET_MESSAGE_INITIAL + VIR_NET_MESSAGE_LEN_MAX;
     int ret = -1;
 
-    if (!msg) {
-        virReportOOMError();
+    if (!msg)
         return -1;
-    }
 
     msg->header.prog = 0x11223344;
     msg->header.vers = 0x01;
@@ -101,16 +99,12 @@ static int testMessageHeaderDecode(const void *args ATTRIBUTE_UNUSED)
     };
     int ret = -1;
 
-    if (!msg) {
-        virReportOOMError();
+    if (!msg)
         return -1;
-    }
 
     msg->bufferLength = 4;
-    if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0) {
-        virReportOOMError();
+    if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0)
         goto cleanup;
-    }
     memcpy(msg->buffer, input_buf, msg->bufferLength);
 
     msg->header.prog = 0x11223344;
@@ -225,10 +219,8 @@ static int testMessagePayloadEncode(const void *args ATTRIBUTE_UNUSED)
         0x00, 0x00, 0x00, 0x00,  /* Error network pointer */
     };
 
-    if (!msg) {
-        virReportOOMError();
+    if (!msg)
         return -1;
-    }
 
     memset(&err, 0, sizeof(err));
 
@@ -336,10 +328,8 @@ static int testMessagePayloadDecode(const void *args ATTRIBUTE_UNUSED)
     int ret = -1;
 
     msg->bufferLength = 4;
-    if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0) {
-        virReportOOMError();
+    if (VIR_ALLOC_N(msg->buffer, msg->bufferLength) < 0)
         goto cleanup;
-    }
     memcpy(msg->buffer, input_buffer, msg->bufferLength);
     memset(&err, 0, sizeof(err));
 
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index fef4b37..61d36f7 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -98,10 +98,8 @@ testPrepImages(void)
         virAsprintf(&absqcow2, "%s/qcow2", datadir) < 0 ||
         virAsprintf(&abswrap, "%s/wrap", datadir) < 0 ||
         virAsprintf(&absqed, "%s/qed", datadir) < 0 ||
-        virAsprintf(&abslink2, "%s/sub/link2", datadir) < 0) {
-        virReportOOMError();
+        virAsprintf(&abslink2, "%s/sub/link2", datadir) < 0)
         goto cleanup;
-    }
 
     if (virFileMakePath(datadir "/sub") < 0) {
         fprintf(stderr, "unable to create directory %s\n", datadir "/sub");
@@ -271,7 +269,6 @@ testStorageChain(const void *args)
                         NULLSTR(elt->directory),
                         elt->backingStoreFormat, elt->backingStoreIsFile,
                         elt->capacity, elt->encrypted) < 0) {
-            virReportOOMError();
             VIR_FREE(expect);
             VIR_FREE(actual);
             goto cleanup;
-- 
1.8.1.5


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