backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / xml2vmxtest.c
blob5d5dc0a5189a49114c37e7d77df906300997f23e
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 virVMXContext ctx;
18 static virDomainXMLOptionPtr xmlopt;
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, "esx");
34 /* i686 guest */
35 guest =
36 virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
37 VIR_ARCH_I686,
38 NULL, NULL, 0, NULL);
40 if (guest == NULL)
41 goto failure;
43 if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, NULL, NULL, 0,
44 NULL) == NULL) {
45 goto failure;
48 /* x86_64 guest */
49 guest =
50 virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
51 VIR_ARCH_X86_64,
52 NULL, NULL, 0, NULL);
54 if (guest == NULL)
55 goto failure;
57 if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, NULL, NULL, 0,
58 NULL) == NULL) {
59 goto failure;
62 return;
64 failure:
65 virObjectUnref(caps);
66 virObjectUnref(xmlopt);
67 caps = NULL;
70 static int
71 testCompareFiles(const char *xml, const char *vmx, int virtualHW_version)
73 int result = -1;
74 char *formatted = NULL;
75 virDomainDefPtr def = NULL;
77 def = virDomainDefParseFile(xml, caps, xmlopt, NULL,
78 VIR_DOMAIN_DEF_PARSE_INACTIVE);
80 if (def == NULL)
81 goto failure;
83 if (!virDomainDefCheckABIStability(def, def, xmlopt)) {
84 fprintf(stderr, "ABI stability check failed on %s", xml);
85 goto failure;
88 formatted = virVMXFormatConfig(&ctx, xmlopt, def, virtualHW_version);
89 if (formatted == NULL)
90 goto failure;
92 if (virTestCompareToFile(formatted, vmx) < 0)
93 goto failure;
95 result = 0;
97 failure:
98 VIR_FREE(formatted);
99 virDomainDefFree(def);
101 return result;
104 struct testInfo {
105 const char *input;
106 const char *output;
107 int virtualHW_version;
110 static int
111 testCompareHelper(const void *data)
113 int result = -1;
114 const struct testInfo *info = data;
115 char *xml = NULL;
116 char *vmx = NULL;
118 if (virAsprintf(&xml, "%s/xml2vmxdata/xml2vmx-%s.xml", abs_srcdir,
119 info->input) < 0 ||
120 virAsprintf(&vmx, "%s/xml2vmxdata/xml2vmx-%s.vmx", abs_srcdir,
121 info->output) < 0) {
122 goto cleanup;
125 result = testCompareFiles(xml, vmx, info->virtualHW_version);
127 cleanup:
128 VIR_FREE(xml);
129 VIR_FREE(vmx);
131 return result;
134 static int
135 testAutodetectSCSIControllerModel(virDomainDiskDefPtr def ATTRIBUTE_UNUSED,
136 int *model, void *opaque ATTRIBUTE_UNUSED)
138 *model = VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC;
140 return 0;
143 static char *
144 testFormatVMXFileName(const char *src, void *opaque ATTRIBUTE_UNUSED)
146 bool success = false;
147 char *copyOfDatastorePath = NULL;
148 char *tmp = NULL;
149 char *saveptr = NULL;
150 char *datastoreName = NULL;
151 char *directoryAndFileName = NULL;
152 char *absolutePath = NULL;
154 if (STRPREFIX(src, "[")) {
155 /* Found potential datastore path */
156 if (VIR_STRDUP(copyOfDatastorePath, src) < 0)
157 goto cleanup;
159 /* Expected format: '[<datastore>] <path>' where <path> is optional */
160 if ((tmp = STRSKIP(copyOfDatastorePath, "[")) == NULL || *tmp == ']' ||
161 (datastoreName = strtok_r(tmp, "]", &saveptr)) == NULL) {
162 goto cleanup;
165 directoryAndFileName = strtok_r(NULL, "", &saveptr);
167 if (directoryAndFileName == NULL) {
168 directoryAndFileName = (char *)"";
169 } else {
170 directoryAndFileName += strspn(directoryAndFileName, " ");
173 if (virAsprintf(&absolutePath, "/vmfs/volumes/%s/%s", datastoreName,
174 directoryAndFileName) < 0)
175 goto cleanup;
176 } else if (STRPREFIX(src, "/")) {
177 /* Found absolute path */
178 ignore_value(VIR_STRDUP(absolutePath, src));
179 } else {
180 /* Found relative path, this is not supported */
181 goto cleanup;
184 success = true;
186 cleanup:
187 if (! success)
188 VIR_FREE(absolutePath);
190 VIR_FREE(copyOfDatastorePath);
192 return absolutePath;
195 static int
196 mymain(void)
198 int result = 0;
200 # define DO_TEST(_in, _out, _version) \
201 do { \
202 struct testInfo info = { _in, _out, _version }; \
203 virResetLastError(); \
204 if (virTestRun("VMware XML-2-VMX "_in" -> "_out, \
205 testCompareHelper, &info) < 0) { \
206 result = -1; \
208 } while (0)
210 testCapsInit();
212 if (caps == NULL)
213 return EXIT_FAILURE;
215 if (!(xmlopt = virVMXDomainXMLConfInit()))
216 return EXIT_FAILURE;
218 ctx.opaque = NULL;
219 ctx.parseFileName = NULL;
220 ctx.formatFileName = testFormatVMXFileName;
221 ctx.autodetectSCSIControllerModel = testAutodetectSCSIControllerModel;
222 ctx.datacenterPath = NULL;
224 DO_TEST("minimal", "minimal", 4);
225 DO_TEST("minimal-64bit", "minimal-64bit", 4);
227 DO_TEST("graphics-vnc", "graphics-vnc", 4);
229 DO_TEST("scsi-driver", "scsi-driver", 4);
230 DO_TEST("scsi-writethrough", "scsi-writethrough", 4);
232 DO_TEST("harddisk-scsi-file", "harddisk-scsi-file", 4);
233 DO_TEST("harddisk-ide-file", "harddisk-ide-file", 4);
235 DO_TEST("cdrom-scsi-file", "cdrom-scsi-file", 4);
236 DO_TEST("cdrom-scsi-empty", "cdrom-scsi-empty", 4);
237 DO_TEST("cdrom-scsi-device", "cdrom-scsi-device", 4);
238 DO_TEST("cdrom-scsi-raw-device", "cdrom-scsi-raw-device", 4);
239 DO_TEST("cdrom-scsi-raw-auto-detect", "cdrom-scsi-raw-auto-detect", 4);
240 DO_TEST("cdrom-scsi-passthru", "cdrom-scsi-passthru", 4);
241 DO_TEST("cdrom-ide-file", "cdrom-ide-file", 4);
242 DO_TEST("cdrom-ide-empty", "cdrom-ide-empty", 4);
243 DO_TEST("cdrom-ide-device", "cdrom-ide-device", 4);
244 DO_TEST("cdrom-ide-raw-device", "cdrom-ide-raw-device", 4);
245 DO_TEST("cdrom-ide-raw-auto-detect", "cdrom-ide-raw-auto-detect", 4);
247 DO_TEST("floppy-file", "floppy-file", 4);
248 DO_TEST("floppy-device", "floppy-device", 4);
250 DO_TEST("sharedfolder", "sharedfolder", 4);
252 DO_TEST("ethernet-e1000", "ethernet-e1000", 4);
253 DO_TEST("ethernet-vmxnet2", "ethernet-vmxnet2", 4);
255 DO_TEST("ethernet-custom", "ethernet-custom", 4);
256 DO_TEST("ethernet-bridged", "ethernet-bridged", 4);
257 DO_TEST("ethernet-nat", "ethernet-nat", 4);
259 DO_TEST("ethernet-generated", "ethernet-generated", 4);
260 DO_TEST("ethernet-static", "ethernet-static", 4);
261 DO_TEST("ethernet-vpx", "ethernet-vpx", 4);
262 DO_TEST("ethernet-other", "ethernet-other", 4);
264 DO_TEST("serial-file", "serial-file", 4);
265 DO_TEST("serial-device", "serial-device", 4);
266 DO_TEST("serial-pipe", "serial-pipe", 4);
267 DO_TEST("serial-network-server", "serial-network-server", 7);
268 DO_TEST("serial-network-client", "serial-network-client", 7);
270 DO_TEST("parallel-file", "parallel-file", 4);
271 DO_TEST("parallel-device", "parallel-device", 4);
273 DO_TEST("esx-in-the-wild-1", "esx-in-the-wild-1", 4);
274 DO_TEST("esx-in-the-wild-2", "esx-in-the-wild-2", 4);
275 DO_TEST("esx-in-the-wild-3", "esx-in-the-wild-3", 4);
276 DO_TEST("esx-in-the-wild-4", "esx-in-the-wild-4", 4);
277 DO_TEST("esx-in-the-wild-5", "esx-in-the-wild-5", 4);
278 DO_TEST("esx-in-the-wild-6", "esx-in-the-wild-6", 4);
279 DO_TEST("esx-in-the-wild-7", "esx-in-the-wild-7", 4);
280 DO_TEST("esx-in-the-wild-9", "esx-in-the-wild-9", 10);
282 DO_TEST("gsx-in-the-wild-1", "gsx-in-the-wild-1", 4);
283 DO_TEST("gsx-in-the-wild-2", "gsx-in-the-wild-2", 4);
284 DO_TEST("gsx-in-the-wild-3", "gsx-in-the-wild-3", 4);
285 DO_TEST("gsx-in-the-wild-4", "gsx-in-the-wild-4", 4);
287 DO_TEST("ws-in-the-wild-1", "ws-in-the-wild-1", 8);
288 DO_TEST("ws-in-the-wild-2", "ws-in-the-wild-2", 8);
290 DO_TEST("fusion-in-the-wild-1", "fusion-in-the-wild-1", 9);
292 DO_TEST("annotation", "annotation", 4);
294 DO_TEST("smbios", "smbios", 4);
296 DO_TEST("svga", "svga", 4);
298 DO_TEST("firmware-efi", "firmware-efi", 4);
300 DO_TEST("datacenterpath", "datacenterpath", 4);
302 virObjectUnref(caps);
303 virObjectUnref(xmlopt);
305 return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
308 VIR_TEST_MAIN(mymain)
310 #else
312 int main(void)
314 return EXIT_AM_SKIP;
317 #endif /* WITH_VMX */