10 # include "viralloc.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
;
24 virCapsGuestPtr guest
= NULL
;
26 caps
= virCapabilitiesNew(VIR_ARCH_I686
, true, true);
31 virCapabilitiesAddHostMigrateTransport(caps
, "esx");
36 virCapabilitiesAddGuest(caps
, VIR_DOMAIN_OSTYPE_HVM
,
43 if (virCapabilitiesAddGuestDomain(guest
, VIR_DOMAIN_VIRT_VMWARE
, NULL
, NULL
, 0,
50 virCapabilitiesAddGuest(caps
, VIR_DOMAIN_OSTYPE_HVM
,
57 if (virCapabilitiesAddGuestDomain(guest
, VIR_DOMAIN_VIRT_VMWARE
, NULL
, NULL
, 0,
66 virObjectUnref(xmlopt
);
71 testCompareFiles(const char *xml
, const char *vmx
, int virtualHW_version
)
74 char *formatted
= NULL
;
75 virDomainDefPtr def
= NULL
;
77 def
= virDomainDefParseFile(xml
, caps
, xmlopt
, NULL
,
78 VIR_DOMAIN_DEF_PARSE_INACTIVE
);
83 if (!virDomainDefCheckABIStability(def
, def
, xmlopt
)) {
84 fprintf(stderr
, "ABI stability check failed on %s", xml
);
88 formatted
= virVMXFormatConfig(&ctx
, xmlopt
, def
, virtualHW_version
);
89 if (formatted
== NULL
)
92 if (virTestCompareToFile(formatted
, vmx
) < 0)
99 virDomainDefFree(def
);
107 int virtualHW_version
;
111 testCompareHelper(const void *data
)
114 const struct testInfo
*info
= data
;
118 if (virAsprintf(&xml
, "%s/xml2vmxdata/xml2vmx-%s.xml", abs_srcdir
,
120 virAsprintf(&vmx
, "%s/xml2vmxdata/xml2vmx-%s.vmx", abs_srcdir
,
125 result
= testCompareFiles(xml
, vmx
, info
->virtualHW_version
);
135 testAutodetectSCSIControllerModel(virDomainDiskDefPtr def ATTRIBUTE_UNUSED
,
136 int *model
, void *opaque ATTRIBUTE_UNUSED
)
138 *model
= VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC
;
144 testFormatVMXFileName(const char *src
, void *opaque ATTRIBUTE_UNUSED
)
146 bool success
= false;
147 char *copyOfDatastorePath
= 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)
159 /* Expected format: '[<datastore>] <path>' where <path> is optional */
160 if ((tmp
= STRSKIP(copyOfDatastorePath
, "[")) == NULL
|| *tmp
== ']' ||
161 (datastoreName
= strtok_r(tmp
, "]", &saveptr
)) == NULL
) {
165 directoryAndFileName
= strtok_r(NULL
, "", &saveptr
);
167 if (directoryAndFileName
== NULL
) {
168 directoryAndFileName
= (char *)"";
170 directoryAndFileName
+= strspn(directoryAndFileName
, " ");
173 if (virAsprintf(&absolutePath
, "/vmfs/volumes/%s/%s", datastoreName
,
174 directoryAndFileName
) < 0)
176 } else if (STRPREFIX(src
, "/")) {
177 /* Found absolute path */
178 ignore_value(VIR_STRDUP(absolutePath
, src
));
180 /* Found relative path, this is not supported */
188 VIR_FREE(absolutePath
);
190 VIR_FREE(copyOfDatastorePath
);
200 # define DO_TEST(_in, _out, _version) \
202 struct testInfo info = { _in, _out, _version }; \
203 virResetLastError(); \
204 if (virTestRun("VMware XML-2-VMX "_in" -> "_out, \
205 testCompareHelper, &info) < 0) { \
215 if (!(xmlopt
= virVMXDomainXMLConfInit()))
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
)
317 #endif /* WITH_VMX */