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"
|
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"
|
|
|
|
|
|
|
|
# define VIR_FROM_THIS VIR_FROM_BHYVE
|
|
|
|
|
|
|
|
static bhyveConn driver;
|
|
|
|
|
2015-12-13 03:17:15 +00:00
|
|
|
typedef enum {
|
|
|
|
FLAG_EXPECT_FAILURE = 1 << 0,
|
|
|
|
FLAG_EXPECT_PARSE_ERROR = 1 << 1,
|
|
|
|
} 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
|
|
|
{
|
2014-11-08 16:48:31 +00:00
|
|
|
char *actualargv = NULL, *actualld = NULL, *actualdm = NULL;
|
2014-03-26 16:53:49 +00:00
|
|
|
virDomainDefPtr vmdef = NULL;
|
2014-11-08 16:48:31 +00:00
|
|
|
virCommandPtr cmd = NULL, ldcmd = NULL;
|
2014-08-14 16:15:57 +00:00
|
|
|
virConnectPtr conn;
|
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
|
|
|
|
|
|
|
if (!(vmdef = virDomainDefParseFile(xml, driver.caps, driver.xmlopt,
|
2016-09-22 15:14:17 +00:00
|
|
|
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;
|
|
|
|
VIR_TEST_DEBUG("Got expected error: %s\n",
|
|
|
|
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
|
|
|
|
2015-12-13 03:17:15 +00:00
|
|
|
cmd = virBhyveProcessBuildBhyveCmd(conn, vmdef, false);
|
2016-06-30 03:00:04 +00:00
|
|
|
if (vmdef->os.loader)
|
|
|
|
ldcmd = virCommandNew("dummy");
|
|
|
|
else
|
|
|
|
ldcmd = virBhyveProcessBuildLoadCmd(conn, vmdef, "<device.map>",
|
|
|
|
&actualdm);
|
2015-12-13 03:17:15 +00:00
|
|
|
|
|
|
|
if ((cmd == NULL) || (ldcmd == NULL)) {
|
|
|
|
if (flags & FLAG_EXPECT_FAILURE) {
|
|
|
|
ret = 0;
|
|
|
|
VIR_TEST_DEBUG("Got expected error: %s\n",
|
|
|
|
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
|
|
|
|
qemu: use line breaks in command line args written to log
The QEMU command line arguments are very long and currently all written
on a single line to /var/log/libvirt/qemu/$GUEST.log. This introduces
logic to add line breaks after every env variable and "-" optional
argument, and every positional argument. This will create a clearer log
file, which will in turn present better in bug reports when people cut +
paste from the log into a bug comment.
An example log file entry now looks like this:
2018-12-14 12:57:03.677+0000: starting up libvirt version: 5.0.0, qemu version: 3.0.0qemu-3.0.0-1.fc29, kernel: 4.19.5-300.fc29.x86_64, hostname: localhost.localdomain
LC_ALL=C \
PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin \
HOME=/home/berrange \
USER=berrange \
LOGNAME=berrange \
QEMU_AUDIO_DRV=none \
/usr/bin/qemu-system-ppc64 \
-name guest=guest,debug-threads=on \
-S \
-object secret,id=masterKey0,format=raw,file=/home/berrange/.config/libvirt/qemu/lib/domain-33-guest/master-key.aes \
-machine pseries-2.10,accel=tcg,usb=off,dump-guest-core=off \
-m 1024 \
-realtime mlock=off \
-smp 1,sockets=1,cores=1,threads=1 \
-uuid c8a74977-ab18-41d0-ae3b-4041c7fffbcd \
-display none \
-no-user-config \
-nodefaults \
-chardev socket,id=charmonitor,fd=23,server,nowait \
-mon chardev=charmonitor,id=monitor,mode=control \
-rtc base=utc \
-no-shutdown \
-boot strict=on \
-device qemu-xhci,id=usb,bus=pci.0,addr=0x1 \
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \
-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
-msg timestamp=on
2018-12-14 12:57:03.730+0000: shutting down, reason=failed
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-12-14 12:07:08 +00:00
|
|
|
if (!(actualargv = virCommandToString(cmd, false)))
|
2014-03-26 16:53:49 +00:00
|
|
|
goto out;
|
|
|
|
|
2014-11-08 16:48:31 +00:00
|
|
|
if (actualdm != NULL)
|
|
|
|
virTrimSpaces(actualdm, NULL);
|
|
|
|
|
qemu: use line breaks in command line args written to log
The QEMU command line arguments are very long and currently all written
on a single line to /var/log/libvirt/qemu/$GUEST.log. This introduces
logic to add line breaks after every env variable and "-" optional
argument, and every positional argument. This will create a clearer log
file, which will in turn present better in bug reports when people cut +
paste from the log into a bug comment.
An example log file entry now looks like this:
2018-12-14 12:57:03.677+0000: starting up libvirt version: 5.0.0, qemu version: 3.0.0qemu-3.0.0-1.fc29, kernel: 4.19.5-300.fc29.x86_64, hostname: localhost.localdomain
LC_ALL=C \
PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin \
HOME=/home/berrange \
USER=berrange \
LOGNAME=berrange \
QEMU_AUDIO_DRV=none \
/usr/bin/qemu-system-ppc64 \
-name guest=guest,debug-threads=on \
-S \
-object secret,id=masterKey0,format=raw,file=/home/berrange/.config/libvirt/qemu/lib/domain-33-guest/master-key.aes \
-machine pseries-2.10,accel=tcg,usb=off,dump-guest-core=off \
-m 1024 \
-realtime mlock=off \
-smp 1,sockets=1,cores=1,threads=1 \
-uuid c8a74977-ab18-41d0-ae3b-4041c7fffbcd \
-display none \
-no-user-config \
-nodefaults \
-chardev socket,id=charmonitor,fd=23,server,nowait \
-mon chardev=charmonitor,id=monitor,mode=control \
-rtc base=utc \
-no-shutdown \
-boot strict=on \
-device qemu-xhci,id=usb,bus=pci.0,addr=0x1 \
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \
-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
-msg timestamp=on
2018-12-14 12:57:03.730+0000: shutting down, reason=failed
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-12-14 12:07:08 +00:00
|
|
|
if (!(actualld = virCommandToString(ldcmd, false)))
|
2014-11-08 16:48:31 +00:00
|
|
|
goto out;
|
|
|
|
|
2016-05-26 15:01:53 +00:00
|
|
|
if (virTestCompareToFile(actualargv, cmdline) < 0)
|
2014-03-26 16:53:49 +00:00
|
|
|
goto out;
|
|
|
|
|
2016-05-26 15:01:53 +00:00
|
|
|
if (virTestCompareToFile(actualld, ldcmdline) < 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:
|
2018-02-06 09:09:06 +00:00
|
|
|
if (vmdef &&
|
|
|
|
vmdef->ngraphics == 1 &&
|
2018-02-06 09:09:10 +00:00
|
|
|
vmdef->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC)
|
|
|
|
virPortAllocatorRelease(vmdef->graphics[0]->data.vnc.port);
|
2018-02-06 09:09:06 +00:00
|
|
|
|
2014-03-26 16:53:49 +00:00
|
|
|
VIR_FREE(actualargv);
|
2014-11-08 16:48:31 +00:00
|
|
|
VIR_FREE(actualld);
|
|
|
|
VIR_FREE(actualdm);
|
2014-03-26 16:53:49 +00:00
|
|
|
virCommandFree(cmd);
|
2014-11-08 16:48:31 +00:00
|
|
|
virCommandFree(ldcmd);
|
2014-03-26 16:53:49 +00:00
|
|
|
virDomainDefFree(vmdef);
|
2016-11-13 10:01:34 +00:00
|
|
|
virObjectUnref(conn);
|
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)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
2015-12-13 03:17:15 +00:00
|
|
|
const struct testInfo *info = data;
|
2014-03-26 16:53:49 +00:00
|
|
|
char *xml = NULL;
|
2014-11-08 16:48:31 +00:00
|
|
|
char *args = NULL, *ldargs = NULL, *dmargs = NULL;
|
2014-03-26 16:53:49 +00:00
|
|
|
|
|
|
|
if (virAsprintf(&xml, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.xml",
|
2015-12-13 03:17:15 +00:00
|
|
|
abs_srcdir, info->name) < 0 ||
|
2014-03-26 16:53:49 +00:00
|
|
|
virAsprintf(&args, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.args",
|
2015-12-13 03:17:15 +00:00
|
|
|
abs_srcdir, info->name) < 0 ||
|
2014-11-08 16:48:31 +00:00
|
|
|
virAsprintf(&ldargs, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.ldargs",
|
2015-12-13 03:17:15 +00:00
|
|
|
abs_srcdir, info->name) < 0 ||
|
2014-11-08 16:48:31 +00:00
|
|
|
virAsprintf(&dmargs, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.devmap",
|
2015-12-13 03:17:15 +00:00
|
|
|
abs_srcdir, info->name) < 0)
|
2014-03-26 16:53:49 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-12-13 03:17:15 +00:00
|
|
|
ret = testCompareXMLToArgvFiles(xml, args, ldargs, dmargs, info->flags);
|
2014-03-26 16:53:49 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(xml);
|
|
|
|
VIR_FREE(args);
|
2016-11-13 10:01:34 +00:00
|
|
|
VIR_FREE(ldargs);
|
|
|
|
VIR_FREE(dmargs);
|
2014-03-26 16:53:49 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
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 | \
|
|
|
|
BHYVE_CAP_CPUTOPOLOGY;
|
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");
|
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");
|
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");
|
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");
|
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");
|
|
|
|
|
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);
|
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 */
|