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 {
|
|
|
|
FLAG_EXPECT_FAILURE = 1,
|
|
|
|
FLAG_EXPECT_PARSE_ERROR = 2,
|
|
|
|
FLAG_EXPECT_WARNING = 4,
|
|
|
|
} virBhyveArgv2XMLTestFlags;
|
|
|
|
|
|
|
|
static int
|
|
|
|
testCompareXMLToArgvFiles(const char *xmlfile,
|
|
|
|
const char *cmdfile,
|
|
|
|
unsigned int flags)
|
|
|
|
|
|
|
|
{
|
|
|
|
char *actualxml = NULL;
|
|
|
|
char *cmd = NULL;
|
|
|
|
char *log = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
virDomainDefPtr vmdef = NULL;
|
|
|
|
|
|
|
|
if (virTestLoadFile(cmdfile, &cmd) < 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
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 {
|
|
|
|
goto fail;
|
|
|
|
}
|
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.");
|
2016-06-24 18:41:20 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2019-09-13 15:00:26 +00:00
|
|
|
if ((log = virTestLogContentAndReset()) == NULL)
|
|
|
|
goto fail;
|
|
|
|
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");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
} else { /* didn't expect a warning */
|
|
|
|
if (*log) {
|
|
|
|
VIR_TEST_DEBUG("Got unexpected warning from "
|
|
|
|
"bhyveParseCommandLineString:\n%s",
|
|
|
|
log);
|
2016-06-24 18:41:20 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vmdef && !(actualxml = virDomainDefFormat(vmdef, driver.caps, 0)))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (vmdef && virTestCompareToFile(actualxml, xmlfile) < 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
VIR_FREE(actualxml);
|
|
|
|
VIR_FREE(cmd);
|
|
|
|
VIR_FREE(log);
|
|
|
|
virDomainDefFree(vmdef);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct testInfo {
|
|
|
|
const char *name;
|
|
|
|
unsigned int flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
testCompareXMLToArgvHelper(const void *data)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
const struct testInfo *info = data;
|
|
|
|
char *xml = NULL;
|
|
|
|
char *args = NULL;
|
|
|
|
|
|
|
|
if (virAsprintf(&xml, "%s/bhyveargv2xmldata/bhyveargv2xml-%s.xml",
|
|
|
|
abs_srcdir, info->name) < 0 ||
|
|
|
|
virAsprintf(&args, "%s/bhyveargv2xmldata/bhyveargv2xml-%s.args",
|
|
|
|
abs_srcdir, info->name) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
result = testCompareXMLToArgvFiles(xml, args, info->flags);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(xml);
|
|
|
|
VIR_FREE(args);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) \
|
2016-06-24 18:41:20 +00:00
|
|
|
DO_TEST_FULL(name, 5)
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define DO_TEST_WARN(name) \
|
2016-06-24 18:41:20 +00:00
|
|
|
DO_TEST_FULL(name, 4)
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define DO_TEST_FAIL_SILENT(name) \
|
2016-06-24 18:41:20 +00:00
|
|
|
DO_TEST_FULL(name, 1)
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define DO_TEST_PARSE_ERROR(name) \
|
2016-06-24 18:41:20 +00:00
|
|
|
DO_TEST_FULL(name, 2)
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
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 */
|