2014-03-26 16:53:49 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "testutils.h"
|
|
|
|
|
|
|
|
#ifdef WITH_BHYVE
|
|
|
|
|
|
|
|
# include "datatypes.h"
|
|
|
|
|
2014-04-08 17:18:00 +00:00
|
|
|
# include "bhyve/bhyve_capabilities.h"
|
2021-02-22 09:46:13 +00:00
|
|
|
# include "bhyve/bhyve_conf.h"
|
2017-01-05 12:31:35 +00:00
|
|
|
# include "bhyve/bhyve_domain.h"
|
2014-03-26 16:53:49 +00:00
|
|
|
# include "bhyve/bhyve_utils.h"
|
|
|
|
# include "bhyve/bhyve_command.h"
|
2021-02-22 09:46:13 +00:00
|
|
|
# include "bhyve/bhyve_process.h"
|
2014-03-26 16:53:49 +00:00
|
|
|
|
|
|
|
# define VIR_FROM_THIS VIR_FROM_BHYVE
|
|
|
|
|
|
|
|
static bhyveConn driver;
|
|
|
|
|
2015-12-13 03:17:15 +00:00
|
|
|
typedef enum {
|
2021-02-22 09:46:13 +00:00
|
|
|
FLAG_EXPECT_FAILURE = 1 << 0,
|
|
|
|
FLAG_EXPECT_PARSE_ERROR = 1 << 1,
|
|
|
|
FLAG_EXPECT_PREPARE_ERROR = 1 << 2,
|
2015-12-13 03:17:15 +00:00
|
|
|
} virBhyveXMLToArgvTestFlags;
|
|
|
|
|
2014-03-26 16:53:49 +00:00
|
|
|
static int testCompareXMLToArgvFiles(const char *xml,
|
2014-11-08 16:48:31 +00:00
|
|
|
const char *cmdline,
|
|
|
|
const char *ldcmdline,
|
2015-12-13 03:17:15 +00:00
|
|
|
const char *dmcmdline,
|
|
|
|
unsigned int flags)
|
2014-03-26 16:53:49 +00:00
|
|
|
{
|
2020-07-28 00:56:33 +00:00
|
|
|
g_autofree char *actualargv = NULL;
|
|
|
|
g_autofree char *actualld = NULL;
|
|
|
|
g_autofree char *actualdm = NULL;
|
2021-02-22 09:46:13 +00:00
|
|
|
g_autoptr(virDomainObj) vm = NULL;
|
2020-07-28 00:59:58 +00:00
|
|
|
g_autoptr(virCommand) cmd = NULL;
|
|
|
|
g_autoptr(virCommand) ldcmd = NULL;
|
|
|
|
g_autoptr(virConnect) conn = NULL;
|
2014-03-26 16:53:49 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
2014-08-14 16:15:57 +00:00
|
|
|
if (!(conn = virGetConnect()))
|
|
|
|
goto out;
|
2014-03-26 16:53:49 +00:00
|
|
|
|
2021-02-22 09:46:13 +00:00
|
|
|
if (!(vm = virDomainObjNew(driver.xmlopt)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!(vm->def = virDomainDefParseFile(xml, driver.xmlopt,
|
|
|
|
NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) {
|
2017-01-05 14:38:20 +00:00
|
|
|
if (flags & FLAG_EXPECT_PARSE_ERROR) {
|
2015-12-13 03:17:15 +00:00
|
|
|
ret = 0;
|
2017-01-05 14:38:20 +00:00
|
|
|
} else if (flags & FLAG_EXPECT_FAILURE) {
|
|
|
|
ret = 0;
|
2019-05-03 08:31:02 +00:00
|
|
|
VIR_TEST_DEBUG("Got expected error: %s",
|
2017-01-05 14:38:20 +00:00
|
|
|
virGetLastErrorMessage());
|
|
|
|
virResetLastError();
|
|
|
|
}
|
|
|
|
|
2014-03-26 16:53:49 +00:00
|
|
|
goto out;
|
2015-12-13 03:17:15 +00:00
|
|
|
}
|
2014-03-26 16:53:49 +00:00
|
|
|
|
2014-11-08 16:48:36 +00:00
|
|
|
conn->privateData = &driver;
|
2014-03-26 16:53:49 +00:00
|
|
|
|
2021-02-22 09:46:13 +00:00
|
|
|
if (bhyveProcessPrepareDomain(&driver, vm, 0) < 0) {
|
|
|
|
if (flags & FLAG_EXPECT_PREPARE_ERROR) {
|
|
|
|
ret = 0;
|
|
|
|
VIR_TEST_DEBUG("Got expected error: %s",
|
|
|
|
virGetLastErrorMessage());
|
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd = virBhyveProcessBuildBhyveCmd(&driver, vm->def, false);
|
|
|
|
if (vm->def->os.loader)
|
2016-06-30 03:00:04 +00:00
|
|
|
ldcmd = virCommandNew("dummy");
|
|
|
|
else
|
2021-02-22 09:46:13 +00:00
|
|
|
ldcmd = virBhyveProcessBuildLoadCmd(&driver, vm->def, "<device.map>",
|
2016-06-30 03:00:04 +00:00
|
|
|
&actualdm);
|
2015-12-13 03:17:15 +00:00
|
|
|
|
|
|
|
if ((cmd == NULL) || (ldcmd == NULL)) {
|
|
|
|
if (flags & FLAG_EXPECT_FAILURE) {
|
|
|
|
ret = 0;
|
2019-05-03 08:31:02 +00:00
|
|
|
VIR_TEST_DEBUG("Got expected error: %s",
|
2015-12-13 03:17:15 +00:00
|
|
|
virGetLastErrorMessage());
|
|
|
|
virResetLastError();
|
|
|
|
}
|
2014-03-26 16:53:49 +00:00
|
|
|
goto out;
|
2015-12-13 03:17:15 +00:00
|
|
|
}
|
2014-03-26 16:53:49 +00:00
|
|
|
|
2021-04-16 18:32:34 +00:00
|
|
|
if (!(actualargv = virCommandToStringFull(cmd, true, true)))
|
2014-03-26 16:53:49 +00:00
|
|
|
goto out;
|
|
|
|
|
2014-11-08 16:48:31 +00:00
|
|
|
if (actualdm != NULL)
|
|
|
|
virTrimSpaces(actualdm, NULL);
|
|
|
|
|
2021-04-16 18:32:34 +00:00
|
|
|
if (!(actualld = virCommandToStringFull(ldcmd, true, true)))
|
2014-11-08 16:48:31 +00:00
|
|
|
goto out;
|
|
|
|
|
2021-03-31 08:46:36 +00:00
|
|
|
if (virTestCompareToFileFull(actualargv, cmdline, false) < 0)
|
2014-03-26 16:53:49 +00:00
|
|
|
goto out;
|
|
|
|
|
2021-03-31 08:46:36 +00:00
|
|
|
if (virTestCompareToFileFull(actualld, ldcmdline, false) < 0)
|
2014-11-08 16:48:31 +00:00
|
|
|
goto out;
|
|
|
|
|
2015-04-23 15:14:26 +00:00
|
|
|
if (virFileExists(dmcmdline) || actualdm) {
|
2016-05-26 15:01:53 +00:00
|
|
|
if (virTestCompareToFile(actualdm, dmcmdline) < 0)
|
2015-04-23 15:14:26 +00:00
|
|
|
goto out;
|
2014-11-08 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
2014-03-26 16:53:49 +00:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
out:
|
2021-02-22 09:46:13 +00:00
|
|
|
if (vm && vm->def &&
|
|
|
|
vm->def->ngraphics == 1 &&
|
|
|
|
vm->def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC)
|
|
|
|
virPortAllocatorRelease(vm->def->graphics[0]->data.vnc.port);
|
2018-02-06 09:09:06 +00:00
|
|
|
|
2014-03-26 16:53:49 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-12-13 03:17:15 +00:00
|
|
|
struct testInfo {
|
|
|
|
const char *name;
|
|
|
|
unsigned int flags;
|
|
|
|
};
|
|
|
|
|
2014-03-26 16:53:49 +00:00
|
|
|
static int
|
|
|
|
testCompareXMLToArgvHelper(const void *data)
|
|
|
|
{
|
2015-12-13 03:17:15 +00:00
|
|
|
const struct testInfo *info = data;
|
2020-07-28 00:56:33 +00:00
|
|
|
g_autofree char *xml = NULL;
|
|
|
|
g_autofree char *args = NULL;
|
|
|
|
g_autofree char *ldargs = NULL;
|
|
|
|
g_autofree char *dmargs = NULL;
|
2014-03-26 16:53:49 +00:00
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
xml = g_strdup_printf("%s/bhyvexml2argvdata/bhyvexml2argv-%s.xml",
|
|
|
|
abs_srcdir, info->name);
|
|
|
|
args = g_strdup_printf("%s/bhyvexml2argvdata/bhyvexml2argv-%s.args",
|
|
|
|
abs_srcdir, info->name);
|
|
|
|
ldargs = g_strdup_printf("%s/bhyvexml2argvdata/bhyvexml2argv-%s.ldargs",
|
|
|
|
abs_srcdir, info->name);
|
|
|
|
dmargs = g_strdup_printf("%s/bhyvexml2argvdata/bhyvexml2argv-%s.devmap",
|
|
|
|
abs_srcdir, info->name);
|
2014-03-26 16:53:49 +00:00
|
|
|
|
2020-07-28 00:58:58 +00:00
|
|
|
return testCompareXMLToArgvFiles(xml, args, ldargs, dmargs, info->flags);
|
2014-03-26 16:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2021-02-22 09:46:13 +00:00
|
|
|
g_autofree char *fakefirmwaredir = g_strdup("fakefirmwaredir");
|
|
|
|
g_autofree char *fakefirmwareemptydir = g_strdup("fakefirmwareemptydir");
|
2014-03-26 16:53:49 +00:00
|
|
|
|
2014-04-08 17:18:00 +00:00
|
|
|
if ((driver.caps = virBhyveCapsBuild()) == NULL)
|
2014-03-26 16:53:49 +00:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2017-01-05 12:31:35 +00:00
|
|
|
if ((driver.xmlopt = virBhyveDriverCreateXMLConf(&driver)) == NULL)
|
2014-03-26 16:53:49 +00:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2018-02-06 09:09:09 +00:00
|
|
|
if (!(driver.remotePorts = virPortAllocatorRangeNew("display", 5900, 65535)))
|
2017-05-08 10:36:43 +00:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2021-02-22 09:46:13 +00:00
|
|
|
if (!(driver.config = virBhyveDriverConfigNew()))
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
driver.config->firmwareDir = fakefirmwaredir;
|
2017-05-08 10:36:43 +00:00
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define DO_TEST_FULL(name, flags) \
|
|
|
|
do { \
|
|
|
|
static struct testInfo info = { \
|
|
|
|
name, (flags) \
|
|
|
|
}; \
|
|
|
|
if (virTestRun("BHYVE XML-2-ARGV " name, \
|
2015-12-13 03:17:15 +00:00
|
|
|
testCompareXMLToArgvHelper, &info) < 0) \
|
2017-11-03 12:09:47 +00:00
|
|
|
ret = -1; \
|
2014-03-26 16:53:49 +00:00
|
|
|
} while (0)
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define DO_TEST(name) \
|
2015-12-13 03:17:15 +00:00
|
|
|
DO_TEST_FULL(name, 0)
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define DO_TEST_FAILURE(name) \
|
2015-12-13 03:17:15 +00:00
|
|
|
DO_TEST_FULL(name, FLAG_EXPECT_FAILURE)
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define DO_TEST_PARSE_ERROR(name) \
|
2015-12-13 03:17:15 +00:00
|
|
|
DO_TEST_FULL(name, FLAG_EXPECT_PARSE_ERROR)
|
|
|
|
|
2021-02-22 09:46:13 +00:00
|
|
|
# define DO_TEST_PREPARE_ERROR(name) \
|
|
|
|
DO_TEST_FULL(name, FLAG_EXPECT_PREPARE_ERROR)
|
|
|
|
|
2014-11-08 16:48:36 +00:00
|
|
|
driver.grubcaps = BHYVE_GRUB_CAP_CONSDEV;
|
2016-06-30 03:00:04 +00:00
|
|
|
driver.bhyvecaps = BHYVE_CAP_RTC_UTC | BHYVE_CAP_AHCI32SLOT | \
|
2017-02-12 14:06:23 +00:00
|
|
|
BHYVE_CAP_NET_E1000 | BHYVE_CAP_LPC_BOOTROM | \
|
2018-05-21 14:53:36 +00:00
|
|
|
BHYVE_CAP_FBUF | BHYVE_CAP_XHCI | \
|
2020-05-06 13:35:55 +00:00
|
|
|
BHYVE_CAP_CPUTOPOLOGY | BHYVE_CAP_SOUND_HDA | \
|
2020-10-07 16:07:04 +00:00
|
|
|
BHYVE_CAP_VNC_PASSWORD | BHYVE_CAP_VIRTIO_9P;
|
2014-03-26 16:53:49 +00:00
|
|
|
|
|
|
|
DO_TEST("base");
|
2018-05-09 01:01:36 +00:00
|
|
|
DO_TEST("wired");
|
2014-03-26 16:53:49 +00:00
|
|
|
DO_TEST("acpiapic");
|
2014-07-19 15:15:26 +00:00
|
|
|
DO_TEST("disk-cdrom");
|
2014-03-26 16:53:49 +00:00
|
|
|
DO_TEST("disk-virtio");
|
|
|
|
DO_TEST("macaddr");
|
2014-03-30 11:54:52 +00:00
|
|
|
DO_TEST("serial");
|
|
|
|
DO_TEST("console");
|
2021-02-07 03:57:07 +00:00
|
|
|
DO_TEST("console-master-slave-not-specified");
|
2014-11-08 16:48:33 +00:00
|
|
|
DO_TEST("grub-defaults");
|
2014-11-12 22:31:53 +00:00
|
|
|
DO_TEST("grub-bootorder");
|
|
|
|
DO_TEST("grub-bootorder2");
|
2015-12-13 03:17:15 +00:00
|
|
|
DO_TEST("bhyveload-bootorder");
|
|
|
|
DO_TEST("bhyveload-bootorder1");
|
|
|
|
DO_TEST_FAILURE("bhyveload-bootorder2");
|
|
|
|
DO_TEST("bhyveload-bootorder3");
|
2014-11-08 16:48:33 +00:00
|
|
|
DO_TEST("bhyveload-explicitargs");
|
2015-12-13 03:17:15 +00:00
|
|
|
DO_TEST_FAILURE("bhyveload-bootorder4");
|
|
|
|
DO_TEST_PARSE_ERROR("bhyveload-bootorder5");
|
2014-11-08 16:48:33 +00:00
|
|
|
DO_TEST("custom-loader");
|
|
|
|
DO_TEST("disk-cdrom-grub");
|
2014-11-08 16:48:36 +00:00
|
|
|
DO_TEST("serial-grub");
|
2015-07-19 08:20:35 +00:00
|
|
|
DO_TEST("localtime");
|
2016-08-27 12:30:34 +00:00
|
|
|
DO_TEST("net-e1000");
|
2016-06-30 03:00:04 +00:00
|
|
|
DO_TEST("uefi");
|
2017-02-12 14:06:23 +00:00
|
|
|
DO_TEST("vnc");
|
2017-05-09 10:48:30 +00:00
|
|
|
DO_TEST("vnc-vgaconf-on");
|
|
|
|
DO_TEST("vnc-vgaconf-off");
|
|
|
|
DO_TEST("vnc-vgaconf-io");
|
2017-05-08 10:36:43 +00:00
|
|
|
DO_TEST("vnc-autoport");
|
2020-05-06 13:35:53 +00:00
|
|
|
DO_TEST("vnc-resolution");
|
2020-05-06 13:35:55 +00:00
|
|
|
DO_TEST("vnc-password");
|
|
|
|
DO_TEST_FAILURE("vnc-password-comma");
|
2018-05-21 14:53:36 +00:00
|
|
|
DO_TEST("cputopology");
|
|
|
|
DO_TEST_FAILURE("cputopology-nvcpu-mismatch");
|
2019-01-17 15:07:20 +00:00
|
|
|
DO_TEST("commandline");
|
2019-01-25 15:27:58 +00:00
|
|
|
DO_TEST("msrs");
|
2020-07-14 14:44:13 +00:00
|
|
|
DO_TEST("sound");
|
2019-02-17 13:04:00 +00:00
|
|
|
DO_TEST("isa-controller");
|
|
|
|
DO_TEST_FAILURE("isa-multiple-controllers");
|
2021-02-22 09:46:13 +00:00
|
|
|
DO_TEST("firmware-efi");
|
|
|
|
driver.config->firmwareDir = fakefirmwareemptydir;
|
|
|
|
DO_TEST_PREPARE_ERROR("firmware-efi");
|
2020-10-07 16:07:04 +00:00
|
|
|
DO_TEST("fs-9p");
|
|
|
|
DO_TEST("fs-9p-readonly");
|
|
|
|
DO_TEST_FAILURE("fs-9p-unsupported-type");
|
|
|
|
DO_TEST_FAILURE("fs-9p-unsupported-driver");
|
|
|
|
DO_TEST_FAILURE("fs-9p-unsupported-accessmode");
|
|
|
|
driver.bhyvecaps &= ~BHYVE_CAP_VIRTIO_9P;
|
|
|
|
DO_TEST_FAILURE("fs-9p");
|
2014-11-08 16:48:36 +00:00
|
|
|
|
2017-01-05 14:38:20 +00:00
|
|
|
/* Address allocation tests */
|
|
|
|
DO_TEST("addr-single-sata-disk");
|
|
|
|
DO_TEST("addr-multiple-sata-disks");
|
|
|
|
DO_TEST("addr-more-than-32-sata-disks");
|
2017-02-01 16:19:31 +00:00
|
|
|
DO_TEST("addr-single-virtio-disk");
|
|
|
|
DO_TEST("addr-multiple-virtio-disks");
|
2019-02-17 13:04:00 +00:00
|
|
|
DO_TEST("addr-isa-controller-on-slot-1");
|
|
|
|
DO_TEST("addr-isa-controller-on-slot-31");
|
2020-09-20 14:53:57 +00:00
|
|
|
DO_TEST("addr-non-isa-controller-on-slot-1");
|
2017-01-05 14:38:20 +00:00
|
|
|
|
|
|
|
/* The same without 32 devs per controller support */
|
|
|
|
driver.bhyvecaps ^= BHYVE_CAP_AHCI32SLOT;
|
|
|
|
DO_TEST("addr-no32devs-single-sata-disk");
|
|
|
|
DO_TEST("addr-no32devs-multiple-sata-disks");
|
|
|
|
DO_TEST_FAILURE("addr-no32devs-more-than-32-sata-disks");
|
|
|
|
|
2017-03-20 13:58:51 +00:00
|
|
|
/* USB xhci tablet */
|
|
|
|
DO_TEST("input-xhci-tablet");
|
|
|
|
DO_TEST_FAILURE("xhci-multiple-controllers");
|
|
|
|
DO_TEST_FAILURE("xhci-no-devs");
|
|
|
|
DO_TEST_FAILURE("xhci-multiple-devs");
|
|
|
|
driver.bhyvecaps ^= BHYVE_CAP_XHCI;
|
|
|
|
DO_TEST_FAILURE("input-xhci-tablet");
|
|
|
|
|
2014-11-08 16:48:36 +00:00
|
|
|
driver.grubcaps = 0;
|
|
|
|
|
|
|
|
DO_TEST("serial-grub-nocons");
|
2014-03-26 16:53:49 +00:00
|
|
|
|
2016-08-27 12:30:34 +00:00
|
|
|
driver.bhyvecaps &= ~BHYVE_CAP_NET_E1000;
|
|
|
|
|
|
|
|
DO_TEST_FAILURE("net-e1000");
|
|
|
|
|
2016-06-30 03:00:04 +00:00
|
|
|
driver.bhyvecaps &= ~BHYVE_CAP_LPC_BOOTROM;
|
|
|
|
DO_TEST_FAILURE("uefi");
|
|
|
|
|
2017-02-12 14:06:23 +00:00
|
|
|
driver.bhyvecaps &= ~BHYVE_CAP_FBUF;
|
|
|
|
DO_TEST_FAILURE("vnc");
|
|
|
|
|
2018-05-21 14:53:36 +00:00
|
|
|
driver.bhyvecaps &= ~BHYVE_CAP_CPUTOPOLOGY;
|
|
|
|
DO_TEST_FAILURE("cputopology");
|
|
|
|
|
2020-07-14 14:44:13 +00:00
|
|
|
driver.bhyvecaps &= ~BHYVE_CAP_SOUND_HDA;
|
|
|
|
DO_TEST_FAILURE("sound");
|
|
|
|
|
2020-05-06 13:35:55 +00:00
|
|
|
driver.bhyvecaps &= ~BHYVE_CAP_VNC_PASSWORD;
|
|
|
|
DO_TEST_FAILURE("vnc-password");
|
|
|
|
|
2014-03-26 16:53:49 +00:00
|
|
|
virObjectUnref(driver.caps);
|
|
|
|
virObjectUnref(driver.xmlopt);
|
2018-02-06 09:09:06 +00:00
|
|
|
virPortAllocatorRangeFree(driver.remotePorts);
|
2021-02-22 09:46:13 +00:00
|
|
|
virObjectUnref(driver.config);
|
2014-03-26 16:53:49 +00:00
|
|
|
|
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-08-21 16:13:16 +00:00
|
|
|
VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("bhyvexml2argv"))
|
2014-03-26 16:53:49 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
return EXIT_AM_SKIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WITH_BHYVE */
|