Add missing libxml2-tools dependency
[archive/platform/upstream/libvirt.git] / tests / fchosttest.c
1 /*
2  * Copyright (C) 2013 Red Hat, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library.  If not, see
16  * <http://www.gnu.org/licenses/>.
17  *
18  */
19
20 #include <config.h>
21
22 #include "virstring.h"
23 #include "virutil.h"
24 #include "testutils.h"
25
26 #define VIR_FROM_THIS VIR_FROM_NONE
27
28 static char *fchost_prefix;
29
30 #define TEST_FC_HOST_PREFIX fchost_prefix
31 #define TEST_FC_HOST_NUM 5
32
33 /* Test virIsCapableFCHost */
34 static int
35 test1(const void *data ATTRIBUTE_UNUSED)
36 {
37     if (virIsCapableFCHost(TEST_FC_HOST_PREFIX,
38                            TEST_FC_HOST_NUM))
39         return 0;
40
41     return -1;
42 }
43
44 /* Test virIsCapableVport */
45 static int
46 test2(const void *data ATTRIBUTE_UNUSED)
47 {
48     if (virIsCapableVport(TEST_FC_HOST_PREFIX,
49                           TEST_FC_HOST_NUM))
50         return 0;
51
52     return -1;
53 }
54
55 /* Test virReadFCHost */
56 static int
57 test3(const void *data ATTRIBUTE_UNUSED)
58 {
59     const char *expect_wwnn = "2001001b32a9da4e";
60     const char *expect_wwpn = "2101001b32a9da4e";
61     const char *expect_fabric_wwn = "2001000dec9877c1";
62     const char *expect_max_vports = "127";
63     const char *expect_vports = "0";
64     char *wwnn = NULL;
65     char *wwpn = NULL;
66     char *fabric_wwn = NULL;
67     char *max_vports = NULL;
68     char *vports = NULL;
69     int ret = -1;
70
71     if (virReadFCHost(TEST_FC_HOST_PREFIX,
72                       TEST_FC_HOST_NUM,
73                       "node_name",
74                       &wwnn) < 0)
75         return -1;
76
77     if (virReadFCHost(TEST_FC_HOST_PREFIX,
78                       TEST_FC_HOST_NUM,
79                       "port_name",
80                       &wwpn) < 0)
81         goto cleanup;
82
83     if (virReadFCHost(TEST_FC_HOST_PREFIX,
84                       TEST_FC_HOST_NUM,
85                       "fabric_name",
86                       &fabric_wwn) < 0)
87         goto cleanup;
88
89     if (virReadFCHost(TEST_FC_HOST_PREFIX,
90                       TEST_FC_HOST_NUM,
91                       "max_npiv_vports",
92                       &max_vports) < 0)
93         goto cleanup;
94
95
96     if (virReadFCHost(TEST_FC_HOST_PREFIX,
97                       TEST_FC_HOST_NUM,
98                       "npiv_vports_inuse",
99                       &vports) < 0)
100         goto cleanup;
101
102     if (STRNEQ(expect_wwnn, wwnn) ||
103         STRNEQ(expect_wwpn, wwpn) ||
104         STRNEQ(expect_fabric_wwn, fabric_wwn) ||
105         STRNEQ(expect_max_vports, max_vports) ||
106         STRNEQ(expect_vports, vports))
107         goto cleanup;
108
109     ret = 0;
110  cleanup:
111     VIR_FREE(wwnn);
112     VIR_FREE(wwpn);
113     VIR_FREE(fabric_wwn);
114     VIR_FREE(max_vports);
115     VIR_FREE(vports);
116     return ret;
117 }
118
119 /* Test virGetFCHostNameByWWN */
120 static int
121 test4(const void *data ATTRIBUTE_UNUSED)
122 {
123     const char *expect_hostname = "host5";
124     char *hostname = NULL;
125     int ret = -1;
126
127     if (!(hostname = virGetFCHostNameByWWN(TEST_FC_HOST_PREFIX,
128                                            "2001001b32a9da4e",
129                                            "2101001b32a9da4e")))
130         return -1;
131
132     if (STRNEQ(hostname, expect_hostname))
133         goto cleanup;
134
135     ret = 0;
136  cleanup:
137     VIR_FREE(hostname);
138     return ret;
139 }
140
141 /* Test virFindFCHostCapableVport (host4 is not Online) */
142 static int
143 test5(const void *data ATTRIBUTE_UNUSED)
144 {
145     const char *expect_hostname = "host5";
146     char *hostname = NULL;
147     int ret = -1;
148
149     if (!(hostname = virFindFCHostCapableVport(TEST_FC_HOST_PREFIX)))
150         return -1;
151
152     if (STRNEQ(hostname, expect_hostname))
153         goto cleanup;
154
155     ret = 0;
156  cleanup:
157     VIR_FREE(hostname);
158     return ret;
159 }
160
161 static int
162 mymain(void)
163 {
164     int ret = 0;
165
166     if (virAsprintf(&fchost_prefix, "%s/%s", abs_srcdir,
167                     "fchostdata/fc_host/") < 0) {
168         ret = -1;
169         goto cleanup;
170     }
171
172     if (virtTestRun("test1", test1, NULL) < 0)
173         ret = -1;
174     if (virtTestRun("test2", test2, NULL) < 0)
175         ret = -1;
176     if (virtTestRun("test3", test3, NULL) < 0)
177         ret = -1;
178     if (virtTestRun("test4", test4, NULL) < 0)
179         ret = -1;
180     if (virtTestRun("test5", test5, NULL) < 0)
181         ret = -1;
182
183  cleanup:
184     VIR_FREE(fchost_prefix);
185     return ret;
186 }
187
188 VIRT_TEST_MAIN(mymain)