2014-03-27 00:53:49 +08:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "testutils.h"
|
|
|
|
|
|
|
|
#ifdef WITH_BHYVE
|
|
|
|
|
|
|
|
# include "datatypes.h"
|
|
|
|
|
2014-04-09 01:18:00 +08:00
|
|
|
# include "bhyve/bhyve_capabilities.h"
|
2014-03-27 00:53:49 +08:00
|
|
|
# include "bhyve/bhyve_utils.h"
|
|
|
|
# include "bhyve/bhyve_command.h"
|
|
|
|
|
|
|
|
# define VIR_FROM_THIS VIR_FROM_BHYVE
|
|
|
|
|
|
|
|
static bhyveConn driver;
|
|
|
|
|
|
|
|
static int testCompareXMLToArgvFiles(const char *xml,
|
2014-11-09 00:48:31 +08:00
|
|
|
const char *cmdline,
|
|
|
|
const char *ldcmdline,
|
|
|
|
const char *dmcmdline)
|
2014-03-27 00:53:49 +08:00
|
|
|
{
|
2014-11-09 00:48:31 +08:00
|
|
|
char *actualargv = NULL, *actualld = NULL, *actualdm = NULL;
|
2014-03-27 00:53:49 +08:00
|
|
|
virDomainDefPtr vmdef = NULL;
|
2014-11-09 00:48:31 +08:00
|
|
|
virCommandPtr cmd = NULL, ldcmd = NULL;
|
2014-08-15 00:15:57 +08:00
|
|
|
virConnectPtr conn;
|
2014-03-27 00:53:49 +08:00
|
|
|
int ret = -1;
|
|
|
|
|
2014-08-15 00:15:57 +08:00
|
|
|
if (!(conn = virGetConnect()))
|
|
|
|
goto out;
|
2014-03-27 00:53:49 +08:00
|
|
|
|
|
|
|
if (!(vmdef = virDomainDefParseFile(xml, driver.caps, driver.xmlopt,
|
2014-11-19 00:44:00 +08:00
|
|
|
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
|
2014-03-27 00:53:49 +08:00
|
|
|
goto out;
|
|
|
|
|
2014-11-09 00:48:36 +08:00
|
|
|
conn->privateData = &driver;
|
2014-03-27 00:53:49 +08:00
|
|
|
|
2014-08-15 00:15:57 +08:00
|
|
|
if (!(cmd = virBhyveProcessBuildBhyveCmd(conn, vmdef, false)))
|
2014-03-27 00:53:49 +08:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!(actualargv = virCommandToString(cmd)))
|
|
|
|
goto out;
|
|
|
|
|
2014-11-09 00:48:31 +08:00
|
|
|
if (!(ldcmd = virBhyveProcessBuildLoadCmd(conn, vmdef, "<device.map>",
|
|
|
|
&actualdm)))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (actualdm != NULL)
|
|
|
|
virTrimSpaces(actualdm, NULL);
|
|
|
|
|
|
|
|
if (!(actualld = virCommandToString(ldcmd)))
|
|
|
|
goto out;
|
|
|
|
|
2015-04-23 23:14:26 +08:00
|
|
|
if (virtTestCompareToFile(actualargv, cmdline) < 0)
|
2014-03-27 00:53:49 +08:00
|
|
|
goto out;
|
|
|
|
|
2015-04-23 23:14:26 +08:00
|
|
|
if (virtTestCompareToFile(actualld, ldcmdline) < 0)
|
2014-11-09 00:48:31 +08:00
|
|
|
goto out;
|
|
|
|
|
2015-04-23 23:14:26 +08:00
|
|
|
if (virFileExists(dmcmdline) || actualdm) {
|
|
|
|
if (virtTestCompareToFile(actualdm, dmcmdline) < 0)
|
|
|
|
goto out;
|
2014-11-09 00:48:31 +08:00
|
|
|
}
|
|
|
|
|
2014-03-27 00:53:49 +08:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
VIR_FREE(actualargv);
|
2014-11-09 00:48:31 +08:00
|
|
|
VIR_FREE(actualld);
|
|
|
|
VIR_FREE(actualdm);
|
2014-03-27 00:53:49 +08:00
|
|
|
virCommandFree(cmd);
|
2014-11-09 00:48:31 +08:00
|
|
|
virCommandFree(ldcmd);
|
2014-03-27 00:53:49 +08:00
|
|
|
virDomainDefFree(vmdef);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testCompareXMLToArgvHelper(const void *data)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
const char *name = data;
|
|
|
|
char *xml = NULL;
|
2014-11-09 00:48:31 +08:00
|
|
|
char *args = NULL, *ldargs = NULL, *dmargs = NULL;
|
2014-03-27 00:53:49 +08:00
|
|
|
|
|
|
|
if (virAsprintf(&xml, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.xml",
|
|
|
|
abs_srcdir, name) < 0 ||
|
|
|
|
virAsprintf(&args, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.args",
|
2014-11-09 00:48:31 +08:00
|
|
|
abs_srcdir, name) < 0 ||
|
|
|
|
virAsprintf(&ldargs, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.ldargs",
|
|
|
|
abs_srcdir, name) < 0 ||
|
|
|
|
virAsprintf(&dmargs, "%s/bhyvexml2argvdata/bhyvexml2argv-%s.devmap",
|
2014-03-27 00:53:49 +08:00
|
|
|
abs_srcdir, name) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-11-09 00:48:31 +08:00
|
|
|
ret = testCompareXMLToArgvFiles(xml, args, ldargs, dmargs);
|
2014-03-27 00:53:49 +08:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(xml);
|
|
|
|
VIR_FREE(args);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2014-04-09 01:18:00 +08:00
|
|
|
if ((driver.caps = virBhyveCapsBuild()) == NULL)
|
2014-03-27 00:53:49 +08:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
if ((driver.xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL)) == NULL)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
# define DO_TEST(name) \
|
|
|
|
do { \
|
|
|
|
if (virtTestRun("BHYVE XML-2-ARGV " name, \
|
|
|
|
testCompareXMLToArgvHelper, name) < 0) \
|
|
|
|
ret = -1; \
|
|
|
|
} while (0)
|
|
|
|
|
2014-11-09 00:48:36 +08:00
|
|
|
driver.grubcaps = BHYVE_GRUB_CAP_CONSDEV;
|
2015-07-19 16:20:35 +08:00
|
|
|
driver.bhyvecaps = BHYVE_CAP_RTC_UTC;
|
2014-03-27 00:53:49 +08:00
|
|
|
|
|
|
|
DO_TEST("base");
|
|
|
|
DO_TEST("acpiapic");
|
2014-07-19 23:15:26 +08:00
|
|
|
DO_TEST("disk-cdrom");
|
2014-03-27 00:53:49 +08:00
|
|
|
DO_TEST("disk-virtio");
|
|
|
|
DO_TEST("macaddr");
|
2014-03-30 19:54:52 +08:00
|
|
|
DO_TEST("serial");
|
|
|
|
DO_TEST("console");
|
2014-11-09 00:48:33 +08:00
|
|
|
DO_TEST("grub-defaults");
|
2014-11-13 06:31:53 +08:00
|
|
|
DO_TEST("grub-bootorder");
|
|
|
|
DO_TEST("grub-bootorder2");
|
2014-11-09 00:48:33 +08:00
|
|
|
DO_TEST("bhyveload-explicitargs");
|
|
|
|
DO_TEST("custom-loader");
|
|
|
|
DO_TEST("disk-cdrom-grub");
|
2014-11-09 00:48:36 +08:00
|
|
|
DO_TEST("serial-grub");
|
2015-07-19 16:20:35 +08:00
|
|
|
DO_TEST("localtime");
|
2014-11-09 00:48:36 +08:00
|
|
|
|
|
|
|
driver.grubcaps = 0;
|
|
|
|
|
|
|
|
DO_TEST("serial-grub-nocons");
|
2014-03-27 00:53:49 +08:00
|
|
|
|
|
|
|
virObjectUnref(driver.caps);
|
|
|
|
virObjectUnref(driver.xmlopt);
|
|
|
|
|
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIRT_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/bhyvexml2argvmock.so")
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
return EXIT_AM_SKIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WITH_BHYVE */
|