10 # include "viralloc.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
;
24 virCapsGuestPtr guest
= NULL
;
26 caps
= virCapabilitiesNew(VIR_ARCH_I686
, true, true);
31 virCapabilitiesAddHostMigrateTransport(caps
, "vpxmigr");
35 virCapabilitiesAddGuest(caps
, VIR_DOMAIN_OSTYPE_HVM
,
42 if (virCapabilitiesAddGuestDomain(guest
, VIR_DOMAIN_VIRT_VMWARE
, NULL
, NULL
, 0,
49 virCapabilitiesAddGuest(caps
, VIR_DOMAIN_OSTYPE_HVM
,
56 if (virCapabilitiesAddGuestDomain(guest
, VIR_DOMAIN_VIRT_VMWARE
, NULL
, NULL
, 0,
69 testCompareFiles(const char *vmx
, const char *xml
)
73 char *formatted
= NULL
;
74 virDomainDefPtr def
= NULL
;
76 if (virTestLoadFile(vmx
, &vmxData
) < 0)
79 if (!(def
= virVMXParseConfig(&ctx
, xmlopt
, caps
, vmxData
)))
82 if (!virDomainDefCheckABIStability(def
, def
, xmlopt
)) {
83 fprintf(stderr
, "ABI stability check failed on %s", vmx
);
87 if (!(formatted
= virDomainDefFormat(def
, caps
,
88 VIR_DOMAIN_DEF_FORMAT_SECURE
)))
91 if (virTestCompareToFile(formatted
, xml
) < 0)
99 virDomainDefFree(def
);
110 testCompareHelper(const void *data
)
113 const struct testInfo
*info
= data
;
117 if (virAsprintf(&vmx
, "%s/vmx2xmldata/vmx2xml-%s.vmx", abs_srcdir
,
119 virAsprintf(&xml
, "%s/vmx2xmldata/vmx2xml-%s.xml", abs_srcdir
,
124 ret
= testCompareFiles(vmx
, xml
);
134 testParseVMXFileName(const char *fileName
, void *opaque ATTRIBUTE_UNUSED
)
136 char *copyOfFileName
= NULL
;
138 char *saveptr
= NULL
;
139 char *datastoreName
= NULL
;
140 char *directoryAndFileName
= NULL
;
143 if (STRPREFIX(fileName
, "/vmfs/volumes/")) {
144 /* Found absolute path referencing a file inside a datastore */
145 if (VIR_STRDUP(copyOfFileName
, fileName
) < 0)
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
) {
155 if (virAsprintf(&src
, "[%s] %s", datastoreName
,
156 directoryAndFileName
) < 0)
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 */
165 /* Found single file name referencing a file inside a datastore */
166 if (virAsprintf(&src
, "[datastore] directory/%s", fileName
) < 0)
171 VIR_FREE(copyOfFileName
);
181 # define DO_TEST(_in, _out) \
183 struct testInfo info = { _in, _out }; \
184 virResetLastError(); \
185 if (virTestRun("VMware VMX-2-XML "_in" -> "_out, \
186 testCompareHelper, &info) < 0) { \
196 if (!(xmlopt
= virVMXDomainXMLConfInit()))
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
)
309 #endif /* WITH_VMX */