backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / vmx2xmltest.c
blobd7d03f1753b4e99945b11ce7824c1412c3a5b7b4
1 #include <config.h>
3 #include "testutils.h"
5 #ifdef WITH_VMX
7 # include <unistd.h>
9 # include "internal.h"
10 # include "viralloc.h"
11 # include "vmx/vmx.h"
12 # include "virstring.h"
14 # define VIR_FROM_THIS VIR_FROM_VMWARE
16 static virCapsPtr caps;
17 static virDomainXMLOptionPtr xmlopt;
18 static virVMXContext ctx;
21 static void
22 testCapsInit(void)
24 virCapsGuestPtr guest = NULL;
26 caps = virCapabilitiesNew(VIR_ARCH_I686, true, true);
28 if (caps == NULL)
29 return;
31 virCapabilitiesAddHostMigrateTransport(caps, "vpxmigr");
33 /* i686 guest */
34 guest =
35 virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
36 VIR_ARCH_I686,
37 NULL, NULL, 0, NULL);
39 if (guest == NULL)
40 goto failure;
42 if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, NULL, NULL, 0,
43 NULL) == NULL) {
44 goto failure;
47 /* x86_64 guest */
48 guest =
49 virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
50 VIR_ARCH_X86_64,
51 NULL, NULL, 0, NULL);
53 if (guest == NULL)
54 goto failure;
56 if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, NULL, NULL, 0,
57 NULL) == NULL) {
58 goto failure;
61 return;
63 failure:
64 virObjectUnref(caps);
65 caps = NULL;
68 static int
69 testCompareFiles(const char *vmx, const char *xml)
71 int ret = -1;
72 char *vmxData = NULL;
73 char *formatted = NULL;
74 virDomainDefPtr def = NULL;
76 if (virTestLoadFile(vmx, &vmxData) < 0)
77 goto cleanup;
79 if (!(def = virVMXParseConfig(&ctx, xmlopt, caps, vmxData)))
80 goto cleanup;
82 if (!virDomainDefCheckABIStability(def, def, xmlopt)) {
83 fprintf(stderr, "ABI stability check failed on %s", vmx);
84 goto cleanup;
87 if (!(formatted = virDomainDefFormat(def, caps,
88 VIR_DOMAIN_DEF_FORMAT_SECURE)))
89 goto cleanup;
91 if (virTestCompareToFile(formatted, xml) < 0)
92 goto cleanup;
94 ret = 0;
96 cleanup:
97 VIR_FREE(vmxData);
98 VIR_FREE(formatted);
99 virDomainDefFree(def);
101 return ret;
104 struct testInfo {
105 const char *input;
106 const char *output;
109 static int
110 testCompareHelper(const void *data)
112 int ret = -1;
113 const struct testInfo *info = data;
114 char *vmx = NULL;
115 char *xml = NULL;
117 if (virAsprintf(&vmx, "%s/vmx2xmldata/vmx2xml-%s.vmx", abs_srcdir,
118 info->input) < 0 ||
119 virAsprintf(&xml, "%s/vmx2xmldata/vmx2xml-%s.xml", abs_srcdir,
120 info->output) < 0) {
121 goto cleanup;
124 ret = testCompareFiles(vmx, xml);
126 cleanup:
127 VIR_FREE(vmx);
128 VIR_FREE(xml);
130 return ret;
133 static char *
134 testParseVMXFileName(const char *fileName, void *opaque ATTRIBUTE_UNUSED)
136 char *copyOfFileName = NULL;
137 char *tmp = NULL;
138 char *saveptr = NULL;
139 char *datastoreName = NULL;
140 char *directoryAndFileName = NULL;
141 char *src = NULL;
143 if (STRPREFIX(fileName, "/vmfs/volumes/")) {
144 /* Found absolute path referencing a file inside a datastore */
145 if (VIR_STRDUP(copyOfFileName, fileName) < 0)
146 goto cleanup;
148 /* Expected format: '/vmfs/volumes/<datastore>/<path>' */
149 if ((tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) == NULL ||
150 (datastoreName = strtok_r(tmp, "/", &saveptr)) == NULL ||
151 (directoryAndFileName = strtok_r(NULL, "", &saveptr)) == NULL) {
152 goto cleanup;
155 if (virAsprintf(&src, "[%s] %s", datastoreName,
156 directoryAndFileName) < 0)
157 goto cleanup;
158 } else if (STRPREFIX(fileName, "/")) {
159 /* Found absolute path referencing a file outside a datastore */
160 ignore_value(VIR_STRDUP(src, fileName));
161 } else if (strchr(fileName, '/') != NULL) {
162 /* Found relative path, this is not supported */
163 src = NULL;
164 } else {
165 /* Found single file name referencing a file inside a datastore */
166 if (virAsprintf(&src, "[datastore] directory/%s", fileName) < 0)
167 goto cleanup;
170 cleanup:
171 VIR_FREE(copyOfFileName);
173 return src;
176 static int
177 mymain(void)
179 int ret = 0;
181 # define DO_TEST(_in, _out) \
182 do { \
183 struct testInfo info = { _in, _out }; \
184 virResetLastError(); \
185 if (virTestRun("VMware VMX-2-XML "_in" -> "_out, \
186 testCompareHelper, &info) < 0) { \
187 ret = -1; \
189 } while (0)
191 testCapsInit();
193 if (caps == NULL)
194 return EXIT_FAILURE;
196 if (!(xmlopt = virVMXDomainXMLConfInit()))
197 return EXIT_FAILURE;
199 ctx.opaque = NULL;
200 ctx.parseFileName = testParseVMXFileName;
201 ctx.formatFileName = NULL;
202 ctx.autodetectSCSIControllerModel = NULL;
203 ctx.datacenterPath = NULL;
205 DO_TEST("case-insensitive-1", "case-insensitive-1");
206 DO_TEST("case-insensitive-2", "case-insensitive-2");
208 DO_TEST("minimal", "minimal");
209 DO_TEST("minimal-64bit", "minimal-64bit");
211 DO_TEST("graphics-vnc", "graphics-vnc");
213 DO_TEST("scsi-driver", "scsi-driver");
214 DO_TEST("scsi-writethrough", "scsi-writethrough");
216 DO_TEST("harddisk-scsi-file", "harddisk-scsi-file");
217 DO_TEST("harddisk-ide-file", "harddisk-ide-file");
218 DO_TEST("harddisk-transient", "harddisk-transient");
220 DO_TEST("cdrom-scsi-file", "cdrom-scsi-file");
221 DO_TEST("cdrom-scsi-empty", "cdrom-scsi-empty");
222 DO_TEST("cdrom-scsi-device", "cdrom-scsi-device");
223 DO_TEST("cdrom-scsi-raw-device", "cdrom-scsi-raw-device");
224 DO_TEST("cdrom-scsi-raw-auto-detect", "cdrom-scsi-raw-auto-detect");
225 DO_TEST("cdrom-scsi-passthru", "cdrom-scsi-passthru");
226 DO_TEST("cdrom-ide-file", "cdrom-ide-file");
227 DO_TEST("cdrom-ide-empty", "cdrom-ide-empty");
228 DO_TEST("cdrom-ide-device", "cdrom-ide-device");
229 DO_TEST("cdrom-ide-raw-device", "cdrom-ide-raw-device");
230 DO_TEST("cdrom-ide-raw-auto-detect", "cdrom-ide-raw-auto-detect");
231 DO_TEST("cdrom-ide-raw-auto-detect", "cdrom-ide-raw-auto-detect");
233 DO_TEST("floppy-file", "floppy-file");
234 DO_TEST("floppy-device", "floppy-device");
236 DO_TEST("sharedfolder", "sharedfolder");
238 DO_TEST("ethernet-e1000", "ethernet-e1000");
239 DO_TEST("ethernet-vmxnet2", "ethernet-vmxnet2");
241 DO_TEST("ethernet-custom", "ethernet-custom");
242 DO_TEST("ethernet-bridged", "ethernet-bridged");
243 DO_TEST("ethernet-nat", "ethernet-nat");
245 DO_TEST("ethernet-generated", "ethernet-generated");
246 DO_TEST("ethernet-static", "ethernet-static");
247 DO_TEST("ethernet-vpx", "ethernet-vpx");
248 DO_TEST("ethernet-other", "ethernet-other");
250 DO_TEST("serial-file", "serial-file");
251 DO_TEST("serial-device", "serial-device");
252 DO_TEST("serial-pipe-client-app", "serial-pipe");
253 DO_TEST("serial-pipe-server-vm", "serial-pipe");
254 DO_TEST("serial-pipe-client-app", "serial-pipe");
255 DO_TEST("serial-pipe-server-vm", "serial-pipe");
256 DO_TEST("serial-network-server", "serial-network-server");
257 DO_TEST("serial-network-client", "serial-network-client");
259 DO_TEST("parallel-file", "parallel-file");
260 DO_TEST("parallel-device", "parallel-device");
262 DO_TEST("esx-in-the-wild-1", "esx-in-the-wild-1");
263 DO_TEST("esx-in-the-wild-2", "esx-in-the-wild-2");
264 DO_TEST("esx-in-the-wild-3", "esx-in-the-wild-3");
265 DO_TEST("esx-in-the-wild-4", "esx-in-the-wild-4");
266 DO_TEST("esx-in-the-wild-5", "esx-in-the-wild-5");
267 DO_TEST("esx-in-the-wild-6", "esx-in-the-wild-6");
268 DO_TEST("esx-in-the-wild-7", "esx-in-the-wild-7");
269 DO_TEST("esx-in-the-wild-8", "esx-in-the-wild-8");
270 DO_TEST("esx-in-the-wild-9", "esx-in-the-wild-9");
272 DO_TEST("gsx-in-the-wild-1", "gsx-in-the-wild-1");
273 DO_TEST("gsx-in-the-wild-2", "gsx-in-the-wild-2");
274 DO_TEST("gsx-in-the-wild-3", "gsx-in-the-wild-3");
275 DO_TEST("gsx-in-the-wild-4", "gsx-in-the-wild-4");
277 DO_TEST("ws-in-the-wild-1", "ws-in-the-wild-1");
278 DO_TEST("ws-in-the-wild-2", "ws-in-the-wild-2");
280 DO_TEST("fusion-in-the-wild-1", "fusion-in-the-wild-1");
282 DO_TEST("annotation", "annotation");
284 DO_TEST("smbios", "smbios");
286 DO_TEST("svga", "svga");
288 DO_TEST("firmware-efi", "firmware-efi");
290 ctx.datacenterPath = "folder1/folder2/datacenter1";
292 DO_TEST("datacenterpath", "datacenterpath");
294 virObjectUnref(caps);
295 virObjectUnref(xmlopt);
297 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
300 VIR_TEST_MAIN(mymain)
302 #else
304 int main(void)
306 return EXIT_AM_SKIP;
309 #endif /* WITH_VMX */