[PATCHv2 03/14] event [squash with next]: test shared state driver in test:///default

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

 



The updated testsuite fails without the rest of this patch.
Valgrind didn't report any leaks.

* tests/objecteventtest.c (testDomainStartStopEvent): Enhance to
cover this.
(timeout, mymain): Ensure test fails rather than blocks.

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
---
 tests/objecteventtest.c | 49 ++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 42 insertions(+), 7 deletions(-)

diff --git a/tests/objecteventtest.c b/tests/objecteventtest.c
index 833c0fc..6f657d2 100644
--- a/tests/objecteventtest.c
+++ b/tests/objecteventtest.c
@@ -265,8 +265,10 @@ testDomainStartStopEvent(const void *data)
     lifecycleEventCounter counter;
     int eventId = VIR_DOMAIN_EVENT_ID_LIFECYCLE;
     int id;
-    int ret = 0;
+    int ret = -1;
     virDomainPtr dom;
+    virConnectPtr conn2 = NULL;
+    virDomainPtr dom2 = NULL;

     lifecycleEventCounter_reset(&counter);

@@ -282,20 +284,40 @@ testDomainStartStopEvent(const void *data)
     virDomainDestroy(dom);
     virDomainCreate(dom);

-    if (virEventRunDefaultImpl() < 0) {
-        ret = -1;
+    if (virEventRunDefaultImpl() < 0)
         goto cleanup;
-    }

     if (counter.startEvents != 1 || counter.stopEvents != 1 ||
-            counter.unexpectedEvents > 0) {
-        ret = -1;
+            counter.unexpectedEvents > 0)
+        goto cleanup;
+
+    /* Repeat the test, but this time, trigger the events via an
+     * alternate connection.  */
+    if (!(conn2 = virConnectOpen("test:///default")))
+        goto cleanup;
+    if (!(dom2 = virDomainLookupByName(conn2, "test")))
         goto cleanup;
-    }

+    if (virDomainDestroy(dom2) < 0)
+        goto cleanup;
+    if (virDomainCreate(dom2) < 0)
+        goto cleanup;
+
+    if (virEventRunDefaultImpl() < 0)
+        goto cleanup;
+
+    if (counter.startEvents != 2 || counter.stopEvents != 2 ||
+            counter.unexpectedEvents > 0)
+        goto cleanup;
+
+    ret = 0;
 cleanup:
     virConnectDomainEventDeregisterAny(test->conn, id);
     virDomainFree(dom);
+    if (dom2)
+        virDomainFree(dom2);
+    if (conn2)
+        virConnectClose(conn2);

     return ret;
 }
@@ -419,14 +441,26 @@ cleanup:
     return ret;
 }

+static void
+timeout(int id ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED)
+{
+    fputs("test taking too long; giving up", stderr);
+    _exit(EXIT_FAILURE);
+}
+
 static int
 mymain(void)
 {
     objecteventTest test;
     int ret = EXIT_SUCCESS;
+    int timer;

     virEventRegisterDefaultImpl();

+    /* Set up a timer to abort this test if it takes 10 seconds.  */
+    if ((timer = virEventAddTimeout(10 * 1000, timeout, NULL, NULL)) < 0)
+        return EXIT_FAILURE;
+
     if (!(test.conn = virConnectOpen("test:///default")))
         return EXIT_FAILURE;

@@ -460,6 +494,7 @@ mymain(void)
     virNetworkUndefine(test.net);
     virNetworkFree(test.net);
     virConnectClose(test.conn);
+    virEventRemoveTimeout(timer);

     return ret;
 }
-- 
1.8.4.2

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