backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / bhyvexml2argvtest.c
blobc84925c57bf2d864d92ebb62720e80f2f3b57254
1 #include <config.h>
3 #include "testutils.h"
5 #ifdef WITH_BHYVE
7 # include "datatypes.h"
9 # include "bhyve/bhyve_capabilities.h"
10 # include "bhyve/bhyve_domain.h"
11 # include "bhyve/bhyve_utils.h"
12 # include "bhyve/bhyve_command.h"
14 # define VIR_FROM_THIS VIR_FROM_BHYVE
16 static bhyveConn driver;
18 typedef enum {
19 FLAG_EXPECT_FAILURE = 1 << 0,
20 FLAG_EXPECT_PARSE_ERROR = 1 << 1,
21 } virBhyveXMLToArgvTestFlags;
23 static int testCompareXMLToArgvFiles(const char *xml,
24 const char *cmdline,
25 const char *ldcmdline,
26 const char *dmcmdline,
27 unsigned int flags)
29 char *actualargv = NULL, *actualld = NULL, *actualdm = NULL;
30 virDomainDefPtr vmdef = NULL;
31 virCommandPtr cmd = NULL, ldcmd = NULL;
32 virConnectPtr conn;
33 int ret = -1;
35 if (!(conn = virGetConnect()))
36 goto out;
38 if (!(vmdef = virDomainDefParseFile(xml, driver.caps, driver.xmlopt,
39 NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) {
40 if (flags & FLAG_EXPECT_PARSE_ERROR) {
41 ret = 0;
42 } else if (flags & FLAG_EXPECT_FAILURE) {
43 ret = 0;
44 VIR_TEST_DEBUG("Got expected error: %s\n",
45 virGetLastErrorMessage());
46 virResetLastError();
49 goto out;
52 conn->privateData = &driver;
54 cmd = virBhyveProcessBuildBhyveCmd(conn, vmdef, false);
55 if (vmdef->os.loader)
56 ldcmd = virCommandNew("dummy");
57 else
58 ldcmd = virBhyveProcessBuildLoadCmd(conn, vmdef, "<device.map>",
59 &actualdm);
61 if ((cmd == NULL) || (ldcmd == NULL)) {
62 if (flags & FLAG_EXPECT_FAILURE) {
63 ret = 0;
64 VIR_TEST_DEBUG("Got expected error: %s\n",
65 virGetLastErrorMessage());
66 virResetLastError();
68 goto out;
71 if (!(actualargv = virCommandToString(cmd, false)))
72 goto out;
74 if (actualdm != NULL)
75 virTrimSpaces(actualdm, NULL);
77 if (!(actualld = virCommandToString(ldcmd, false)))
78 goto out;
80 if (virTestCompareToFile(actualargv, cmdline) < 0)
81 goto out;
83 if (virTestCompareToFile(actualld, ldcmdline) < 0)
84 goto out;
86 if (virFileExists(dmcmdline) || actualdm) {
87 if (virTestCompareToFile(actualdm, dmcmdline) < 0)
88 goto out;
91 ret = 0;
93 out:
94 if (vmdef &&
95 vmdef->ngraphics == 1 &&
96 vmdef->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC)
97 virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port);
99 VIR_FREE(actualargv);
100 VIR_FREE(actualld);
101 VIR_FREE(actualdm);
102 virCommandFree(cmd);
103 virCommandFree(ldcmd);
104 virDomainDefFree(vmdef);
105 virObjectUnref(conn);
106 return ret;
109 struct testInfo {
110 const char *name;
111 unsigned int flags;
114 static int
115 testCompareXMLToArgvHelper(const void *data)
117 int ret = -1;
118 const struct testInfo *info = data;
119 char *xml = NULL;
120 char *args = NULL, *ldargs = NULL, *dmargs = NULL;
122 if (virAsprintf(&xml, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.xml",
123 abs_srcdir, info->name) < 0 ||
124 virAsprintf(&args, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.args",
125 abs_srcdir, info->name) < 0 ||
126 virAsprintf(&ldargs, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.ldargs",
127 abs_srcdir, info->name) < 0 ||
128 virAsprintf(&dmargs, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.devmap",
129 abs_srcdir, info->name) < 0)
130 goto cleanup;
132 ret = testCompareXMLToArgvFiles(xml, args, ldargs, dmargs, info->flags);
134 cleanup:
135 VIR_FREE(xml);
136 VIR_FREE(args);
137 VIR_FREE(ldargs);
138 VIR_FREE(dmargs);
139 return ret;
142 static int
143 mymain(void)
145 int ret = 0;
147 if ((driver.caps = virBhyveCapsBuild()) == NULL)
148 return EXIT_FAILURE;
150 if ((driver.xmlopt = virBhyveDriverCreateXMLConf(&driver)) == NULL)
151 return EXIT_FAILURE;
153 if (!(driver.remotePorts = virPortAllocatorRangeNew("display", 5900, 65535)))
154 return EXIT_FAILURE;
157 # define DO_TEST_FULL(name, flags) \
158 do { \
159 static struct testInfo info = { \
160 name, (flags) \
161 }; \
162 if (virTestRun("BHYVE XML-2-ARGV " name, \
163 testCompareXMLToArgvHelper, &info) < 0) \
164 ret = -1; \
165 } while (0)
167 # define DO_TEST(name) \
168 DO_TEST_FULL(name, 0)
170 # define DO_TEST_FAILURE(name) \
171 DO_TEST_FULL(name, FLAG_EXPECT_FAILURE)
173 # define DO_TEST_PARSE_ERROR(name) \
174 DO_TEST_FULL(name, FLAG_EXPECT_PARSE_ERROR)
176 driver.grubcaps = BHYVE_GRUB_CAP_CONSDEV;
177 driver.bhyvecaps = BHYVE_CAP_RTC_UTC | BHYVE_CAP_AHCI32SLOT | \
178 BHYVE_CAP_NET_E1000 | BHYVE_CAP_LPC_BOOTROM | \
179 BHYVE_CAP_FBUF | BHYVE_CAP_XHCI | \
180 BHYVE_CAP_CPUTOPOLOGY;
182 DO_TEST("base");
183 DO_TEST("wired");
184 DO_TEST("acpiapic");
185 DO_TEST("disk-cdrom");
186 DO_TEST("disk-virtio");
187 DO_TEST("macaddr");
188 DO_TEST("serial");
189 DO_TEST("console");
190 DO_TEST("grub-defaults");
191 DO_TEST("grub-bootorder");
192 DO_TEST("grub-bootorder2");
193 DO_TEST("bhyveload-bootorder");
194 DO_TEST("bhyveload-bootorder1");
195 DO_TEST_FAILURE("bhyveload-bootorder2");
196 DO_TEST("bhyveload-bootorder3");
197 DO_TEST("bhyveload-explicitargs");
198 DO_TEST_FAILURE("bhyveload-bootorder4");
199 DO_TEST_PARSE_ERROR("bhyveload-bootorder5");
200 DO_TEST("custom-loader");
201 DO_TEST("disk-cdrom-grub");
202 DO_TEST("serial-grub");
203 DO_TEST("localtime");
204 DO_TEST("net-e1000");
205 DO_TEST("uefi");
206 DO_TEST("vnc");
207 DO_TEST("vnc-vgaconf-on");
208 DO_TEST("vnc-vgaconf-off");
209 DO_TEST("vnc-vgaconf-io");
210 DO_TEST("vnc-autoport");
211 DO_TEST("cputopology");
212 DO_TEST_FAILURE("cputopology-nvcpu-mismatch");
213 DO_TEST("commandline");
214 DO_TEST("msrs");
216 /* Address allocation tests */
217 DO_TEST("addr-single-sata-disk");
218 DO_TEST("addr-multiple-sata-disks");
219 DO_TEST("addr-more-than-32-sata-disks");
220 DO_TEST("addr-single-virtio-disk");
221 DO_TEST("addr-multiple-virtio-disks");
223 /* The same without 32 devs per controller support */
224 driver.bhyvecaps ^= BHYVE_CAP_AHCI32SLOT;
225 DO_TEST("addr-no32devs-single-sata-disk");
226 DO_TEST("addr-no32devs-multiple-sata-disks");
227 DO_TEST_FAILURE("addr-no32devs-more-than-32-sata-disks");
229 /* USB xhci tablet */
230 DO_TEST("input-xhci-tablet");
231 DO_TEST_FAILURE("xhci-multiple-controllers");
232 DO_TEST_FAILURE("xhci-no-devs");
233 DO_TEST_FAILURE("xhci-multiple-devs");
234 driver.bhyvecaps ^= BHYVE_CAP_XHCI;
235 DO_TEST_FAILURE("input-xhci-tablet");
237 driver.grubcaps = 0;
239 DO_TEST("serial-grub-nocons");
241 driver.bhyvecaps &= ~BHYVE_CAP_NET_E1000;
243 DO_TEST_FAILURE("net-e1000");
245 driver.bhyvecaps &= ~BHYVE_CAP_LPC_BOOTROM;
246 DO_TEST_FAILURE("uefi");
248 driver.bhyvecaps &= ~BHYVE_CAP_FBUF;
249 DO_TEST_FAILURE("vnc");
251 driver.bhyvecaps &= ~BHYVE_CAP_CPUTOPOLOGY;
252 DO_TEST_FAILURE("cputopology");
254 virObjectUnref(driver.caps);
255 virObjectUnref(driver.xmlopt);
256 virPortAllocatorRangeFree(driver.remotePorts);
258 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
261 VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/bhyvexml2argvmock.so")
263 #else
265 int main(void)
267 return EXIT_AM_SKIP;
270 #endif /* WITH_BHYVE */