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
;
19 FLAG_EXPECT_FAILURE
= 1 << 0,
20 FLAG_EXPECT_PARSE_ERROR
= 1 << 1,
21 } virBhyveXMLToArgvTestFlags
;
23 static int testCompareXMLToArgvFiles(const char *xml
,
25 const char *ldcmdline
,
26 const char *dmcmdline
,
29 char *actualargv
= NULL
, *actualld
= NULL
, *actualdm
= NULL
;
30 virDomainDefPtr vmdef
= NULL
;
31 virCommandPtr cmd
= NULL
, ldcmd
= NULL
;
35 if (!(conn
= virGetConnect()))
38 if (!(vmdef
= virDomainDefParseFile(xml
, driver
.caps
, driver
.xmlopt
,
39 NULL
, VIR_DOMAIN_DEF_PARSE_INACTIVE
))) {
40 if (flags
& FLAG_EXPECT_PARSE_ERROR
) {
42 } else if (flags
& FLAG_EXPECT_FAILURE
) {
44 VIR_TEST_DEBUG("Got expected error: %s\n",
45 virGetLastErrorMessage());
52 conn
->privateData
= &driver
;
54 cmd
= virBhyveProcessBuildBhyveCmd(conn
, vmdef
, false);
56 ldcmd
= virCommandNew("dummy");
58 ldcmd
= virBhyveProcessBuildLoadCmd(conn
, vmdef
, "<device.map>",
61 if ((cmd
== NULL
) || (ldcmd
== NULL
)) {
62 if (flags
& FLAG_EXPECT_FAILURE
) {
64 VIR_TEST_DEBUG("Got expected error: %s\n",
65 virGetLastErrorMessage());
71 if (!(actualargv
= virCommandToString(cmd
, false)))
75 virTrimSpaces(actualdm
, NULL
);
77 if (!(actualld
= virCommandToString(ldcmd
, false)))
80 if (virTestCompareToFile(actualargv
, cmdline
) < 0)
83 if (virTestCompareToFile(actualld
, ldcmdline
) < 0)
86 if (virFileExists(dmcmdline
) || actualdm
) {
87 if (virTestCompareToFile(actualdm
, dmcmdline
) < 0)
95 vmdef
->ngraphics
== 1 &&
96 vmdef
->graphics
[0]->type
== VIR_DOMAIN_GRAPHICS_TYPE_VNC
)
97 virPortAllocatorRelease(vmdef
->graphics
[0]->data
.vnc
.port
);
103 virCommandFree(ldcmd
);
104 virDomainDefFree(vmdef
);
105 virObjectUnref(conn
);
115 testCompareXMLToArgvHelper(const void *data
)
118 const struct testInfo
*info
= data
;
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)
132 ret
= testCompareXMLToArgvFiles(xml
, args
, ldargs
, dmargs
, info
->flags
);
147 if ((driver
.caps
= virBhyveCapsBuild()) == NULL
)
150 if ((driver
.xmlopt
= virBhyveDriverCreateXMLConf(&driver
)) == NULL
)
153 if (!(driver
.remotePorts
= virPortAllocatorRangeNew("display", 5900, 65535)))
157 # define DO_TEST_FULL(name, flags) \
159 static struct testInfo info = { \
162 if (virTestRun("BHYVE XML-2-ARGV " name, \
163 testCompareXMLToArgvHelper, &info) < 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
;
185 DO_TEST("disk-cdrom");
186 DO_TEST("disk-virtio");
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");
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");
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");
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")
270 #endif /* WITH_BHYVE */