backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / storagepoolxml2argvtest.c
blob0c01931946407798e2bb4fca52dd3222b3ed1a95
1 #include <config.h>
3 #include "internal.h"
4 #include "testutils.h"
5 #include "datatypes.h"
6 #include "storage/storage_util.h"
7 #include "testutilsqemu.h"
8 #include "virstring.h"
10 #define VIR_FROM_THIS VIR_FROM_NONE
12 #ifndef MOUNT
13 # define MOUNT "/usr/bin/mount"
14 #endif
16 #ifndef VGCHANGE
17 # define VGCHANGE "/usr/sbin/vgchange"
18 #endif
20 static int
21 testCompareXMLToArgvFiles(bool shouldFail,
22 const char *poolxml,
23 const char *cmdline)
25 int ret = -1;
26 virStoragePoolDefPtr def = NULL;
27 virStoragePoolObjPtr pool = NULL;
28 const char *defTypeStr;
29 VIR_AUTOFREE(char *) actualCmdline = NULL;
30 VIR_AUTOFREE(char *) src = NULL;
31 VIR_AUTOPTR(virCommand) cmd = NULL;
33 if (!(def = virStoragePoolDefParseFile(poolxml)))
34 goto cleanup;
35 defTypeStr = virStoragePoolTypeToString(def->type);
37 switch ((virStoragePoolType)def->type) {
38 case VIR_STORAGE_POOL_FS:
39 case VIR_STORAGE_POOL_NETFS:
40 if (!(pool = virStoragePoolObjNew())) {
41 VIR_TEST_DEBUG("pool type '%s' alloc pool obj fails\n", defTypeStr);
42 goto cleanup;
44 virStoragePoolObjSetDef(pool, def);
46 if (!(src = virStorageBackendFileSystemGetPoolSource(pool))) {
47 VIR_TEST_DEBUG("pool type '%s' has no pool source\n", defTypeStr);
48 def = NULL;
49 goto cleanup;
52 cmd = virStorageBackendFileSystemMountCmd(MOUNT, def, src);
53 def = NULL;
54 break;
56 case VIR_STORAGE_POOL_LOGICAL:
57 cmd = virStorageBackendLogicalChangeCmd(VGCHANGE, def, true);
58 break;
60 case VIR_STORAGE_POOL_DIR:
61 case VIR_STORAGE_POOL_DISK:
62 case VIR_STORAGE_POOL_ISCSI:
63 case VIR_STORAGE_POOL_ISCSI_DIRECT:
64 case VIR_STORAGE_POOL_SCSI:
65 case VIR_STORAGE_POOL_MPATH:
66 case VIR_STORAGE_POOL_RBD:
67 case VIR_STORAGE_POOL_SHEEPDOG:
68 case VIR_STORAGE_POOL_GLUSTER:
69 case VIR_STORAGE_POOL_ZFS:
70 case VIR_STORAGE_POOL_VSTORAGE:
71 case VIR_STORAGE_POOL_LAST:
72 default:
73 VIR_TEST_DEBUG("pool type '%s' has no xml2argv test\n", defTypeStr);
74 goto cleanup;
77 if (!(actualCmdline = virCommandToString(cmd, false))) {
78 VIR_TEST_DEBUG("pool type '%s' failed to get commandline\n", defTypeStr);
79 goto cleanup;
82 virTestClearCommandPath(actualCmdline);
83 if (virTestCompareToFile(actualCmdline, cmdline) < 0)
84 goto cleanup;
86 ret = 0;
88 cleanup:
89 virStoragePoolDefFree(def);
90 virStoragePoolObjEndAPI(&pool);
91 if (shouldFail) {
92 virResetLastError();
93 ret = 0;
95 return ret;
98 struct testInfo {
99 bool shouldFail;
100 const char *pool;
101 const char *platformSuffix;
104 static int
105 testCompareXMLToArgvHelper(const void *data)
107 const struct testInfo *info = data;
108 VIR_AUTOFREE(char *) poolxml = NULL;
109 VIR_AUTOFREE(char *) cmdline = NULL;
111 if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml",
112 abs_srcdir, info->pool) < 0)
113 return -1;
115 if (virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s%s.argv",
116 abs_srcdir, info->pool, info->platformSuffix) < 0 &&
117 !info->shouldFail)
118 return -1;
120 return testCompareXMLToArgvFiles(info->shouldFail, poolxml, cmdline);
124 static int
125 mymain(void)
127 int ret = 0;
128 #ifdef __linux__
129 const char *platform = "-linux";
130 #elif defined(__FreeBSD__)
131 const char *platform = "-freebsd";
132 #else
133 const char *platform = "";
134 #endif
136 #define DO_TEST_FULL(shouldFail, pool, platformSuffix) \
137 do { \
138 struct testInfo info = { shouldFail, pool, platformSuffix }; \
139 if (virTestRun("Storage Pool XML-2-argv " pool, \
140 testCompareXMLToArgvHelper, &info) < 0) \
141 ret = -1; \
143 while (0);
145 #define DO_TEST(pool, ...) \
146 DO_TEST_FULL(false, pool, "")
148 #define DO_TEST_FAIL(pool, ...) \
149 DO_TEST_FULL(true, pool, "")
151 #define DO_TEST_PLATFORM(pool, ...) \
152 DO_TEST_FULL(false, pool, platform)
154 if (storageRegisterAll() < 0)
155 return EXIT_FAILURE;
157 DO_TEST_FAIL("pool-dir");
158 DO_TEST_FAIL("pool-dir-naming");
159 DO_TEST("pool-logical");
160 DO_TEST("pool-logical-nopath");
161 DO_TEST("pool-logical-create");
162 DO_TEST("pool-logical-noname");
163 DO_TEST_FAIL("pool-disk");
164 DO_TEST_FAIL("pool-disk-device-nopartsep");
165 DO_TEST_FAIL("pool-iscsi");
166 DO_TEST_FAIL("pool-iscsi-auth");
168 DO_TEST_PLATFORM("pool-fs");
169 DO_TEST_PLATFORM("pool-netfs");
170 DO_TEST_PLATFORM("pool-netfs-auto");
171 DO_TEST_PLATFORM("pool-netfs-protocol-ver");
172 #if WITH_STORAGE_FS
173 DO_TEST_PLATFORM("pool-netfs-ns-mountopts");
174 #endif
175 DO_TEST_PLATFORM("pool-netfs-gluster");
176 DO_TEST_PLATFORM("pool-netfs-cifs");
178 DO_TEST_FAIL("pool-scsi");
179 DO_TEST_FAIL("pool-scsi-type-scsi-host");
180 DO_TEST_FAIL("pool-scsi-type-fc-host");
181 DO_TEST_FAIL("pool-scsi-type-fc-host-managed");
182 DO_TEST_FAIL("pool-mpath");
183 DO_TEST_FAIL("pool-iscsi-multiiqn");
184 DO_TEST_FAIL("pool-iscsi-vendor-product");
185 DO_TEST_FAIL("pool-sheepdog");
186 DO_TEST_FAIL("pool-gluster");
187 DO_TEST_FAIL("pool-gluster-sub");
188 DO_TEST_FAIL("pool-scsi-type-scsi-host-stable");
189 DO_TEST_FAIL("pool-zfs");
190 DO_TEST_FAIL("pool-zfs-sourcedev");
191 DO_TEST_FAIL("pool-rbd");
192 DO_TEST_FAIL("pool-vstorage");
193 DO_TEST_FAIL("pool-iscsi-direct-auth");
194 DO_TEST_FAIL("pool-iscsi-direct");
196 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
199 VIR_TEST_MAIN(mymain)