[PATCH 2/3] objecteventtest: Check for virNetwork* return values

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

 



Lets not give a bad example and check for return values of
virNetwork* APIs called within the test. Even though it's
unlikely that any API will fail, it can happen. We're connected
to the test driver after all, and our API sequence is correct. So
test driver should fail only in case of bug or OOM.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 tests/objecteventtest.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/tests/objecteventtest.c b/tests/objecteventtest.c
index 052dbe5..95fbfec 100644
--- a/tests/objecteventtest.c
+++ b/tests/objecteventtest.c
@@ -417,7 +417,7 @@ testNetworkCreateXML(const void *data)
                            &counter, NULL);
     net = virNetworkCreateXML(test->conn, networkDef);
 
-    if (virEventRunDefaultImpl() < 0) {
+    if (!net || virEventRunDefaultImpl() < 0) {
         ret = -1;
         goto cleanup;
     }
@@ -429,10 +429,10 @@ testNetworkCreateXML(const void *data)
 
  cleanup:
     virConnectNetworkEventDeregisterAny(test->conn, id);
-    virNetworkDestroy(net);
-
-    virNetworkFree(net);
-
+    if (net) {
+        virNetworkDestroy(net);
+        virNetworkFree(net);
+    }
     return ret;
 }
 
@@ -455,7 +455,7 @@ testNetworkDefine(const void *data)
     /* Make sure the define event is triggered */
     net = virNetworkDefineXML(test->conn, networkDef);
 
-    if (virEventRunDefaultImpl() < 0) {
+    if (!net || virEventRunDefaultImpl() < 0) {
         ret = -1;
         goto cleanup;
     }
@@ -481,7 +481,8 @@ testNetworkDefine(const void *data)
 
  cleanup:
     virConnectNetworkEventDeregisterAny(test->conn, id);
-    virNetworkFree(net);
+    if (net)
+        virNetworkFree(net);
 
     return ret;
 }
@@ -494,6 +495,9 @@ testNetworkStartStopEvent(const void *data)
     int id;
     int ret = 0;
 
+    if (!test->net)
+        return -1;
+
     lifecycleEventCounter_reset(&counter);
 
     id = virConnectNetworkEventRegisterAny(test->conn, test->net,
@@ -509,7 +513,7 @@ testNetworkStartStopEvent(const void *data)
     }
 
     if (counter.startEvents != 1 || counter.stopEvents != 1 ||
-            counter.unexpectedEvents > 0) {
+        counter.unexpectedEvents > 0) {
         ret = -1;
         goto cleanup;
     }
@@ -567,13 +571,16 @@ mymain(void)
         ret = EXIT_FAILURE;
 
     /* Define a test network */
-    test.net = virNetworkDefineXML(test.conn, networkDef);
+    if (!(test.net = virNetworkDefineXML(test.conn, networkDef)))
+        ret = EXIT_FAILURE;
     if (virtTestRun("Network start stop events ", testNetworkStartStopEvent, &test) < 0)
         ret = EXIT_FAILURE;
 
     /* Cleanup */
-    virNetworkUndefine(test.net);
-    virNetworkFree(test.net);
+    if (test.net) {
+        virNetworkUndefine(test.net);
+        virNetworkFree(test.net);
+    }
     virConnectClose(test.conn);
     virEventRemoveTimeout(timer);
 
-- 
2.0.5

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