2 * storagebackendsheepdogtest.c: storage backend for Sheepdog handling
4 * Copyright (C) 2014 Red Hat, Inc.
5 * Copyright (C) 2012 Sebastian Wiedenroth
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library. If not, see
19 * <http://www.gnu.org/licenses/>.
29 #include "testutils.h"
30 #define LIBVIRT_STORAGE_BACKEND_SHEEPDOG_PRIV_H_ALLOW
31 #include "storage/storage_backend_sheepdog_priv.h"
32 #include "virstring.h"
34 #define VIR_FROM_THIS VIR_FROM_NONE
39 uint64_t expected_capacity
;
40 uint64_t expected_allocation
;
43 struct testNodeInfoParserData
{
48 struct testVDIListParserData
{
56 test_node_info_parser(const void *opaque
)
58 const struct testNodeInfoParserData
*data
= opaque
;
59 collie_test test
= data
->data
;
60 VIR_AUTOFREE(char *) output
= NULL
;
61 VIR_AUTOPTR(virStoragePoolDef
) pool
= NULL
;
63 if (!(pool
= virStoragePoolDefParseFile(data
->poolxml
)))
66 if (VIR_STRDUP(output
, test
.output
) < 0)
69 if (virStorageBackendSheepdogParseNodeInfo(pool
, output
) !=
73 if (test
.expected_return
)
76 if (pool
->capacity
== test
.expected_capacity
&&
77 pool
->allocation
== test
.expected_allocation
)
84 test_vdi_list_parser(const void *opaque
)
86 const struct testVDIListParserData
*data
= opaque
;
87 collie_test test
= data
->data
;
88 VIR_AUTOFREE(char *) output
= NULL
;
89 VIR_AUTOPTR(virStoragePoolDef
) pool
= NULL
;
90 VIR_AUTOPTR(virStorageVolDef
) vol
= NULL
;
92 if (!(pool
= virStoragePoolDefParseFile(data
->poolxml
)))
95 if (!(vol
= virStorageVolDefParseFile(pool
, data
->volxml
, 0)))
98 if (VIR_STRDUP(output
, test
.output
) < 0)
101 if (virStorageBackendSheepdogParseVdiList(vol
, output
) !=
102 test
.expected_return
)
105 if (test
.expected_return
)
108 if (vol
->target
.capacity
== test
.expected_capacity
&&
109 vol
->target
.allocation
== test
.expected_allocation
)
120 VIR_AUTOFREE(char *) poolxml
= NULL
;
121 VIR_AUTOFREE(char *) volxml
= NULL
;
123 collie_test node_info_tests
[] = {
125 {"Total 15245667872 117571104 0% 20972341\n", 0, 15245667872, 117571104},
127 {"asdf\nasdf", -1, 0, 0},
128 {"Total ", -1, 0, 0},
129 {"Total 1", -1, 0, 0},
130 {"Total 1\n", -1, 0, 0},
131 {"Total 1 ", -1, 0, 0},
132 {"Total 1 2", -1, 0, 0},
133 {"Total 1 2 ", -1, 0, 0},
134 {"Total 1 2\n", 0, 1, 2},
135 {"Total 1 2 \n", 0, 1, 2},
136 {"Total a 2 \n", -1, 0, 0},
137 {"Total 1 b \n", -1, 0, 0},
138 {"Total a b \n", -1, 0, 0},
139 {"stuff\nTotal 1 2 \n", 0, 1, 2},
140 {"0 1 2 3\nTotal 1 2 \n", 0, 1, 2},
144 collie_test vdi_list_tests
[] = {
146 {"= test 3 10 20 0 1336557216 7c2b27\n", 0, 10, 20},
147 {"= test\\ with\\ spaces 3 10 20 0 1336557216 7c2b27\n", 0, 10, 20},
148 {"= backslashattheend\\\\ 3 10 20 0 1336557216 7c2b27\n", 0, 10, 20},
149 {"s test 1 10 20 0 1336556634 7c2b25\n= test 3 50 60 0 1336557216 7c2b27\n", 0, 50, 60},
151 {"= test", -1, 0, 0},
152 {"= test ", -1, 0, 0},
153 {"= test 1", -1, 0, 0},
154 {"= test 1 ", -1, 0, 0},
155 {"= test 1 2", -1, 0, 0},
156 {"= test 1 2 ", -1, 0, 0},
157 {"= test 1 2 3", -1, 0, 0},
161 collie_test
*test
= node_info_tests
;
163 if (virAsprintf(&poolxml
, "%s/storagepoolxml2xmlin/pool-sheepdog.xml",
167 if (virAsprintf(&volxml
, "%s/storagevolxml2xmlin/vol-sheepdog.xml",
171 #define DO_TEST_NODE(collie) \
173 struct testNodeInfoParserData data = { \
175 .poolxml = poolxml, \
177 if (virTestRun("node_info_parser", test_node_info_parser, \
182 while (test
->output
!= NULL
) {
188 #define DO_TEST_VDI(collie) \
190 struct testVDIListParserData data = { \
192 .poolxml = poolxml, \
195 if (virTestRun("vdi_list_parser", test_vdi_list_parser, \
200 test
= vdi_list_tests
;
202 while (test
->output
!= NULL
) {
208 return ret
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
211 VIR_TEST_MAIN(mymain
)