Debian Codegraph @

src/virt_test.c

raw
1 /**
2 * collectd - src/virt_test.c
3 * Copyright (C) 2016 Francesco Romani <fromani at redhat.com>
4 * Based on
5 * collectd - src/ceph_test.c
6 * Copyright (C) 2015 Florian octo Forster
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; only version 2 of the License is applicable.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 * Authors:
22 * Florian octo Forster <octo at collectd.org>
23 **/
24
25 #include "testing.h"
26 #include "virt.c" /* sic */
27
28 static virDomainPtr *domains;
29 static int nr_domains;
30
31 static int setup(void) {
32 if (virInitialize() != 0) {
33 printf("ERROR: virInitialize() != 0\n");
34 return -1;
35 }
36
37 conn = virConnectOpen("test:///default");
38 if (conn == NULL) {
39 printf("ERROR: virConnectOpen == NULL\n");
40 return -1;
41 }
42
43 return 0;
44 }
45
46 static int teardown(void) {
47 if (domains) {
48 for (int i = 0; i < nr_domains; ++i)
49 virDomainFree(domains[i]);
50 sfree(domains);
51 }
52 nr_domains = 0;
53 if (conn != NULL)
54 virConnectClose(conn);
55
56 return 0;
57 }
58
59 #ifdef HAVE_LIST_ALL_DOMAINS
60 DEF_TEST(get_domain_state_notify) {
61 if (setup() == 0) {
62 nr_domains = virConnectListAllDomains(conn, &domains,
63 VIR_CONNECT_LIST_DOMAINS_PERSISTENT);
64 if (nr_domains <= 0) {
65 printf("ERROR: virConnectListAllDomains: nr_domains <= 0\n");
66 return -1;
67 }
68
69 int ret = get_domain_state_notify(domains[0]);
70 EXPECT_EQ_INT(0, ret);
71 }
72 teardown();
73
74 return 0;
75 }
76 #endif
77
78 DEF_TEST(persistent_domains_state_notification) {
79 if (setup() == 0) {
80 int ret = persistent_domains_state_notification();
81 EXPECT_EQ_INT(0, ret);
82 }
83 teardown();
84
85 return 0;
86 }
87
88 int main(void) {
89 #ifdef HAVE_LIST_ALL_DOMAINS
90 RUN_TEST(get_domain_state_notify);
91 #endif
92 RUN_TEST(persistent_domains_state_notification);
93
94 END_TEST;
95 }