backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / virstorageutiltest.c
blob94d8b9b0916bea3a90ebe922e9dc694824e116bc
1 /*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library. If not, see
14 * <http://www.gnu.org/licenses/>.
17 #include <config.h>
20 #include "testutils.h"
21 #include "virerror.h"
22 #include "virfile.h"
23 #include "virlog.h"
24 #include "virstring.h"
26 #include "storage/storage_util.h"
28 #define VIR_FROM_THIS VIR_FROM_NONE
30 VIR_LOG_INIT("tests.storageutiltest");
33 struct testGlusterExtractPoolSourcesData {
34 const char *srcxml;
35 const char *dstxml;
36 virStoragePoolType type;
39 static int
40 testGlusterExtractPoolSources(const void *opaque)
42 const struct testGlusterExtractPoolSourcesData *data = opaque;
43 virStoragePoolSourceList list = { .type = data->type,
44 .nsources = 0,
45 .sources = NULL
47 size_t i;
48 int ret = -1;
49 VIR_AUTOFREE(char *) srcxmldata = NULL;
50 VIR_AUTOFREE(char *) actual = NULL;
52 if (virTestLoadFile(data->srcxml, &srcxmldata) < 0)
53 goto cleanup;
55 if (virStorageUtilGlusterExtractPoolSources("testhost", srcxmldata,
56 &list, data->type) < 0)
57 goto cleanup;
59 if (!(actual = virStoragePoolSourceListFormat(&list)))
60 goto cleanup;
62 ret = virTestCompareToFile(actual, data->dstxml);
64 cleanup:
65 for (i = 0; i < list.nsources; i++)
66 virStoragePoolSourceClear(&list.sources[i]);
67 VIR_FREE(list.sources);
69 return ret;
73 static int
74 mymain(void)
76 int ret = 0;
78 #define DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_FULL(testname, sffx, pooltype) \
79 do { \
80 struct testGlusterExtractPoolSourcesData data; \
81 data.srcxml = abs_srcdir "/virstorageutildata/" \
82 "gluster-parse-" testname "-src.xml"; \
83 data.dstxml = abs_srcdir "/virstorageutildata/" \
84 "gluster-parse-" testname "-" sffx ".xml"; \
85 data.type = pooltype; \
86 if (virTestRun("gluster-parse-" testname "-" sffx, \
87 testGlusterExtractPoolSources, &data) < 0) \
88 ret = -1; \
89 } while (0)
91 #define DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_NATIVE(testname) \
92 DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_FULL(testname, "native", \
93 VIR_STORAGE_POOL_GLUSTER)
94 #define DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_NETFS(testname) \
95 DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_FULL(testname, "netfs", \
96 VIR_STORAGE_POOL_NETFS)
98 DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_NATIVE("basic");
99 DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_NETFS("basic");
100 DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_NATIVE("multivol");
101 DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_NETFS("multivol");
103 #undef DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_NATIVE
104 #undef DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_NETFS
105 #undef DO_TEST_GLUSTER_EXTRACT_POOL_SOURCES_FULL
107 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
110 VIR_TEST_MAIN(mymain)