10 # include "viralloc.h"
13 # define VIR_FROM_THIS VIR_FROM_VMWARE
16 static virVMXContext ctx
;
17 static virDomainXMLOption
*xmlopt
;
23 virCapsGuest
*guest
= NULL
;
25 caps
= virCapabilitiesNew(VIR_ARCH_I686
, true, true);
30 virCapabilitiesAddHostMigrateTransport(caps
, "esx");
34 guest
= virCapabilitiesAddGuest(caps
, VIR_DOMAIN_OSTYPE_HVM
,
38 virCapabilitiesAddGuestDomain(guest
, VIR_DOMAIN_VIRT_VMWARE
,
42 guest
= virCapabilitiesAddGuest(caps
, VIR_DOMAIN_OSTYPE_HVM
,
46 virCapabilitiesAddGuestDomain(guest
, VIR_DOMAIN_VIRT_VMWARE
,
51 testCompareFiles(const char *xml
, const char *vmx
, int virtualHW_version
)
53 g_autofree
char *formatted
= NULL
;
54 g_autoptr(virDomainDef
) def
= NULL
;
56 def
= virDomainDefParseFile(xml
, xmlopt
, NULL
,
57 VIR_DOMAIN_DEF_PARSE_INACTIVE
);
62 if (!virDomainDefCheckABIStability(def
, def
, xmlopt
)) {
63 fprintf(stderr
, "ABI stability check failed on %s", xml
);
67 formatted
= virVMXFormatConfig(&ctx
, xmlopt
, def
, virtualHW_version
);
68 if (formatted
== NULL
)
71 if (virTestCompareToFile(formatted
, vmx
) < 0)
80 int virtualHW_version
;
84 testCompareHelper(const void *data
)
87 const struct testInfo
*info
= data
;
88 g_autofree
char *xml
= NULL
;
89 g_autofree
char *vmx
= NULL
;
91 xml
= g_strdup_printf("%s/xml2vmxdata/xml2vmx-%s.xml", abs_srcdir
,
93 vmx
= g_strdup_printf("%s/xml2vmxdata/xml2vmx-%s.vmx", abs_srcdir
,
96 result
= testCompareFiles(xml
, vmx
, info
->virtualHW_version
);
102 testAutodetectSCSIControllerModel(virDomainDiskDef
*def G_GNUC_UNUSED
,
103 int *model
, void *opaque G_GNUC_UNUSED
)
105 *model
= VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC
;
111 testFormatVMXFileName(const char *src
, void *opaque G_GNUC_UNUSED
)
113 bool success
= false;
114 g_autofree
char *copyOfDatastorePath
= NULL
;
116 char *saveptr
= NULL
;
117 char *datastoreName
= NULL
;
118 char *directoryAndFileName
= NULL
;
119 char *absolutePath
= NULL
;
121 if (STRPREFIX(src
, "[")) {
122 /* Found potential datastore path */
123 copyOfDatastorePath
= g_strdup(src
);
125 /* Expected format: '[<datastore>] <path>' where <path> is optional */
126 if ((tmp
= STRSKIP(copyOfDatastorePath
, "[")) == NULL
|| *tmp
== ']' ||
127 (datastoreName
= strtok_r(tmp
, "]", &saveptr
)) == NULL
) {
131 directoryAndFileName
= strtok_r(NULL
, "", &saveptr
);
133 if (directoryAndFileName
== NULL
) {
134 directoryAndFileName
= (char *)"";
136 directoryAndFileName
+= strspn(directoryAndFileName
, " ");
139 absolutePath
= g_strdup_printf("/vmfs/volumes/%s/%s", datastoreName
,
140 directoryAndFileName
);
141 } else if (STRPREFIX(src
, "/")) {
142 /* Found absolute path */
143 absolutePath
= g_strdup(src
);
145 /* Found relative path, this is not supported */
153 VIR_FREE(absolutePath
);
163 # define DO_TEST(_in, _out, _version) \
165 struct testInfo info = { _in, _out, _version }; \
166 virResetLastError(); \
167 if (virTestRun("VMware XML-2-VMX "_in" -> "_out, \
168 testCompareHelper, &info) < 0) { \
178 if (!(xmlopt
= virVMXDomainXMLConfInit(caps
)))
182 ctx
.parseFileName
= NULL
;
183 ctx
.formatFileName
= testFormatVMXFileName
;
184 ctx
.autodetectSCSIControllerModel
= testAutodetectSCSIControllerModel
;
185 ctx
.datacenterPath
= NULL
;
187 DO_TEST("minimal", "minimal", 4);
188 DO_TEST("minimal-64bit", "minimal-64bit", 4);
190 DO_TEST("graphics-vnc", "graphics-vnc", 4);
192 DO_TEST("scsi-driver", "scsi-driver", 4);
193 DO_TEST("scsi-writethrough", "scsi-writethrough", 4);
195 DO_TEST("harddisk-scsi-file", "harddisk-scsi-file", 4);
196 DO_TEST("harddisk-ide-file", "harddisk-ide-file", 4);
198 DO_TEST("cdrom-scsi-file", "cdrom-scsi-file", 4);
199 DO_TEST("cdrom-scsi-empty", "cdrom-scsi-empty", 4);
200 DO_TEST("cdrom-scsi-device", "cdrom-scsi-device", 4);
201 DO_TEST("cdrom-scsi-raw-device", "cdrom-scsi-raw-device", 4);
202 DO_TEST("cdrom-scsi-raw-auto-detect", "cdrom-scsi-raw-auto-detect", 4);
203 DO_TEST("cdrom-scsi-passthru", "cdrom-scsi-passthru", 4);
204 DO_TEST("cdrom-ide-file", "cdrom-ide-file", 4);
205 DO_TEST("cdrom-ide-empty", "cdrom-ide-empty", 4);
206 DO_TEST("cdrom-ide-device", "cdrom-ide-device", 4);
207 DO_TEST("cdrom-ide-raw-device", "cdrom-ide-raw-device", 4);
208 DO_TEST("cdrom-ide-raw-auto-detect", "cdrom-ide-raw-auto-detect", 4);
210 DO_TEST("floppy-file", "floppy-file", 4);
211 DO_TEST("floppy-device", "floppy-device", 4);
213 DO_TEST("sharedfolder", "sharedfolder", 4);
215 DO_TEST("ethernet-e1000", "ethernet-e1000", 4);
216 DO_TEST("ethernet-vmxnet2", "ethernet-vmxnet2", 4);
218 DO_TEST("ethernet-custom", "ethernet-custom", 4);
219 DO_TEST("ethernet-bridged", "ethernet-bridged", 4);
220 DO_TEST("ethernet-nat", "ethernet-nat", 4);
222 DO_TEST("ethernet-generated", "ethernet-generated", 4);
223 DO_TEST("ethernet-static", "ethernet-static", 4);
224 DO_TEST("ethernet-vpx", "ethernet-vpx", 4);
225 DO_TEST("ethernet-other", "ethernet-other", 4);
226 DO_TEST("ethernet-mac-type", "ethernet-mac-type", 4);
228 DO_TEST("ethernet-null", "ethernet-null", 4);
229 DO_TEST("ethernet-vds", "ethernet-vds", 4);
231 DO_TEST("serial-file", "serial-file", 4);
232 DO_TEST("serial-device", "serial-device", 4);
233 DO_TEST("serial-pipe", "serial-pipe", 4);
234 DO_TEST("serial-network-server", "serial-network-server", 7);
235 DO_TEST("serial-network-client", "serial-network-client", 7);
237 DO_TEST("parallel-file", "parallel-file", 4);
238 DO_TEST("parallel-device", "parallel-device", 4);
240 DO_TEST("esx-in-the-wild-1", "esx-in-the-wild-1", 4);
241 DO_TEST("esx-in-the-wild-2", "esx-in-the-wild-2", 4);
242 DO_TEST("esx-in-the-wild-3", "esx-in-the-wild-3", 4);
243 DO_TEST("esx-in-the-wild-4", "esx-in-the-wild-4", 4);
244 DO_TEST("esx-in-the-wild-5", "esx-in-the-wild-5", 4);
245 DO_TEST("esx-in-the-wild-6", "esx-in-the-wild-6", 4);
246 DO_TEST("esx-in-the-wild-7", "esx-in-the-wild-7", 4);
247 DO_TEST("esx-in-the-wild-9", "esx-in-the-wild-9", 10);
249 DO_TEST("gsx-in-the-wild-1", "gsx-in-the-wild-1", 4);
250 DO_TEST("gsx-in-the-wild-2", "gsx-in-the-wild-2", 4);
251 DO_TEST("gsx-in-the-wild-3", "gsx-in-the-wild-3", 4);
252 DO_TEST("gsx-in-the-wild-4", "gsx-in-the-wild-4", 4);
254 DO_TEST("ws-in-the-wild-1", "ws-in-the-wild-1", 8);
255 DO_TEST("ws-in-the-wild-2", "ws-in-the-wild-2", 8);
257 DO_TEST("fusion-in-the-wild-1", "fusion-in-the-wild-1", 9);
259 DO_TEST("annotation", "annotation", 4);
261 DO_TEST("smbios", "smbios", 4);
263 DO_TEST("svga", "svga", 4);
265 DO_TEST("firmware-efi", "firmware-efi", 4);
267 DO_TEST("datacenterpath", "datacenterpath", 4);
269 virObjectUnref(caps
);
270 virObjectUnref(xmlopt
);
272 return result
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
275 VIR_TEST_MAIN(mymain
)
284 #endif /* WITH_VMX */