docs: Reword virDomainGetEmulatorPinInfo description
[libvirt.git] / tests / objecteventtest.c
blob7110f541393e491404b0ef330c8e0c3eee6bb054
1 /*
2 * Copyright (C) 2014 Red Hat, Inc.
3 * Copyright (C) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; If not, see
17 * <http://www.gnu.org/licenses/>.
20 #include <config.h>
22 #include <unistd.h>
24 #include "testutils.h"
26 #define VIR_FROM_THIS VIR_FROM_NONE
29 static const char domainDef[] =
30 "<domain type='test'>"
31 " <name>test-domain</name>"
32 " <uuid>77a6fc12-07b5-9415-8abb-a803613f2a40</uuid>"
33 " <memory>8388608</memory>"
34 " <currentMemory>2097152</currentMemory>"
35 " <vcpu>2</vcpu>"
36 " <os>"
37 " <type>hvm</type>"
38 " </os>"
39 "</domain>";
41 static const char networkDef[] =
42 "<network>\n"
43 " <name>test</name>\n"
44 " <bridge name=\"virbr0\"/>\n"
45 " <forward/>\n"
46 " <ip address=\"192.168.122.1\" netmask=\"255.255.255.0\">\n"
47 " <dhcp>\n"
48 " <range start=\"192.168.122.2\" end=\"192.168.122.254\"/>\n"
49 " </dhcp>\n"
50 " </ip>\n"
51 "</network>\n";
53 static const char storagePoolDef[] =
54 "<pool type='dir'>\n"
55 " <name>P</name>\n"
56 " <target>\n"
57 " <path>/target-path</path>\n"
58 " </target>\n"
59 "</pool>\n";
61 static const char nodeDeviceDef[] =
62 "<device>\n"
63 " <parent>scsi_host1</parent>\n"
64 " <capability type='scsi_host'>\n"
65 " <capability type='fc_host'>\n"
66 " <wwpn>1000000023452345</wwpn>\n"
67 " <wwnn>2000000023452345</wwnn>\n"
68 " </capability>\n"
69 " </capability>\n"
70 "</device>\n";
72 typedef struct {
73 int startEvents;
74 int stopEvents;
75 int defineEvents;
76 int undefineEvents;
77 int unexpectedEvents;
78 int createdEvents;
79 int deletedEvents;
80 } lifecycleEventCounter;
83 typedef struct {
84 virConnectPtr conn;
85 virNetworkPtr net;
86 virStoragePoolPtr pool;
87 virNodeDevicePtr dev;
88 } objecteventTest;
91 static int
92 domainLifecycleCb(virConnectPtr conn G_GNUC_UNUSED,
93 virDomainPtr dom G_GNUC_UNUSED,
94 int event,
95 int detail G_GNUC_UNUSED,
96 void *opaque)
98 lifecycleEventCounter *counter = opaque;
100 switch (event) {
101 case VIR_DOMAIN_EVENT_STARTED:
102 counter->startEvents++;
103 break;
104 case VIR_DOMAIN_EVENT_STOPPED:
105 counter->stopEvents++;
106 break;
107 case VIR_DOMAIN_EVENT_DEFINED:
108 counter->defineEvents++;
109 break;
110 case VIR_DOMAIN_EVENT_UNDEFINED:
111 counter->undefineEvents++;
112 break;
113 default:
114 /* Ignore other events */
115 break;
117 return 0;
120 static void
121 networkLifecycleCb(virConnectPtr conn G_GNUC_UNUSED,
122 virNetworkPtr net G_GNUC_UNUSED,
123 int event,
124 int detail G_GNUC_UNUSED,
125 void* opaque)
127 lifecycleEventCounter *counter = opaque;
129 if (event == VIR_NETWORK_EVENT_STARTED)
130 counter->startEvents++;
131 else if (event == VIR_NETWORK_EVENT_STOPPED)
132 counter->stopEvents++;
133 else if (event == VIR_NETWORK_EVENT_DEFINED)
134 counter->defineEvents++;
135 else if (event == VIR_NETWORK_EVENT_UNDEFINED)
136 counter->undefineEvents++;
139 static void
140 storagePoolLifecycleCb(virConnectPtr conn G_GNUC_UNUSED,
141 virStoragePoolPtr pool G_GNUC_UNUSED,
142 int event,
143 int detail G_GNUC_UNUSED,
144 void* opaque)
146 lifecycleEventCounter *counter = opaque;
148 if (event == VIR_STORAGE_POOL_EVENT_STARTED)
149 counter->startEvents++;
150 else if (event == VIR_STORAGE_POOL_EVENT_STOPPED)
151 counter->stopEvents++;
152 else if (event == VIR_STORAGE_POOL_EVENT_DEFINED)
153 counter->defineEvents++;
154 else if (event == VIR_STORAGE_POOL_EVENT_UNDEFINED)
155 counter->undefineEvents++;
156 else if (event == VIR_STORAGE_POOL_EVENT_CREATED)
157 counter->createdEvents++;
158 else if (event == VIR_STORAGE_POOL_EVENT_DELETED)
159 counter->deletedEvents++;
162 static void
163 storagePoolRefreshCb(virConnectPtr conn G_GNUC_UNUSED,
164 virStoragePoolPtr pool G_GNUC_UNUSED,
165 void* opaque)
167 int *counter = opaque;
169 (*counter)++;
172 static void
173 nodeDeviceLifecycleCb(virConnectPtr conn G_GNUC_UNUSED,
174 virNodeDevicePtr dev G_GNUC_UNUSED,
175 int event,
176 int detail G_GNUC_UNUSED,
177 void* opaque)
179 lifecycleEventCounter *counter = opaque;
181 if (event == VIR_NODE_DEVICE_EVENT_CREATED)
182 counter->createdEvents++;
183 else if (event == VIR_NODE_DEVICE_EVENT_DELETED)
184 counter->deletedEvents++;
187 static int
188 testDomainCreateXMLOld(const void *data)
190 const objecteventTest *test = data;
191 lifecycleEventCounter counter = { 0 };
192 virDomainPtr dom = NULL;
193 int ret = -1;
194 bool registered = false;
196 if (virConnectDomainEventRegister(test->conn,
197 domainLifecycleCb,
198 &counter, NULL) != 0)
199 goto cleanup;
200 registered = true;
201 dom = virDomainCreateXML(test->conn, domainDef, 0);
203 if (dom == NULL || virEventRunDefaultImpl() < 0)
204 goto cleanup;
206 if (counter.startEvents != 1 || counter.unexpectedEvents > 0)
207 goto cleanup;
209 if (virConnectDomainEventDeregister(test->conn, domainLifecycleCb) != 0)
210 goto cleanup;
211 registered = false;
212 ret = 0;
214 cleanup:
215 if (registered)
216 virConnectDomainEventDeregister(test->conn, domainLifecycleCb);
217 if (dom) {
218 virDomainDestroy(dom);
219 virDomainFree(dom);
222 return ret;
225 static int
226 testDomainCreateXMLNew(const void *data)
228 const objecteventTest *test = data;
229 lifecycleEventCounter counter = { 0 };
230 int eventId = VIR_DOMAIN_EVENT_ID_LIFECYCLE;
231 virDomainPtr dom = NULL;
232 int id;
233 int ret = -1;
235 id = virConnectDomainEventRegisterAny(test->conn, NULL, eventId,
236 VIR_DOMAIN_EVENT_CALLBACK(&domainLifecycleCb),
237 &counter, NULL);
238 if (id < 0)
239 goto cleanup;
240 dom = virDomainCreateXML(test->conn, domainDef, 0);
242 if (dom == NULL || virEventRunDefaultImpl() < 0)
243 goto cleanup;
245 if (counter.startEvents != 1 || counter.unexpectedEvents > 0)
246 goto cleanup;
248 if (virConnectDomainEventDeregisterAny(test->conn, id) != 0)
249 goto cleanup;
250 id = -1;
251 ret = 0;
253 cleanup:
254 if (id >= 0)
255 virConnectDomainEventDeregisterAny(test->conn, id);
256 if (dom) {
257 virDomainDestroy(dom);
258 virDomainFree(dom);
261 return ret;
264 static int
265 testDomainCreateXMLMixed(const void *data)
267 const objecteventTest *test = data;
268 lifecycleEventCounter counter = { 0 };
269 virDomainPtr dom;
270 int ret = -1;
271 int id1 = -1;
272 int id2 = -1;
273 bool registered = false;
275 /* Fun with mixing old and new API, also with global and
276 * per-domain. Handler should be fired three times, once for each
277 * registration. */
278 dom = virDomainDefineXML(test->conn, domainDef);
279 if (dom == NULL)
280 goto cleanup;
282 id1 = virConnectDomainEventRegisterAny(test->conn, dom,
283 VIR_DOMAIN_EVENT_ID_LIFECYCLE,
284 VIR_DOMAIN_EVENT_CALLBACK(&domainLifecycleCb),
285 &counter, NULL);
286 if (id1 < 0)
287 goto cleanup;
288 if (virConnectDomainEventRegister(test->conn,
289 domainLifecycleCb,
290 &counter, NULL) != 0)
291 goto cleanup;
292 registered = true;
293 id2 = virConnectDomainEventRegisterAny(test->conn, NULL,
294 VIR_DOMAIN_EVENT_ID_LIFECYCLE,
295 VIR_DOMAIN_EVENT_CALLBACK(&domainLifecycleCb),
296 &counter, NULL);
297 if (id2 < 0)
298 goto cleanup;
300 virDomainUndefine(dom);
301 virDomainDestroy(dom);
302 virDomainFree(dom);
304 dom = virDomainCreateXML(test->conn, domainDef, 0);
305 if (dom == NULL || virEventRunDefaultImpl() < 0)
306 goto cleanup;
308 if (counter.startEvents != 3 || counter.unexpectedEvents > 0)
309 goto cleanup;
311 if (virConnectDomainEventDeregister(test->conn, domainLifecycleCb) != 0)
312 goto cleanup;
313 registered = false;
314 if (virConnectDomainEventDeregisterAny(test->conn, id1) != 0)
315 goto cleanup;
316 id1 = -1;
317 if (virConnectDomainEventDeregisterAny(test->conn, id2) != 0)
318 goto cleanup;
319 id2 = -1;
320 ret = 0;
322 cleanup:
323 if (id1 >= 0)
324 virConnectDomainEventDeregisterAny(test->conn, id1);
325 if (id2 >= 0)
326 virConnectDomainEventDeregisterAny(test->conn, id2);
327 if (registered)
328 virConnectDomainEventDeregister(test->conn, domainLifecycleCb);
329 if (dom != NULL) {
330 virDomainUndefine(dom);
331 virDomainDestroy(dom);
332 virDomainFree(dom);
335 return ret;
339 static int
340 testDomainDefine(const void *data)
342 const objecteventTest *test = data;
343 lifecycleEventCounter counter = { 0 };
344 int eventId = VIR_DOMAIN_EVENT_ID_LIFECYCLE;
345 virDomainPtr dom = NULL;
346 int id;
347 int ret = -1;
349 id = virConnectDomainEventRegisterAny(test->conn, NULL, eventId,
350 VIR_DOMAIN_EVENT_CALLBACK(&domainLifecycleCb),
351 &counter, NULL);
353 /* Make sure the define event is triggered */
354 dom = virDomainDefineXML(test->conn, domainDef);
356 if (dom == NULL || virEventRunDefaultImpl() < 0) {
357 goto cleanup;
360 if (counter.defineEvents != 1 || counter.unexpectedEvents > 0) {
361 goto cleanup;
364 /* Make sure the undefine event is triggered */
365 virDomainUndefine(dom);
367 if (virEventRunDefaultImpl() < 0) {
368 goto cleanup;
371 if (counter.undefineEvents != 1 || counter.unexpectedEvents > 0) {
372 goto cleanup;
375 ret = 0;
376 cleanup:
377 virConnectDomainEventDeregisterAny(test->conn, id);
378 if (dom != NULL)
379 virDomainFree(dom);
381 return ret;
384 static int
385 testDomainStartStopEvent(const void *data)
387 const objecteventTest *test = data;
388 lifecycleEventCounter counter = { 0 };
389 int eventId = VIR_DOMAIN_EVENT_ID_LIFECYCLE;
390 int id;
391 int ret = -1;
392 virDomainPtr dom;
393 virConnectPtr conn2 = NULL;
394 virDomainPtr dom2 = NULL;
396 dom = virDomainLookupByName(test->conn, "test");
397 if (dom == NULL)
398 return -1;
400 id = virConnectDomainEventRegisterAny(test->conn, dom, eventId,
401 VIR_DOMAIN_EVENT_CALLBACK(&domainLifecycleCb),
402 &counter, NULL);
404 /* Test domain is started */
405 virDomainDestroy(dom);
406 if (virDomainCreate(dom) < 0)
407 goto cleanup;
409 if (virEventRunDefaultImpl() < 0)
410 goto cleanup;
412 if (counter.startEvents != 1 || counter.stopEvents != 1 ||
413 counter.unexpectedEvents > 0)
414 goto cleanup;
416 /* Repeat the test, but this time, trigger the events via an
417 * alternate connection. */
418 if (!(conn2 = virConnectOpen("test:///default")))
419 goto cleanup;
420 if (!(dom2 = virDomainLookupByName(conn2, "test")))
421 goto cleanup;
423 if (virDomainDestroy(dom2) < 0)
424 goto cleanup;
425 if (virDomainCreate(dom2) < 0)
426 goto cleanup;
428 if (virEventRunDefaultImpl() < 0)
429 goto cleanup;
431 if (counter.startEvents != 2 || counter.stopEvents != 2 ||
432 counter.unexpectedEvents > 0)
433 goto cleanup;
435 ret = 0;
436 cleanup:
437 virConnectDomainEventDeregisterAny(test->conn, id);
438 virDomainFree(dom);
439 if (dom2)
440 virDomainFree(dom2);
441 if (conn2)
442 virConnectClose(conn2);
444 return ret;
447 static int
448 testNetworkCreateXML(const void *data)
450 const objecteventTest *test = data;
451 lifecycleEventCounter counter = { 0 };
452 virNetworkPtr net;
453 int id;
454 int ret = -1;
456 id = virConnectNetworkEventRegisterAny(test->conn, NULL,
457 VIR_NETWORK_EVENT_ID_LIFECYCLE,
458 VIR_NETWORK_EVENT_CALLBACK(&networkLifecycleCb),
459 &counter, NULL);
460 net = virNetworkCreateXML(test->conn, networkDef);
462 if (!net || virEventRunDefaultImpl() < 0) {
463 goto cleanup;
466 if (counter.startEvents != 1 || counter.unexpectedEvents > 0) {
467 goto cleanup;
470 ret = 0;
471 cleanup:
472 virConnectNetworkEventDeregisterAny(test->conn, id);
473 if (net) {
474 virNetworkDestroy(net);
475 virNetworkFree(net);
477 return ret;
480 static int
481 testNetworkDefine(const void *data)
483 const objecteventTest *test = data;
484 lifecycleEventCounter counter = { 0 };
485 virNetworkPtr net;
486 int id;
487 int ret = -1;
489 id = virConnectNetworkEventRegisterAny(test->conn, NULL,
490 VIR_NETWORK_EVENT_ID_LIFECYCLE,
491 VIR_NETWORK_EVENT_CALLBACK(&networkLifecycleCb),
492 &counter, NULL);
494 /* Make sure the define event is triggered */
495 net = virNetworkDefineXML(test->conn, networkDef);
497 if (!net || virEventRunDefaultImpl() < 0) {
498 goto cleanup;
501 if (counter.defineEvents != 1 || counter.unexpectedEvents > 0) {
502 goto cleanup;
505 /* Make sure the undefine event is triggered */
506 virNetworkUndefine(net);
508 if (virEventRunDefaultImpl() < 0) {
509 goto cleanup;
512 if (counter.undefineEvents != 1 || counter.unexpectedEvents > 0) {
513 goto cleanup;
517 ret = 0;
518 cleanup:
519 virConnectNetworkEventDeregisterAny(test->conn, id);
520 if (net)
521 virNetworkFree(net);
523 return ret;
526 static int
527 testNetworkStartStopEvent(const void *data)
529 const objecteventTest *test = data;
530 lifecycleEventCounter counter = { 0 };
531 int id;
532 int ret = -1;
534 if (!test->net)
535 return -1;
537 id = virConnectNetworkEventRegisterAny(test->conn, test->net,
538 VIR_NETWORK_EVENT_ID_LIFECYCLE,
539 VIR_NETWORK_EVENT_CALLBACK(&networkLifecycleCb),
540 &counter, NULL);
541 virNetworkCreate(test->net);
542 virNetworkDestroy(test->net);
544 if (virEventRunDefaultImpl() < 0) {
545 goto cleanup;
548 if (counter.startEvents != 1 || counter.stopEvents != 1 ||
549 counter.unexpectedEvents > 0) {
550 goto cleanup;
553 ret = 0;
554 cleanup:
555 virConnectNetworkEventDeregisterAny(test->conn, id);
557 return ret;
560 static int
561 testStoragePoolCreateXML(const void *data)
563 const objecteventTest *test = data;
564 lifecycleEventCounter counter = { 0 };
565 virStoragePoolPtr pool;
566 int id;
567 int ret = -1;
569 id = virConnectStoragePoolEventRegisterAny(test->conn, NULL,
570 VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
571 VIR_STORAGE_POOL_EVENT_CALLBACK(&storagePoolLifecycleCb),
572 &counter, NULL);
573 pool = virStoragePoolCreateXML(test->conn, storagePoolDef, 0);
575 if (!pool || virEventRunDefaultImpl() < 0) {
576 goto cleanup;
579 if (counter.startEvents != 1 || counter.unexpectedEvents > 0) {
580 goto cleanup;
583 ret = 0;
584 cleanup:
585 virConnectStoragePoolEventDeregisterAny(test->conn, id);
586 if (pool) {
587 virStoragePoolDestroy(pool);
588 virStoragePoolFree(pool);
590 return ret;
593 static int
594 testStoragePoolDefine(const void *data)
596 const objecteventTest *test = data;
597 lifecycleEventCounter counter = { 0 };
598 virStoragePoolPtr pool;
599 int id;
600 int ret = -1;
602 id = virConnectStoragePoolEventRegisterAny(test->conn, NULL,
603 VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
604 VIR_STORAGE_POOL_EVENT_CALLBACK(&storagePoolLifecycleCb),
605 &counter, NULL);
607 /* Make sure the define event is triggered */
608 pool = virStoragePoolDefineXML(test->conn, storagePoolDef, 0);
610 if (!pool || virEventRunDefaultImpl() < 0) {
611 goto cleanup;
614 if (counter.defineEvents != 1 || counter.unexpectedEvents > 0) {
615 goto cleanup;
618 /* Make sure the undefine event is triggered */
619 virStoragePoolUndefine(pool);
621 if (virEventRunDefaultImpl() < 0) {
622 goto cleanup;
625 if (counter.undefineEvents != 1 || counter.unexpectedEvents > 0) {
626 goto cleanup;
629 ret = 0;
630 cleanup:
631 virConnectStoragePoolEventDeregisterAny(test->conn, id);
632 if (pool)
633 virStoragePoolFree(pool);
635 return ret;
638 static int
639 testStoragePoolStartStopEvent(const void *data)
641 const objecteventTest *test = data;
642 lifecycleEventCounter counter = { 0 };
643 int refreshCounter = 0;
644 int id1, id2;
645 int ret = -1;
647 if (!test->pool)
648 return -1;
650 id1 = virConnectStoragePoolEventRegisterAny(test->conn, test->pool,
651 VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
652 VIR_STORAGE_POOL_EVENT_CALLBACK(&storagePoolLifecycleCb),
653 &counter, NULL);
654 id2 = virConnectStoragePoolEventRegisterAny(test->conn, test->pool,
655 VIR_STORAGE_POOL_EVENT_ID_REFRESH,
656 VIR_STORAGE_POOL_EVENT_CALLBACK(&storagePoolRefreshCb),
657 &refreshCounter, NULL);
658 virStoragePoolCreate(test->pool, 0);
659 virStoragePoolRefresh(test->pool, 0);
660 virStoragePoolDestroy(test->pool);
662 if (virEventRunDefaultImpl() < 0) {
663 goto cleanup;
666 if (counter.startEvents != 1 || counter.stopEvents != 1 ||
667 refreshCounter != 1 || counter.unexpectedEvents > 0) {
668 goto cleanup;
671 ret = 0;
672 cleanup:
673 virConnectStoragePoolEventDeregisterAny(test->conn, id1);
674 virConnectStoragePoolEventDeregisterAny(test->conn, id2);
675 return ret;
678 static int
679 testStoragePoolBuild(const void *data)
681 const objecteventTest *test = data;
682 lifecycleEventCounter counter = { 0 };
683 int id;
684 int ret = -1;
686 id = virConnectStoragePoolEventRegisterAny(test->conn, NULL,
687 VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
688 VIR_STORAGE_POOL_EVENT_CALLBACK(&storagePoolLifecycleCb),
689 &counter, NULL);
691 virStoragePoolBuild(test->pool, 0);
693 if (virEventRunDefaultImpl() < 0) {
694 goto cleanup;
697 if (counter.createdEvents != 1) {
698 goto cleanup;
701 ret = 0;
702 cleanup:
703 virConnectStoragePoolEventDeregisterAny(test->conn, id);
704 return ret;
707 static int
708 testStoragePoolDelete(const void *data)
710 const objecteventTest *test = data;
711 lifecycleEventCounter counter = { 0 };
712 int id;
713 int ret = -1;
715 id = virConnectStoragePoolEventRegisterAny(test->conn, NULL,
716 VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
717 VIR_STORAGE_POOL_EVENT_CALLBACK(&storagePoolLifecycleCb),
718 &counter, NULL);
720 virStoragePoolDelete(test->pool, 0);
722 if (virEventRunDefaultImpl() < 0) {
723 goto cleanup;
726 if (counter.deletedEvents != 1) {
727 goto cleanup;
730 ret = 0;
731 cleanup:
732 virConnectStoragePoolEventDeregisterAny(test->conn, id);
733 return ret;
735 static int
736 testNodeDeviceCreateXML(const void *data)
738 const objecteventTest *test = data;
739 lifecycleEventCounter counter = { 0 };
740 virNodeDevicePtr dev;
741 int id;
742 int ret = -1;
744 id = virConnectNodeDeviceEventRegisterAny(test->conn, NULL,
745 VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE,
746 VIR_NODE_DEVICE_EVENT_CALLBACK(&nodeDeviceLifecycleCb),
747 &counter, NULL);
748 dev = virNodeDeviceCreateXML(test->conn, nodeDeviceDef, 0);
749 virNodeDeviceDestroy(dev);
751 if (!dev || virEventRunDefaultImpl() < 0) {
752 goto cleanup;
755 if (counter.createdEvents != 1 || counter.deletedEvents != 1 ||
756 counter.unexpectedEvents > 0) {
757 goto cleanup;
760 ret = 0;
761 cleanup:
762 virConnectNodeDeviceEventDeregisterAny(test->conn, id);
763 if (dev)
764 virNodeDeviceFree(dev);
765 return ret;
768 static void
769 timeout(int id G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED)
771 fputs("test taking too long; giving up", stderr);
772 _exit(EXIT_FAILURE);
775 static int
776 mymain(void)
778 objecteventTest test = { 0 };
779 int ret = EXIT_SUCCESS;
780 int timer;
782 virEventRegisterDefaultImpl();
784 /* Set up a timer to abort this test if it takes 10 seconds. */
785 if ((timer = virEventAddTimeout(10 * 1000, timeout, NULL, NULL)) < 0)
786 return EXIT_FAILURE;
788 if (!(test.conn = virConnectOpen("test:///default")))
789 return EXIT_FAILURE;
791 virTestQuiesceLibvirtErrors(false);
793 /* Domain event tests */
794 if (virTestRun("Domain createXML start event (old API)",
795 testDomainCreateXMLOld, &test) < 0)
796 ret = EXIT_FAILURE;
797 if (virTestRun("Domain createXML start event (new API)",
798 testDomainCreateXMLNew, &test) < 0)
799 ret = EXIT_FAILURE;
800 if (virTestRun("Domain createXML start event (both API)",
801 testDomainCreateXMLMixed, &test) < 0)
802 ret = EXIT_FAILURE;
803 if (virTestRun("Domain (un)define events", testDomainDefine, &test) < 0)
804 ret = EXIT_FAILURE;
805 if (virTestRun("Domain start stop events", testDomainStartStopEvent, &test) < 0)
806 ret = EXIT_FAILURE;
808 /* Network event tests */
809 /* Tests requiring the test network not to be set up */
810 if (virTestRun("Network createXML start event ", testNetworkCreateXML, &test) < 0)
811 ret = EXIT_FAILURE;
812 if (virTestRun("Network (un)define events", testNetworkDefine, &test) < 0)
813 ret = EXIT_FAILURE;
815 /* Define a test network */
816 if (!(test.net = virNetworkDefineXML(test.conn, networkDef)))
817 ret = EXIT_FAILURE;
818 if (virTestRun("Network start stop events ", testNetworkStartStopEvent, &test) < 0)
819 ret = EXIT_FAILURE;
821 /* Cleanup */
822 if (test.net) {
823 virNetworkUndefine(test.net);
824 virNetworkFree(test.net);
827 /* Storage pool event tests */
828 if (virTestRun("Storage pool createXML start event ",
829 testStoragePoolCreateXML, &test) < 0)
830 ret = EXIT_FAILURE;
831 if (virTestRun("Storage pool (un)define events",
832 testStoragePoolDefine, &test) < 0)
833 ret = EXIT_FAILURE;
835 /* Define a test storage pool */
836 if (!(test.pool = virStoragePoolDefineXML(test.conn, storagePoolDef, 0)))
837 ret = EXIT_FAILURE;
838 if (virTestRun("Storage pool start stop events ",
839 testStoragePoolStartStopEvent, &test) < 0)
840 ret = EXIT_FAILURE;
841 /* Storage pool build and delete events */
842 if (virTestRun("Storage pool build event ",
843 testStoragePoolBuild, &test) < 0)
844 ret = EXIT_FAILURE;
845 if (virTestRun("Storage pool delete event ",
846 testStoragePoolDelete, &test) < 0)
847 ret = EXIT_FAILURE;
849 /* Node device event tests */
850 if (virTestRun("Node device createXML add event ",
851 testNodeDeviceCreateXML, &test) < 0)
852 ret = EXIT_FAILURE;
854 /* Cleanup */
855 if (test.pool) {
856 virStoragePoolUndefine(test.pool);
857 virStoragePoolFree(test.pool);
860 virConnectClose(test.conn);
861 virEventRemoveTimeout(timer);
863 return ret;
866 VIR_TEST_MAIN(mymain)