backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / storagebackendsheepdogtest.c
blob1806f9725f725cab04f62d04ef33f46190f84f73
1 /*
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/>.
22 #include <config.h>
24 #include <unistd.h>
26 #include <fcntl.h>
28 #include "internal.h"
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
36 typedef struct {
37 const char *output;
38 int expected_return;
39 uint64_t expected_capacity;
40 uint64_t expected_allocation;
41 } collie_test;
43 struct testNodeInfoParserData {
44 collie_test data;
45 const char *poolxml;
48 struct testVDIListParserData {
49 collie_test data;
50 const char *poolxml;
51 const char *volxml;
55 static int
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)))
64 return -1;
66 if (VIR_STRDUP(output, test.output) < 0)
67 return -1;
69 if (virStorageBackendSheepdogParseNodeInfo(pool, output) !=
70 test.expected_return)
71 return -1;
73 if (test.expected_return)
74 return 0;
76 if (pool->capacity == test.expected_capacity &&
77 pool->allocation == test.expected_allocation)
78 return 0;
80 return -1;
83 static int
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)))
93 return -1;
95 if (!(vol = virStorageVolDefParseFile(pool, data->volxml, 0)))
96 return -1;
98 if (VIR_STRDUP(output, test.output) < 0)
99 return -1;
101 if (virStorageBackendSheepdogParseVdiList(vol, output) !=
102 test.expected_return)
103 return -1;
105 if (test.expected_return)
106 return 0;
108 if (vol->target.capacity == test.expected_capacity &&
109 vol->target.allocation == test.expected_allocation)
110 return 0;
112 return -1;
116 static int
117 mymain(void)
119 int ret = 0;
120 VIR_AUTOFREE(char *) poolxml = NULL;
121 VIR_AUTOFREE(char *) volxml = NULL;
123 collie_test node_info_tests[] = {
124 {"", -1, 0, 0},
125 {"Total 15245667872 117571104 0% 20972341\n", 0, 15245667872, 117571104},
126 {"To", -1, 0, 0},
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},
141 {NULL, 0, 0, 0}
144 collie_test vdi_list_tests[] = {
145 {"", -1, 0, 0},
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},
150 {"=", -1, 0, 0},
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},
158 {NULL, 0, 0, 0}
161 collie_test *test = node_info_tests;
163 if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/pool-sheepdog.xml",
164 abs_srcdir) < 0)
165 goto cleanup;
167 if (virAsprintf(&volxml, "%s/storagevolxml2xmlin/vol-sheepdog.xml",
168 abs_srcdir) < 0)
169 goto cleanup;
171 #define DO_TEST_NODE(collie) \
172 do { \
173 struct testNodeInfoParserData data = { \
174 .data = collie, \
175 .poolxml = poolxml, \
176 }; \
177 if (virTestRun("node_info_parser", test_node_info_parser, \
178 &data) < 0) \
179 ret = -1; \
180 } while (0)
182 while (test->output != NULL) {
183 DO_TEST_NODE(*test);
184 ++test;
188 #define DO_TEST_VDI(collie) \
189 do { \
190 struct testVDIListParserData data = { \
191 .data = collie, \
192 .poolxml = poolxml, \
193 .volxml = volxml, \
194 }; \
195 if (virTestRun("vdi_list_parser", test_vdi_list_parser, \
196 &data) < 0) \
197 ret = -1; \
198 } while (0)
200 test = vdi_list_tests;
202 while (test->output != NULL) {
203 DO_TEST_VDI(*test);
204 ++test;
207 cleanup:
208 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
211 VIR_TEST_MAIN(mymain)