2014-12-16 12:30:05 +08:00
|
|
|
/*
|
2016-02-16 10:42:27 +08:00
|
|
|
* xlconfigtest.c: Test xl.cfg(5) <-> domXML config conversions
|
2014-12-16 12:30:05 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2007, 2010-2011, 2014 Red Hat, Inc.
|
|
|
|
* Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
2019-02-22 19:42:38 +08:00
|
|
|
* Copyright (C) 2014 David Kiarie Kahurani
|
2014-12-16 12:30:05 +08:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
#include "datatypes.h"
|
2019-08-24 02:34:46 +08:00
|
|
|
#include "libxl/xen_xl.h"
|
2014-12-16 12:30:05 +08:00
|
|
|
#include "viralloc.h"
|
|
|
|
#include "virstring.h"
|
|
|
|
#include "testutils.h"
|
|
|
|
#include "testutilsxen.h"
|
2015-01-21 07:45:09 +08:00
|
|
|
#include "libxl/libxl_conf.h"
|
2014-12-16 12:30:05 +08:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
2019-12-03 18:49:49 +08:00
|
|
|
static libxlDriverPrivatePtr driver;
|
2016-04-21 05:14:34 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This function provides a mechanism to replace variables in test
|
|
|
|
* data files whose values are discovered at built time.
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
testReplaceVarsXML(const char *xml)
|
|
|
|
{
|
|
|
|
char *xmlcfgData;
|
|
|
|
char *replacedXML;
|
|
|
|
|
|
|
|
if (virTestLoadFile(xml, &xmlcfgData) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
replacedXML = virStringReplace(xmlcfgData, "/LIBXL_FIRMWARE_DIR",
|
|
|
|
LIBXL_FIRMWARE_DIR);
|
|
|
|
|
|
|
|
VIR_FREE(xmlcfgData);
|
|
|
|
return replacedXML;
|
|
|
|
}
|
|
|
|
|
2014-12-16 12:30:05 +08:00
|
|
|
/*
|
2016-02-16 10:42:27 +08:00
|
|
|
* Parses domXML to virDomainDef object, which is then converted to xl.cfg(5)
|
|
|
|
* config and compared with expected config.
|
2014-12-16 12:30:05 +08:00
|
|
|
*/
|
|
|
|
static int
|
2016-04-21 05:14:34 +08:00
|
|
|
testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars)
|
2014-12-16 12:30:05 +08:00
|
|
|
{
|
2016-02-16 10:42:27 +08:00
|
|
|
char *gotxlcfgData = NULL;
|
2019-10-15 20:47:50 +08:00
|
|
|
g_autoptr(virConf) conf = NULL;
|
2014-12-16 12:30:05 +08:00
|
|
|
virConnectPtr conn = NULL;
|
|
|
|
int wrote = 4096;
|
|
|
|
int ret = -1;
|
|
|
|
virDomainDefPtr def = NULL;
|
2016-04-21 05:14:34 +08:00
|
|
|
char *replacedXML = NULL;
|
2014-12-16 12:30:05 +08:00
|
|
|
|
2016-02-16 10:42:27 +08:00
|
|
|
if (VIR_ALLOC_N(gotxlcfgData, wrote) < 0)
|
2014-12-16 12:30:05 +08:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
conn = virGetConnect();
|
|
|
|
if (!conn) goto fail;
|
|
|
|
|
2016-04-21 05:14:34 +08:00
|
|
|
if (replaceVars) {
|
|
|
|
if (!(replacedXML = testReplaceVarsXML(xml)))
|
|
|
|
goto fail;
|
2019-11-27 20:29:21 +08:00
|
|
|
if (!(def = virDomainDefParseString(replacedXML, driver->xmlopt,
|
2016-09-22 23:14:17 +08:00
|
|
|
NULL, VIR_DOMAIN_XML_INACTIVE)))
|
2016-04-21 05:14:34 +08:00
|
|
|
goto fail;
|
|
|
|
} else {
|
2019-11-27 20:29:21 +08:00
|
|
|
if (!(def = virDomainDefParseFile(xml, driver->xmlopt,
|
2016-09-22 23:14:17 +08:00
|
|
|
NULL, VIR_DOMAIN_XML_INACTIVE)))
|
2016-04-21 05:14:34 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
2014-12-16 12:30:05 +08:00
|
|
|
|
2019-12-03 18:49:49 +08:00
|
|
|
if (!virDomainDefCheckABIStability(def, def, driver->xmlopt)) {
|
2014-12-16 12:30:05 +08:00
|
|
|
fprintf(stderr, "ABI stability check failed on %s", xml);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2015-12-05 10:11:39 +08:00
|
|
|
if (!(conf = xenFormatXL(def, conn)))
|
2014-12-16 12:30:05 +08:00
|
|
|
goto fail;
|
|
|
|
|
2016-02-16 10:42:27 +08:00
|
|
|
if (virConfWriteMem(gotxlcfgData, &wrote, conf) < 0)
|
2014-12-16 12:30:05 +08:00
|
|
|
goto fail;
|
2016-02-16 10:42:27 +08:00
|
|
|
gotxlcfgData[wrote] = '\0';
|
2014-12-16 12:30:05 +08:00
|
|
|
|
2016-05-26 23:01:53 +08:00
|
|
|
if (virTestCompareToFile(gotxlcfgData, xlcfg) < 0)
|
2014-12-16 12:30:05 +08:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
fail:
|
2016-04-21 05:14:34 +08:00
|
|
|
VIR_FREE(replacedXML);
|
2016-02-16 10:42:27 +08:00
|
|
|
VIR_FREE(gotxlcfgData);
|
2014-12-16 12:30:05 +08:00
|
|
|
virDomainDefFree(def);
|
|
|
|
virObjectUnref(conn);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2016-02-16 10:42:27 +08:00
|
|
|
|
2014-12-16 12:30:05 +08:00
|
|
|
/*
|
2016-02-16 10:42:27 +08:00
|
|
|
* Parses xl.cfg(5) config to virDomainDef object, which is then converted to
|
|
|
|
* domXML and compared to expected XML.
|
2014-12-16 12:30:05 +08:00
|
|
|
*/
|
|
|
|
static int
|
2016-04-21 05:14:34 +08:00
|
|
|
testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars)
|
2014-12-16 12:30:05 +08:00
|
|
|
{
|
2016-02-16 10:42:27 +08:00
|
|
|
char *xlcfgData = NULL;
|
2014-12-16 12:30:05 +08:00
|
|
|
char *gotxml = NULL;
|
2019-10-15 20:47:50 +08:00
|
|
|
g_autoptr(virConf) conf = NULL;
|
2014-12-16 12:30:05 +08:00
|
|
|
int ret = -1;
|
|
|
|
virConnectPtr conn;
|
|
|
|
virDomainDefPtr def = NULL;
|
2016-04-21 05:14:34 +08:00
|
|
|
char *replacedXML = NULL;
|
2019-12-03 18:49:49 +08:00
|
|
|
g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
|
2014-12-16 12:30:05 +08:00
|
|
|
|
|
|
|
conn = virGetConnect();
|
|
|
|
if (!conn) goto fail;
|
|
|
|
|
2016-05-26 23:01:52 +08:00
|
|
|
if (virTestLoadFile(xlcfg, &xlcfgData) < 0)
|
2014-12-16 12:30:05 +08:00
|
|
|
goto fail;
|
|
|
|
|
2017-08-07 23:12:02 +08:00
|
|
|
if (!(conf = virConfReadString(xlcfgData, 0)))
|
2014-12-16 12:30:05 +08:00
|
|
|
goto fail;
|
|
|
|
|
2019-12-03 18:49:49 +08:00
|
|
|
if (!(def = xenParseXL(conf, cfg->caps, driver->xmlopt)))
|
2014-12-16 12:30:05 +08:00
|
|
|
goto fail;
|
|
|
|
|
2019-11-27 19:57:34 +08:00
|
|
|
if (!(gotxml = virDomainDefFormat(def, driver->xmlopt,
|
2019-11-27 03:40:46 +08:00
|
|
|
VIR_DOMAIN_XML_INACTIVE |
|
2014-12-16 12:30:05 +08:00
|
|
|
VIR_DOMAIN_XML_SECURE)))
|
|
|
|
goto fail;
|
|
|
|
|
2016-04-21 05:14:34 +08:00
|
|
|
if (replaceVars) {
|
|
|
|
if (!(replacedXML = testReplaceVarsXML(xml)))
|
|
|
|
goto fail;
|
|
|
|
if (virTestCompareToString(gotxml, replacedXML) < 0)
|
|
|
|
goto fail;
|
|
|
|
} else {
|
|
|
|
if (virTestCompareToFile(gotxml, xml) < 0)
|
|
|
|
goto fail;
|
|
|
|
}
|
2014-12-16 12:30:05 +08:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
fail:
|
2016-04-21 05:14:34 +08:00
|
|
|
VIR_FREE(replacedXML);
|
2016-02-16 10:42:27 +08:00
|
|
|
VIR_FREE(xlcfgData);
|
2014-12-16 12:30:05 +08:00
|
|
|
VIR_FREE(gotxml);
|
|
|
|
virDomainDefFree(def);
|
|
|
|
virObjectUnref(conn);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct testInfo {
|
|
|
|
const char *name;
|
|
|
|
int mode;
|
2016-04-21 05:14:34 +08:00
|
|
|
bool replaceVars;
|
2014-12-16 12:30:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
testCompareHelper(const void *data)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
const struct testInfo *info = data;
|
|
|
|
char *xml = NULL;
|
|
|
|
char *cfg = NULL;
|
|
|
|
|
2019-10-22 21:26:14 +08:00
|
|
|
xml = g_strdup_printf("%s/xlconfigdata/test-%s.xml", abs_srcdir, info->name);
|
|
|
|
cfg = g_strdup_printf("%s/xlconfigdata/test-%s.cfg", abs_srcdir, info->name);
|
2014-12-16 12:30:05 +08:00
|
|
|
|
|
|
|
if (info->mode == 0)
|
2016-04-21 05:14:34 +08:00
|
|
|
result = testCompareParseXML(cfg, xml, info->replaceVars);
|
2014-12-16 12:30:05 +08:00
|
|
|
else
|
2016-04-21 05:14:34 +08:00
|
|
|
result = testCompareFormatXML(cfg, xml, info->replaceVars);
|
2014-12-16 12:30:05 +08:00
|
|
|
|
|
|
|
VIR_FREE(xml);
|
|
|
|
VIR_FREE(cfg);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2019-12-03 18:49:49 +08:00
|
|
|
if (!(driver = testXLInitDriver()))
|
2014-12-16 12:30:05 +08:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2017-11-03 20:09:47 +08:00
|
|
|
#define DO_TEST_PARSE(name, replace) \
|
|
|
|
do { \
|
|
|
|
struct testInfo info0 = { name, 0, replace }; \
|
|
|
|
if (virTestRun("Xen XL-2-XML Parse " name, \
|
|
|
|
testCompareHelper, &info0) < 0) \
|
|
|
|
ret = -1; \
|
2016-01-21 20:29:29 +08:00
|
|
|
} while (0)
|
|
|
|
|
2017-11-03 20:09:47 +08:00
|
|
|
#define DO_TEST_FORMAT(name, replace) \
|
|
|
|
do { \
|
|
|
|
struct testInfo info1 = { name, 1, replace }; \
|
|
|
|
if (virTestRun("Xen XL-2-XML Format " name, \
|
|
|
|
testCompareHelper, &info1) < 0) \
|
|
|
|
ret = -1; \
|
2014-12-16 12:30:05 +08:00
|
|
|
} while (0)
|
|
|
|
|
2017-11-03 20:09:47 +08:00
|
|
|
#define DO_TEST(name) \
|
|
|
|
do { \
|
|
|
|
DO_TEST_PARSE(name, false); \
|
|
|
|
DO_TEST_FORMAT(name, false); \
|
2016-04-21 05:14:34 +08:00
|
|
|
} while (0)
|
|
|
|
|
2017-11-03 20:09:47 +08:00
|
|
|
#define DO_TEST_REPLACE_VARS(name) \
|
|
|
|
do { \
|
|
|
|
DO_TEST_PARSE(name, true); \
|
|
|
|
DO_TEST_FORMAT(name, true); \
|
2016-01-21 20:29:29 +08:00
|
|
|
} while (0)
|
|
|
|
|
2018-11-17 04:08:23 +08:00
|
|
|
DO_TEST("fullvirt-ovswitch-tagged");
|
|
|
|
DO_TEST("fullvirt-ovswitch-trunked");
|
2016-04-21 05:14:34 +08:00
|
|
|
DO_TEST_REPLACE_VARS("fullvirt-ovmf");
|
2015-12-16 05:47:40 +08:00
|
|
|
DO_TEST("paravirt-maxvcpus");
|
2015-12-05 09:09:28 +08:00
|
|
|
DO_TEST("new-disk");
|
2016-04-21 05:14:34 +08:00
|
|
|
DO_TEST_FORMAT("disk-positional-parms-full", false);
|
|
|
|
DO_TEST_FORMAT("disk-positional-parms-partial", false);
|
2016-12-19 17:13:35 +08:00
|
|
|
#ifdef LIBXL_HAVE_QED
|
|
|
|
DO_TEST_FORMAT("disk-qed", false);
|
|
|
|
#endif
|
2019-01-19 04:46:56 +08:00
|
|
|
DO_TEST("net-fakemodel");
|
2015-12-05 09:09:28 +08:00
|
|
|
DO_TEST("spice");
|
|
|
|
DO_TEST("spice-features");
|
2015-12-29 06:26:17 +08:00
|
|
|
DO_TEST("vif-rate");
|
2016-02-23 09:50:19 +08:00
|
|
|
DO_TEST("fullvirt-nohap");
|
2017-01-20 08:19:18 +08:00
|
|
|
DO_TEST("fullvirt-hpet-timer");
|
|
|
|
DO_TEST("fullvirt-tsc-timer");
|
|
|
|
DO_TEST("fullvirt-multi-timer");
|
2017-04-24 21:07:01 +08:00
|
|
|
DO_TEST("fullvirt-nestedhvm");
|
|
|
|
DO_TEST("fullvirt-nestedhvm-disabled");
|
2018-04-12 09:03:27 +08:00
|
|
|
DO_TEST("fullvirt-cpuid");
|
2019-09-16 03:43:24 +08:00
|
|
|
DO_TEST("fullvirt-acpi-slic");
|
2017-11-11 03:12:34 +08:00
|
|
|
#ifdef LIBXL_HAVE_VNUMA
|
|
|
|
DO_TEST("fullvirt-vnuma");
|
|
|
|
DO_TEST_PARSE("fullvirt-vnuma-autocomplete", false);
|
|
|
|
DO_TEST_PARSE("fullvirt-vnuma-nodistances", false);
|
|
|
|
DO_TEST_PARSE("fullvirt-vnuma-partialdist", false);
|
|
|
|
#endif
|
2015-04-02 20:57:54 +08:00
|
|
|
|
2016-01-21 20:29:29 +08:00
|
|
|
DO_TEST("paravirt-cmdline");
|
2016-04-21 05:14:34 +08:00
|
|
|
DO_TEST_FORMAT("paravirt-cmdline-extra-root", false);
|
|
|
|
DO_TEST_FORMAT("paravirt-cmdline-bogus-extra-root", false);
|
2016-02-11 08:39:18 +08:00
|
|
|
DO_TEST("rbd-multihost-noauth");
|
2018-11-27 03:34:39 +08:00
|
|
|
DO_TEST_FORMAT("paravirt-type", false);
|
|
|
|
DO_TEST_FORMAT("fullvirt-type", false);
|
2018-11-27 03:34:40 +08:00
|
|
|
DO_TEST("pvh-type");
|
2016-01-21 20:29:29 +08:00
|
|
|
|
2016-09-27 01:33:18 +08:00
|
|
|
#ifdef LIBXL_HAVE_DEVICE_CHANNEL
|
|
|
|
DO_TEST("channel-pty");
|
|
|
|
DO_TEST("channel-unix");
|
|
|
|
#endif
|
2016-08-18 10:20:50 +08:00
|
|
|
#ifdef LIBXL_HAVE_BUILDINFO_SERIAL_LIST
|
|
|
|
DO_TEST("fullvirt-multiserial");
|
|
|
|
#endif
|
2015-04-02 20:57:54 +08:00
|
|
|
#ifdef LIBXL_HAVE_BUILDINFO_USBDEVICE_LIST
|
2015-12-05 09:09:28 +08:00
|
|
|
DO_TEST("fullvirt-multiusb");
|
2015-04-02 20:57:54 +08:00
|
|
|
#endif
|
2015-03-20 12:16:11 +08:00
|
|
|
#ifdef LIBXL_HAVE_BUILDINFO_KERNEL
|
2015-12-05 09:09:28 +08:00
|
|
|
DO_TEST("fullvirt-direct-kernel-boot");
|
2016-04-21 05:14:34 +08:00
|
|
|
DO_TEST_FORMAT("fullvirt-direct-kernel-boot-extra", false);
|
|
|
|
DO_TEST_FORMAT("fullvirt-direct-kernel-boot-bogus-extra", false);
|
2015-03-20 12:16:11 +08:00
|
|
|
#endif
|
2019-03-09 02:51:57 +08:00
|
|
|
#ifdef LIBXL_HAVE_BUILDINFO_GRANT_LIMITS
|
|
|
|
DO_TEST("max-gntframes");
|
|
|
|
#endif
|
|
|
|
|
2020-04-08 07:33:26 +08:00
|
|
|
DO_TEST("max-eventchannels");
|
|
|
|
|
2016-05-17 17:34:46 +08:00
|
|
|
DO_TEST("vif-typename");
|
2017-12-07 10:27:47 +08:00
|
|
|
DO_TEST("vif-multi-ip");
|
2016-05-19 16:14:36 +08:00
|
|
|
DO_TEST("usb");
|
2016-06-15 14:00:12 +08:00
|
|
|
DO_TEST("usbctrl");
|
2020-04-14 10:37:07 +08:00
|
|
|
DO_TEST("paravirt-e820_host");
|
2020-04-18 04:19:16 +08:00
|
|
|
#ifdef LIBXL_HAVE_CREATEINFO_PASSTHROUGH
|
|
|
|
DO_TEST("fullvirt-hypervisor-features");
|
|
|
|
#endif
|
2014-12-16 12:30:05 +08:00
|
|
|
|
2019-12-03 18:49:49 +08:00
|
|
|
testXLFreeDriver(driver);
|
2014-12-16 12:30:05 +08:00
|
|
|
|
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-12-03 18:49:49 +08:00
|
|
|
VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("xl"))
|