2016-06-24 18:41:20 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "testutils.h"
|
|
|
|
|
|
|
|
#ifdef WITH_BHYVE
|
|
|
|
|
|
|
|
# include "datatypes.h"
|
|
|
|
|
|
|
|
# include "util/viruuid.h"
|
|
|
|
# include "bhyve/bhyve_driver.h"
|
|
|
|
# include "bhyve/bhyve_capabilities.h"
|
|
|
|
# include "bhyve/bhyve_utils.h"
|
|
|
|
# include "bhyve/bhyve_parse_command.h"
|
|
|
|
|
|
|
|
# define VIR_FROM_THIS VIR_FROM_BHYVE
|
|
|
|
|
|
|
|
static bhyveConn driver;
|
|
|
|
|
|
|
|
typedef enum {
|
2020-11-24 14:25:27 +00:00
|
|
|
FLAG_EXPECT_FAILURE = 1 << 0,
|
|
|
|
FLAG_EXPECT_PARSE_ERROR = 1 << 1,
|
|
|
|
FLAG_EXPECT_WARNING = 1 << 2,
|
2016-06-24 18:41:20 +00:00
|
|
|
} virBhyveArgv2XMLTestFlags;
|
|
|
|
|
|
|
|
static int
|
|
|
|
testCompareXMLToArgvFiles(const char *xmlfile,
|
|
|
|
const char *cmdfile,
|
|
|
|
unsigned int flags)
|
|
|
|
|
|
|
|
{
|
2020-07-28 00:56:33 +00:00
|
|
|
g_autofree char *actualxml = NULL;
|
|
|
|
g_autofree char *cmd = NULL;
|
|
|
|
g_autofree char *log = NULL;
|
2020-07-28 00:59:58 +00:00
|
|
|
g_autoptr(virDomainDef) vmdef = NULL;
|
2016-06-24 18:41:20 +00:00
|
|
|
|
|
|
|
if (virTestLoadFile(cmdfile, &cmd) < 0)
|
2020-07-28 00:58:58 +00:00
|
|
|
return -1;
|
2016-06-24 18:41:20 +00:00
|
|
|
|
|
|
|
if (!(vmdef = bhyveParseCommandLineString(cmd, driver.bhyvecaps,
|
|
|
|
driver.xmlopt))) {
|
2019-09-13 15:00:26 +00:00
|
|
|
if ((flags & FLAG_EXPECT_FAILURE)) {
|
|
|
|
VIR_TEST_DEBUG("Got expected failure from "
|
|
|
|
"bhyveParseCommandLineString.");
|
2016-06-24 18:41:20 +00:00
|
|
|
} else {
|
2020-07-28 00:58:58 +00:00
|
|
|
return -1;
|
2016-06-24 18:41:20 +00:00
|
|
|
}
|
2019-09-13 15:00:26 +00:00
|
|
|
} else if ((flags & FLAG_EXPECT_FAILURE)) {
|
2016-06-24 18:41:20 +00:00
|
|
|
VIR_TEST_DEBUG("Did not get expected failure from "
|
2019-05-03 08:31:02 +00:00
|
|
|
"bhyveParseCommandLineString.");
|
2020-07-28 00:58:58 +00:00
|
|
|
return -1;
|
2016-06-24 18:41:20 +00:00
|
|
|
}
|
|
|
|
|
2019-09-13 15:00:26 +00:00
|
|
|
if ((log = virTestLogContentAndReset()) == NULL)
|
2020-07-28 00:58:58 +00:00
|
|
|
return -1;
|
2019-09-13 15:00:26 +00:00
|
|
|
if (flags & FLAG_EXPECT_WARNING) {
|
|
|
|
if (*log) {
|
|
|
|
VIR_TEST_DEBUG("Got expected warning from "
|
|
|
|
"bhyveParseCommandLineString:\n%s",
|
|
|
|
log);
|
|
|
|
} else {
|
|
|
|
VIR_TEST_DEBUG("bhyveParseCommandLineString "
|
|
|
|
"should have logged a warning");
|
2020-07-28 00:58:58 +00:00
|
|
|
return -1;
|
2019-09-13 15:00:26 +00:00
|
|
|
}
|
|
|
|
} else { /* didn't expect a warning */
|
|
|
|
if (*log) {
|
|
|
|
VIR_TEST_DEBUG("Got unexpected warning from "
|
|
|
|
"bhyveParseCommandLineString:\n%s",
|
|
|
|
log);
|
2020-07-28 00:58:58 +00:00
|
|
|
return -1;
|
2016-06-24 18:41:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-05 09:46:02 +00:00
|
|
|
if (vmdef && !virDomainDefCheckABIStability(vmdef, vmdef, driver.xmlopt)) {
|
2016-06-24 18:41:20 +00:00
|
|
|
VIR_TEST_DEBUG("ABI stability check failed on %s", xmlfile);
|
2020-07-28 00:58:58 +00:00
|
|
|
return -1;
|
2016-06-24 18:41:20 +00:00
|
|
|
}
|
|
|
|
|
2020-05-06 13:35:55 +00:00
|
|
|
if (vmdef && !(actualxml = virDomainDefFormat(vmdef, driver.xmlopt, VIR_DOMAIN_DEF_FORMAT_SECURE)))
|
2020-07-28 00:58:58 +00:00
|
|
|
return -1;
|
2016-06-24 18:41:20 +00:00
|
|
|
|
|
|
|
if (vmdef && virTestCompareToFile(actualxml, xmlfile) < 0)
|
2020-07-28 00:58:58 +00:00
|
|
|
return -1;
|
2016-06-24 18:41:20 +00:00
|
|
|
|
2020-07-28 00:58:58 +00:00
|
|
|
return 0;
|
2016-06-24 18:41:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct testInfo {
|
|
|
|
const char *name;
|
|
|
|
unsigned int flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
testCompareXMLToArgvHelper(const void *data)
|
|
|
|
{
|
|
|
|
const struct testInfo *info = data;
|
2020-07-28 00:56:33 +00:00
|
|
|
g_autofree char *xml = NULL;
|
|
|
|
g_autofree char *args = NULL;
|
2016-06-24 18:41:20 +00:00
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
xml = g_strdup_printf("%s/bhyveargv2xmldata/bhyveargv2xml-%s.xml",
|
|
|
|
abs_srcdir, info->name);
|
|
|
|
args = g_strdup_printf("%s/bhyveargv2xmldata/bhyveargv2xml-%s.args",
|
|
|
|
abs_srcdir, info->name);
|
2016-06-24 18:41:20 +00:00
|
|
|
|
2020-07-28 00:58:58 +00:00
|
|
|
return testCompareXMLToArgvFiles(xml, args, info->flags);
|
2016-06-24 18:41:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if ((driver.caps = virBhyveCapsBuild()) == NULL)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2017-05-19 13:07:15 +00:00
|
|
|
if ((driver.xmlopt = virDomainXMLOptionNew(NULL, NULL,
|
2017-06-01 22:44:46 +00:00
|
|
|
NULL, NULL, NULL)) == NULL)
|
2016-06-24 18:41:20 +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 ARGV-2-XML " name, \
|
2016-06-24 18:41:20 +00:00
|
|
|
testCompareXMLToArgvHelper, &info) < 0) \
|
2017-11-03 12:09:47 +00:00
|
|
|
ret = -1; \
|
2016-06-24 18:41:20 +00:00
|
|
|
} while (0)
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define DO_TEST(name) \
|
2016-06-24 18:41:20 +00:00
|
|
|
DO_TEST_FULL(name, 0)
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define DO_TEST_FAIL(name) \
|
2020-11-24 14:24:26 +00:00
|
|
|
DO_TEST_FULL(name, FLAG_EXPECT_FAILURE | FLAG_EXPECT_WARNING)
|
2016-06-24 18:41:20 +00:00
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define DO_TEST_WARN(name) \
|
2020-11-24 14:24:26 +00:00
|
|
|
DO_TEST_FULL(name, FLAG_EXPECT_WARNING)
|
2016-06-24 18:41:20 +00:00
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define DO_TEST_FAIL_SILENT(name) \
|
2020-11-24 14:24:26 +00:00
|
|
|
DO_TEST_FULL(name, FLAG_EXPECT_FAILURE)
|
2016-06-24 18:41:20 +00:00
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define DO_TEST_PARSE_ERROR(name) \
|
2020-11-24 14:24:26 +00:00
|
|
|
DO_TEST_FULL(name, FLAG_EXPECT_PARSE_ERROR)
|
2016-06-24 18:41:20 +00:00
|
|
|
|
|
|
|
driver.grubcaps = BHYVE_GRUB_CAP_CONSDEV;
|
|
|
|
driver.bhyvecaps = BHYVE_CAP_RTC_UTC;
|
|
|
|
|
|
|
|
DO_TEST("base");
|
2018-05-09 01:01:36 +00:00
|
|
|
DO_TEST("wired");
|
2016-06-24 18:41:20 +00:00
|
|
|
DO_TEST("oneline");
|
|
|
|
DO_TEST("name");
|
|
|
|
DO_TEST("console");
|
|
|
|
DO_TEST_FAIL("console2");
|
|
|
|
DO_TEST_FAIL("console3");
|
|
|
|
DO_TEST_FAIL("console4");
|
|
|
|
DO_TEST("acpiapic");
|
|
|
|
DO_TEST("utc");
|
|
|
|
DO_TEST("vcpus");
|
|
|
|
DO_TEST("cdrom");
|
|
|
|
DO_TEST("ahci-hd");
|
|
|
|
DO_TEST("virtio-blk");
|
|
|
|
DO_TEST("virtio-net");
|
2016-08-27 12:30:34 +00:00
|
|
|
DO_TEST("e1000");
|
2016-06-24 18:41:20 +00:00
|
|
|
DO_TEST_WARN("virtio-net2");
|
|
|
|
DO_TEST_WARN("virtio-net3");
|
|
|
|
DO_TEST_WARN("virtio-net4");
|
|
|
|
DO_TEST_WARN("disk-toomany");
|
|
|
|
DO_TEST("uuid");
|
|
|
|
DO_TEST_FAIL("uuid2");
|
|
|
|
DO_TEST("memsize-large");
|
|
|
|
DO_TEST("memsize-human");
|
|
|
|
DO_TEST_FAIL("memsize-fail");
|
|
|
|
DO_TEST("custom-loader");
|
|
|
|
DO_TEST("bhyveload-custom");
|
|
|
|
DO_TEST("bhyveload-vda");
|
|
|
|
DO_TEST_FAIL("bhyveload-name-mismatch");
|
|
|
|
DO_TEST_FAIL("bhyverun-name-mismatch");
|
|
|
|
DO_TEST_FAIL("bhyveload-mem-mismatch");
|
|
|
|
DO_TEST_FAIL("bhyverun-mem-mismatch");
|
|
|
|
DO_TEST_FAIL("bhyveload-mem-mismatch");
|
|
|
|
DO_TEST_FAIL("bhyveload-memsize-fail");
|
|
|
|
DO_TEST("bhyveload-bootorder");
|
|
|
|
DO_TEST_FAIL("extraargs");
|
2020-05-06 13:35:52 +00:00
|
|
|
DO_TEST("vnc");
|
|
|
|
DO_TEST("vnc-listen");
|
|
|
|
DO_TEST("vnc-vga-on");
|
|
|
|
DO_TEST("vnc-vga-off");
|
|
|
|
DO_TEST("vnc-vga-io");
|
2020-05-06 13:35:53 +00:00
|
|
|
DO_TEST("vnc-resolution");
|
2020-05-06 13:35:55 +00:00
|
|
|
DO_TEST("vnc-password");
|
2016-06-24 18:41:20 +00:00
|
|
|
|
|
|
|
virObjectUnref(driver.caps);
|
|
|
|
virObjectUnref(driver.xmlopt);
|
|
|
|
|
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-08-21 16:13:16 +00:00
|
|
|
VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("bhyveargv2xml"))
|
2016-06-24 18:41:20 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
return EXIT_AM_SKIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WITH_BHYVE */
|