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

[libvirt] [PATCHv2 06/14] event [squash with next]: test that old-style can't clobber new-style



Test the previous patch.

* tests/objecteventtest.c (testDomainCreateXMLMixed): New test.

Signed-off-by: Eric Blake <eblake redhat com>
---
 tests/objecteventtest.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 67 insertions(+), 2 deletions(-)

diff --git a/tests/objecteventtest.c b/tests/objecteventtest.c
index 6f657d2..649fc25 100644
--- a/tests/objecteventtest.c
+++ b/tests/objecteventtest.c
@@ -167,7 +167,7 @@ cleanup:
 }

 static int
-testDomainCreateXML(const void *data)
+testDomainCreateXMLNew(const void *data)
 {
     const objecteventTest *test = data;
     lifecycleEventCounter counter;
@@ -208,6 +208,68 @@ cleanup:
 }

 static int
+testDomainCreateXMLMixed(const void *data)
+{
+    const objecteventTest *test = data;
+    lifecycleEventCounter counter;
+    virDomainPtr dom;
+    int ret = -1;
+    int id = -1;
+    bool registered = false;
+
+    lifecycleEventCounter_reset(&counter);
+
+    /* Fun with mixing old and new API.  Handler should be fired twice,
+     * once for each registration.  */
+    dom = virDomainCreateXML(test->conn, domainDef, 0);
+    if (dom == NULL)
+        goto cleanup;
+
+    id = virConnectDomainEventRegisterAny(test->conn, dom,
+                                          VIR_DOMAIN_EVENT_ID_LIFECYCLE,
+                           VIR_DOMAIN_EVENT_CALLBACK(&domainLifecycleCb),
+                                          &counter, NULL);
+    if (id < 0)
+        goto cleanup;
+    if (virDomainDestroy(dom) < 0)
+        goto cleanup;
+    if (virConnectDomainEventRegister(test->conn,
+                                      domainLifecycleCb,
+                                      &counter, NULL) != 0)
+        goto cleanup;
+    registered = true;
+
+    dom = virDomainCreateXML(test->conn, domainDef, 0);
+    if (dom == NULL || virEventRunDefaultImpl() < 0)
+        goto cleanup;
+
+    if (counter.startEvents != 2 || counter.unexpectedEvents > 0)
+        goto cleanup;
+
+    if (virConnectDomainEventDeregister(test->conn, domainLifecycleCb) != 0)
+        goto cleanup;
+    registered = false;
+    if (virConnectDomainEventDeregisterAny(test->conn, id) != 0)
+        goto cleanup;
+    id = -1;
+    ret = 0;
+
+cleanup:
+    if (id >= 0)
+        virConnectDomainEventDeregisterAny(test->conn, id);
+    if (registered)
+        virConnectDomainEventDeregister(test->conn, domainLifecycleCb);
+    if (dom != NULL) {
+        virDomainUndefine(dom);
+        virDomainDestroy(dom);
+        virDomainFree(dom);
+    }
+
+    return ret;
+}
+
+
+static int
 testDomainDefine(const void *data)
 {
     const objecteventTest *test = data;
@@ -471,7 +533,10 @@ mymain(void)
                     testDomainCreateXMLOld, &test) < 0)
         ret = EXIT_FAILURE;
     if (virtTestRun("Domain createXML start event (new API)",
-                    testDomainCreateXML, &test) < 0)
+                    testDomainCreateXMLNew, &test) < 0)
+        ret = EXIT_FAILURE;
+    if (virtTestRun("Domain createXML start event (both API)",
+                    testDomainCreateXMLMixed, &test) < 0)
         ret = EXIT_FAILURE;
     if (virtTestRun("Domain (un)define events", testDomainDefine, &test) < 0)
         ret = EXIT_FAILURE;
-- 
1.8.4.2


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