6 #include "storage/storage_backend.h"
7 #include "testutilsqemu.h"
10 #define VIR_FROM_THIS VIR_FROM_NONE
12 const char create_tool[] = "qemu-img";
14 /* createVol sets this on volume creation */
16 testSetVolumeType(virStorageVolDefPtr vol,
17 virStoragePoolDefPtr pool)
23 case VIR_STORAGE_POOL_DIR:
24 case VIR_STORAGE_POOL_FS:
25 case VIR_STORAGE_POOL_NETFS:
26 vol->type = VIR_STORAGE_VOL_FILE;
29 case VIR_STORAGE_POOL_LOGICAL:
30 vol->type = VIR_STORAGE_VOL_BLOCK;
36 testCompareXMLToArgvFiles(bool shouldFail,
39 const char *inputpoolxml,
40 const char *inputvolxml,
45 char *volXmlData = NULL;
46 char *poolXmlData = NULL;
47 char *inputpoolXmlData = NULL;
48 char *inputvolXmlData = NULL;
49 char *expectedCmdline = NULL;
50 char *actualCmdline = NULL;
55 virCommandPtr cmd = NULL;
58 virStorageVolDefPtr vol = NULL, inputvol = NULL;
59 virStoragePoolDefPtr pool = NULL;
60 virStoragePoolDefPtr inputpool = NULL;
61 virStoragePoolObj poolobj = {.def = NULL };
64 if (!(conn = virGetConnect()))
67 if (virtTestLoadFile(poolxml, &poolXmlData) < 0)
69 if (virtTestLoadFile(volxml, &volXmlData) < 0)
72 virtTestLoadFile(inputvolxml, &inputvolXmlData) < 0)
75 if (!(pool = virStoragePoolDefParseString(poolXmlData)))
81 if (virtTestLoadFile(inputpoolxml, &inputpoolXmlData) < 0)
83 if (!(inputpool = virStoragePoolDefParseString(inputpoolXmlData)))
87 if (!(vol = virStorageVolDefParseString(pool, volXmlData)))
91 !(inputvol = virStorageVolDefParseString(inputpool, inputvolXmlData)))
94 testSetVolumeType(vol, pool);
95 testSetVolumeType(inputvol, inputpool);
97 cmd = virStorageBackendCreateQemuImgCmd(conn, &poolobj, vol, inputvol,
98 flags, create_tool, imgformat);
107 if (!(actualCmdline = virCommandToString(cmd)))
110 len = virtTestLoadFile(cmdline, &expectedCmdline);
113 if (len && expectedCmdline[len-1] == '\n')
114 expectedCmdline[len-1] = '\0';
116 if (STRNEQ_NULLABLE(expectedCmdline, actualCmdline)) {
117 virtTestDifference(stderr, expectedCmdline, actualCmdline);
124 virStoragePoolDefFree(pool);
125 virStoragePoolDefFree(inputpool);
126 virStorageVolDefFree(vol);
127 virStorageVolDefFree(inputvol);
129 VIR_FREE(actualCmdline);
130 VIR_FREE(expectedCmdline);
131 VIR_FREE(inputpoolXmlData);
132 VIR_FREE(poolXmlData);
133 VIR_FREE(volXmlData);
134 VIR_FREE(inputvolXmlData);
135 virObjectUnref(conn);
143 const char *inputpool;
144 const char *inputvol;
151 testCompareXMLToArgvHelper(const void *data)
154 const struct testInfo *info = data;
155 char *poolxml = NULL;
156 char *inputpoolxml = NULL;
158 char *inputvolxml = NULL;
159 char *cmdline = NULL;
161 if (info->inputvol &&
162 virAsprintf(&inputvolxml, "%s/storagevolxml2xmlin/%s.xml",
163 abs_srcdir, info->inputvol) < 0)
165 if (info->inputpool &&
166 virAsprintf(&inputpoolxml, "%s/storagepoolxml2xmlin/%s.xml",
167 abs_srcdir, info->inputpool) < 0)
169 if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml",
170 abs_srcdir, info->pool) < 0 ||
171 virAsprintf(&volxml, "%s/storagevolxml2xmlin/%s.xml",
172 abs_srcdir, info->vol) < 0) {
175 if (virAsprintf(&cmdline, "%s/storagevolxml2argvdata/%s.argv",
176 abs_srcdir, info->cmdline) < 0 && !info->shouldFail)
179 result = testCompareXMLToArgvFiles(info->shouldFail, poolxml, volxml,
180 inputpoolxml, inputvolxml,
181 cmdline, info->flags,
187 VIR_FREE(inputvolxml);
188 VIR_FREE(inputpoolxml);
207 unsigned int flags = VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
209 #define DO_TEST_FULL(shouldFail, pool, vol, inputpool, inputvol, cmdline, \
212 struct testInfo info = { shouldFail, pool, vol, inputpool, inputvol, \
213 cmdline, flags, imgformat }; \
214 if (virtTestRun("Storage Vol XML-2-argv " cmdline, \
215 testCompareXMLToArgvHelper, &info) < 0) \
220 #define DO_TEST(pool, ...) \
221 DO_TEST_FULL(false, pool, __VA_ARGS__)
223 #define DO_TEST_FAIL(pool, ...) \
224 DO_TEST_FULL(true, pool, __VA_ARGS__)
226 DO_TEST("pool-dir", "vol-qcow2",
228 "qcow2", 0, FMT_OPTIONS);
229 DO_TEST_FAIL("pool-dir", "vol-qcow2",
231 "qcow2-prealloc", flags, FMT_OPTIONS);
232 DO_TEST("pool-dir", "vol-qcow2-nobacking",
234 "qcow2-nobacking-prealloc", flags, FMT_OPTIONS);
235 DO_TEST("pool-dir", "vol-qcow2-nobacking",
236 "pool-dir", "vol-file",
237 "qcow2-nobacking-convert-prealloc", flags, FMT_OPTIONS);
238 DO_TEST_FAIL("pool-dir", "vol-qcow2",
239 "pool-dir", "vol-file",
240 "qcow2-convert-prealloc", flags, FMT_OPTIONS);
241 DO_TEST("pool-dir", "vol-qcow2",
243 "qcow2-flag", 0, FMT_FLAG);
244 DO_TEST("pool-dir", "vol-qcow2-nobacking",
246 "qcow2-nobacking-flag", 0, FMT_FLAG);
247 DO_TEST("pool-dir", "vol-qcow2-nobacking",
248 "pool-dir", "vol-file",
249 "qcow2-nobacking-convert-flag", 0, FMT_FLAG);
250 DO_TEST("pool-dir", "vol-qcow2",
252 "qcow2-none", 0, FMT_NONE);
253 DO_TEST("pool-dir", "vol-qcow2-nobacking",
255 "qcow2-nobacking-none", 0, FMT_NONE);
256 DO_TEST("pool-dir", "vol-qcow2-nobacking",
257 "pool-dir", "vol-file",
258 "qcow2-nobacking-convert-none", 0, FMT_NONE);
259 DO_TEST("pool-dir", "vol-qcow2-lazy",
261 "qcow2-lazy", 0, FMT_OPTIONS);
262 DO_TEST("pool-dir", "vol-qcow2-1.1",
264 "qcow2-1.1", 0, FMT_OPTIONS);
265 DO_TEST_FAIL("pool-dir", "vol-qcow2-0.10-lazy",
267 "qcow2-0.10-lazy", 0, FMT_OPTIONS);
268 DO_TEST("pool-dir", "vol-qcow2-nobacking",
269 "pool-logical", "vol-logical",
270 "qcow2-from-logical", 0, FMT_OPTIONS);
271 DO_TEST("pool-logical", "vol-logical",
272 "pool-dir", "vol-qcow2-nobacking",
273 "logical-from-qcow2", 0, FMT_OPTIONS);
275 DO_TEST("pool-dir", "vol-qcow2",
277 "qcow2-compat", 0, FMT_COMPAT);
278 DO_TEST("pool-dir", "vol-qcow2-nobacking",
280 "qcow2-nobacking-prealloc-compat", flags, FMT_COMPAT);
281 DO_TEST("pool-dir", "vol-qcow2-nobacking",
282 "pool-dir", "vol-file",
283 "qcow2-nobacking-convert-prealloc-compat", flags, FMT_COMPAT);
284 DO_TEST("pool-dir", "vol-qcow2-lazy",
286 "qcow2-lazy", 0, FMT_COMPAT);
287 DO_TEST("pool-dir", "vol-qcow2-1.1",
289 "qcow2-1.1", 0, FMT_COMPAT);
290 DO_TEST_FAIL("pool-dir", "vol-qcow2-0.10-lazy",
292 "qcow2-0.10-lazy", 0, FMT_COMPAT);
293 DO_TEST("pool-dir", "vol-qcow2-nobacking",
294 "pool-logical", "vol-logical",
295 "qcow2-from-logical-compat", 0, FMT_COMPAT);
296 DO_TEST("pool-logical", "vol-logical",
297 "pool-dir", "vol-qcow2-nobacking",
298 "logical-from-qcow2", 0, FMT_COMPAT);
300 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
303 VIRT_TEST_MAIN(mymain)