Ensure our testsuite has some coverage of old-style domain
event registration.
* tests/objecteventtest.c (testDomainCreateXMLOld): New test.
(mymain): Run it.
(testDomainCreateXML): Check return values.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
I verified that this test fails until you also apply patch
2/2 "event: make deregister return value match docs". Should
I squash them together or keep it as separate commits?
tests/objecteventtest.c | 67 ++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 58 insertions(+), 9 deletions(-)
diff --git a/tests/objecteventtest.c b/tests/objecteventtest.c
index ae29792..f7b60cd 100644
--- a/tests/objecteventtest.c
+++ b/tests/objecteventtest.c
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2014 Red Hat, Inc.
* Copyright (C) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
*
* This library is free software; you can redistribute it and/or
@@ -126,6 +127,46 @@ networkLifecycleCb(virConnectPtr conn ATTRIBUTE_UNUSED,
static int
+testDomainCreateXMLOld(const void *data)
+{
+ const objecteventTest *test = data;
+ lifecycleEventCounter counter;
+ virDomainPtr dom;
+ int ret = -1;
+ bool registered = false;
+
+ lifecycleEventCounter_reset(&counter);
+
+ 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 != 1 || counter.unexpectedEvents > 0)
+ goto cleanup;
+
+ if (virConnectDomainEventDeregister(test->conn, domainLifecycleCb) != 0)
+ goto cleanup;
+ registered = false;
+ ret = 0;
+
+cleanup:
+ if (registered)
+ virConnectDomainEventDeregister(test->conn, domainLifecycleCb);
+ if (dom != NULL) {
+ virDomainDestroy(dom);
+ virDomainFree(dom);
+ }
+
+ return ret;
+}
+
+static int
testDomainCreateXML(const void *data)
{
const objecteventTest *test = data;
@@ -133,27 +174,31 @@ testDomainCreateXML(const void *data)
int eventId = VIR_DOMAIN_EVENT_ID_LIFECYCLE;
virDomainPtr dom;
int id;
- int ret = 0;
+ int ret = -1;
lifecycleEventCounter_reset(&counter);
id = virConnectDomainEventRegisterAny(test->conn, NULL, eventId,
VIR_DOMAIN_EVENT_CALLBACK(&domainLifecycleCb),
&counter, NULL);
+ if (id < 0)
+ goto cleanup;
dom = virDomainCreateXML(test->conn, domainDef, 0);
- if (dom == NULL || virEventRunDefaultImpl() < 0) {
- ret = -1;
+ if (dom == NULL || virEventRunDefaultImpl() < 0)
goto cleanup;
- }
- if (counter.startEvents != 1 || counter.unexpectedEvents > 0) {
- ret = -1;
+ if (counter.startEvents != 1 || counter.unexpectedEvents > 0)
goto cleanup;
- }
+
+ if (virConnectDomainEventDeregisterAny(test->conn, id) != 0)
+ goto cleanup;
+ id = -1;
+ ret = 0;
cleanup:
- virConnectDomainEventDeregisterAny(test->conn, id);
+ if (id >= 0)
+ virConnectDomainEventDeregisterAny(test->conn, id);
if (dom != NULL) {
virDomainDestroy(dom);
virDomainFree(dom);
@@ -388,7 +433,11 @@ mymain(void)
virtTestQuiesceLibvirtErrors(false);
/* Domain event tests */
- if (virtTestRun("Domain createXML start event ", testDomainCreateXML,
&test) < 0)
+ if (virtTestRun("Domain createXML start event (old API)",
+ testDomainCreateXMLOld, &test) < 0)
+ ret = EXIT_FAILURE;
+ if (virtTestRun("Domain createXML start event (new API)",
+ testDomainCreateXML, &test) < 0)
ret = EXIT_FAILURE;
if (virtTestRun("Domain (un)define events", testDomainDefine, &test)
< 0)
ret = EXIT_FAILURE;
--
1.8.4.2