remote: add sysusers file to create 'libvirt' group
[libvirt.git] / tests / xml2vmxtest.c
blob1cadb9500a7ec3e932b8e5230c1c645ddca3fded
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"
13 # define VIR_FROM_THIS VIR_FROM_VMWARE
15 static virCaps *caps;
16 static virVMXContext ctx;
17 static virDomainXMLOption *xmlopt;
20 static void
21 testCapsInit(void)
23 virCapsGuest *guest = NULL;
25 caps = virCapabilitiesNew(VIR_ARCH_I686, true, true);
27 if (caps == NULL)
28 return;
30 virCapabilitiesAddHostMigrateTransport(caps, "esx");
33 /* i686 guest */
34 guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
35 VIR_ARCH_I686,
36 NULL, NULL, 0, NULL);
38 virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE,
39 NULL, NULL, 0, NULL);
41 /* x86_64 guest */
42 guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
43 VIR_ARCH_X86_64,
44 NULL, NULL, 0, NULL);
46 virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE,
47 NULL, NULL, 0, NULL);
50 static int
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);
59 if (def == NULL)
60 return -1;
62 if (!virDomainDefCheckABIStability(def, def, xmlopt)) {
63 fprintf(stderr, "ABI stability check failed on %s", xml);
64 return -1;
67 formatted = virVMXFormatConfig(&ctx, xmlopt, def, virtualHW_version);
68 if (formatted == NULL)
69 return -1;
71 if (virTestCompareToFile(formatted, vmx) < 0)
72 return -1;
74 return 0;
77 struct testInfo {
78 const char *input;
79 const char *output;
80 int virtualHW_version;
83 static int
84 testCompareHelper(const void *data)
86 int result = -1;
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,
92 info->input);
93 vmx = g_strdup_printf("%s/xml2vmxdata/xml2vmx-%s.vmx", abs_srcdir,
94 info->output);
96 result = testCompareFiles(xml, vmx, info->virtualHW_version);
98 return result;
101 static int
102 testAutodetectSCSIControllerModel(virDomainDiskDef *def G_GNUC_UNUSED,
103 int *model, void *opaque G_GNUC_UNUSED)
105 *model = VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC;
107 return 0;
110 static char *
111 testFormatVMXFileName(const char *src, void *opaque G_GNUC_UNUSED)
113 bool success = false;
114 g_autofree char *copyOfDatastorePath = NULL;
115 char *tmp = 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) {
128 goto cleanup;
131 directoryAndFileName = strtok_r(NULL, "", &saveptr);
133 if (directoryAndFileName == NULL) {
134 directoryAndFileName = (char *)"";
135 } else {
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);
144 } else {
145 /* Found relative path, this is not supported */
146 goto cleanup;
149 success = true;
151 cleanup:
152 if (! success)
153 VIR_FREE(absolutePath);
155 return absolutePath;
158 static int
159 mymain(void)
161 int result = 0;
163 # define DO_TEST(_in, _out, _version) \
164 do { \
165 struct testInfo info = { _in, _out, _version }; \
166 virResetLastError(); \
167 if (virTestRun("VMware XML-2-VMX "_in" -> "_out, \
168 testCompareHelper, &info) < 0) { \
169 result = -1; \
171 } while (0)
173 testCapsInit();
175 if (caps == NULL)
176 return EXIT_FAILURE;
178 if (!(xmlopt = virVMXDomainXMLConfInit(caps)))
179 return EXIT_FAILURE;
181 ctx.opaque = NULL;
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)
277 #else
279 int main(void)
281 return EXIT_AM_SKIP;
284 #endif /* WITH_VMX */