2007-01-20 04:30:05 +08:00
|
|
|
/*
|
|
|
|
* xmconfigtest.c: Test backend for xm_internal config file handling
|
|
|
|
*
|
2014-03-17 17:38:38 +08:00
|
|
|
* Copyright (C) 2007, 2010-2011, 2014 Red Hat, Inc.
|
2007-01-20 04: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
|
2012-09-21 06:30:55 +08:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 18:06:23 +08:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2007-01-20 04:30:05 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-01-30 02:15:54 +08:00
|
|
|
#include <config.h>
|
2007-11-26 20:03:34 +08:00
|
|
|
|
2008-04-18 23:28:33 +08:00
|
|
|
#include <unistd.h>
|
2007-01-20 04:30:05 +08:00
|
|
|
|
Wed Dec 5 13:48:00 UTC 2007 Richard W.M. Jones <rjones@redhat.com>
* python/libvir.c, python/libvirt_wrap.h, qemud/qemud.c,
qemud/remote.c, src/internal.h, src/openvz_conf.c,
src/openvz_driver.c, src/proxy_internal.h, src/qemu_conf.c,
src/qemu_driver.c, src/remote_internal.h, src/test.h, src/util.c,
src/xen_unified.c, src/xen_unified.h, tests/nodeinfotest.c,
tests/qemuxml2argvtest.c, tests/qemuxml2xmltest.c, tests/reconnect.c,
tests/sexpr2xmltest.c, tests/virshtest.c, tests/xencapstest.c,
tests/xmconfigtest.c, tests/xml2sexprtest.c:
Change #include <> to #include "" for local includes.
Removed many includes from src/internal.h and put them in
the C files which actually use them.
Removed <ansidecl.h> - unused.
Added a comment around __func__.
Removed a clashing redefinition of VERSION symbol.
All limits (PATH_MAX etc) now done in src/internal.h, so we
don't need to include those headers in other files.
2007-12-05 21:56:22 +08:00
|
|
|
#include "internal.h"
|
2008-11-05 07:22:06 +08:00
|
|
|
#include "datatypes.h"
|
2019-08-24 02:34:46 +08:00
|
|
|
#include "libxl/xen_xm.h"
|
2007-01-20 04:30:05 +08:00
|
|
|
#include "testutils.h"
|
2008-07-25 21:39:02 +08:00
|
|
|
#include "testutilsxen.h"
|
2012-12-13 02:06:53 +08:00
|
|
|
#include "viralloc.h"
|
2013-04-03 18:36:23 +08:00
|
|
|
#include "virstring.h"
|
2016-12-31 05:43:43 +08:00
|
|
|
#include "libxl/libxl_conf.h"
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2013-06-07 16:37:25 +08:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
2021-03-11 15:16:13 +08:00
|
|
|
static libxlDriverPrivate *driver;
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2011-04-25 06:25:10 +08:00
|
|
|
static int
|
2015-12-05 09:09:28 +08:00
|
|
|
testCompareParseXML(const char *xmcfg, const char *xml)
|
2011-04-25 06:25:10 +08:00
|
|
|
{
|
2021-09-05 04:36:12 +08:00
|
|
|
g_autofree char *gotxmcfgData = NULL;
|
2019-10-15 20:47:50 +08:00
|
|
|
g_autoptr(virConf) conf = NULL;
|
2021-08-20 21:53:53 +08:00
|
|
|
g_autoptr(virConnect) conn = NULL;
|
2011-04-25 06:25:10 +08:00
|
|
|
int wrote = 4096;
|
2021-09-05 03:50:02 +08:00
|
|
|
g_autoptr(virDomainDef) def = NULL;
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2020-09-23 07:04:17 +08:00
|
|
|
gotxmcfgData = g_new0(char, wrote);
|
2011-04-25 06:25:10 +08:00
|
|
|
|
2008-11-21 20:16:08 +08:00
|
|
|
conn = virGetConnect();
|
2021-09-05 04:39:45 +08:00
|
|
|
if (!conn)
|
|
|
|
return -1;
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2019-11-27 20:29:21 +08:00
|
|
|
if (!(def = virDomainDefParseFile(xml, driver->xmlopt, NULL,
|
2015-04-23 23:10:15 +08:00
|
|
|
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
|
2021-09-05 04:39:45 +08:00
|
|
|
return -1;
|
2008-07-25 21:39:02 +08:00
|
|
|
|
2019-12-03 18:49:49 +08:00
|
|
|
if (!virDomainDefCheckABIStability(def, def, driver->xmlopt)) {
|
2014-01-11 01:18:03 +08:00
|
|
|
fprintf(stderr, "ABI stability check failed on %s", xml);
|
2021-09-05 04:39:45 +08:00
|
|
|
return -1;
|
2014-01-11 01:18:03 +08:00
|
|
|
}
|
|
|
|
|
2015-12-05 10:11:39 +08:00
|
|
|
if (!(conf = xenFormatXM(conn, def)))
|
2021-09-05 04:39:45 +08:00
|
|
|
return -1;
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2011-04-25 06:25:10 +08:00
|
|
|
if (virConfWriteMem(gotxmcfgData, &wrote, conf) < 0)
|
2021-09-05 04:39:45 +08:00
|
|
|
return -1;
|
2011-04-25 06:25:10 +08:00
|
|
|
gotxmcfgData[wrote] = '\0';
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2016-05-26 23:01:53 +08:00
|
|
|
if (virTestCompareToFile(gotxmcfgData, xmcfg) < 0)
|
2021-09-05 04:39:45 +08:00
|
|
|
return -1;
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2021-09-05 04:39:45 +08:00
|
|
|
return 0;
|
2007-01-20 04:30:05 +08:00
|
|
|
}
|
|
|
|
|
2011-04-25 06:25:10 +08:00
|
|
|
static int
|
2015-12-05 09:09:28 +08:00
|
|
|
testCompareFormatXML(const char *xmcfg, const char *xml)
|
2011-04-25 06:25:10 +08:00
|
|
|
{
|
2021-09-05 04:36:12 +08:00
|
|
|
g_autofree char *xmcfgData = NULL;
|
|
|
|
g_autofree char *gotxml = NULL;
|
2019-10-15 20:47:50 +08:00
|
|
|
g_autoptr(virConf) conf = NULL;
|
2021-09-05 03:50:02 +08:00
|
|
|
g_autoptr(virDomainDef) def = NULL;
|
2019-12-03 18:49:49 +08:00
|
|
|
g_autoptr(libxlDriverConfig) cfg = libxlDriverConfigGet(driver);
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2016-05-26 23:01:52 +08:00
|
|
|
if (virTestLoadFile(xmcfg, &xmcfgData) < 0)
|
2021-09-05 04:39:45 +08:00
|
|
|
return -1;
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2017-08-07 23:12:02 +08:00
|
|
|
if (!(conf = virConfReadString(xmcfgData, 0)))
|
2021-09-05 04:39:45 +08:00
|
|
|
return -1;
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2019-12-03 18:49:49 +08:00
|
|
|
if (!(def = xenParseXM(conf, cfg->caps, driver->xmlopt)))
|
2021-09-05 04:39:45 +08:00
|
|
|
return -1;
|
2008-07-25 21:39:02 +08:00
|
|
|
|
2019-11-27 19:57:34 +08:00
|
|
|
if (!(gotxml = virDomainDefFormat(def, driver->xmlopt, VIR_DOMAIN_DEF_FORMAT_SECURE)))
|
2021-09-05 04:39:45 +08:00
|
|
|
return -1;
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2016-05-26 23:01:53 +08:00
|
|
|
if (virTestCompareToFile(gotxml, xml) < 0)
|
2021-09-05 04:39:45 +08:00
|
|
|
return -1;
|
2007-04-04 22:19:49 +08:00
|
|
|
|
2021-09-05 04:39:45 +08:00
|
|
|
return 0;
|
2007-01-20 04:30:05 +08:00
|
|
|
}
|
|
|
|
|
2007-07-17 05:30:30 +08:00
|
|
|
|
2008-04-18 23:28:33 +08:00
|
|
|
struct testInfo {
|
|
|
|
const char *name;
|
|
|
|
int mode;
|
|
|
|
};
|
2007-07-19 05:08:22 +08:00
|
|
|
|
2011-04-25 06:25:10 +08:00
|
|
|
static int
|
|
|
|
testCompareHelper(const void *data)
|
|
|
|
{
|
|
|
|
int result = -1;
|
2008-04-18 23:28:33 +08:00
|
|
|
const struct testInfo *info = data;
|
2021-09-05 04:36:12 +08:00
|
|
|
g_autofree char *xml = NULL;
|
|
|
|
g_autofree char *cfg = NULL;
|
2011-04-25 06:25:10 +08:00
|
|
|
|
2019-10-22 21:26:14 +08:00
|
|
|
xml = g_strdup_printf("%s/xmconfigdata/test-%s.xml", abs_srcdir, info->name);
|
|
|
|
cfg = g_strdup_printf("%s/xmconfigdata/test-%s.cfg", abs_srcdir, info->name);
|
2011-04-25 06:25:10 +08:00
|
|
|
|
2008-04-18 23:28:33 +08:00
|
|
|
if (info->mode == 0)
|
2015-12-05 09:09:28 +08:00
|
|
|
result = testCompareParseXML(cfg, xml);
|
2008-04-18 23:28:33 +08:00
|
|
|
else
|
2015-12-05 09:09:28 +08:00
|
|
|
result = testCompareFormatXML(cfg, xml);
|
2011-04-25 06:25:10 +08:00
|
|
|
|
|
|
|
return result;
|
2007-07-19 05:08:22 +08:00
|
|
|
}
|
|
|
|
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2008-05-29 23:31:49 +08:00
|
|
|
static int
|
2011-04-30 00:21:20 +08:00
|
|
|
mymain(void)
|
2007-01-20 04:30:05 +08:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2008-04-18 23:28:33 +08:00
|
|
|
|
2019-12-03 18:49:49 +08:00
|
|
|
if (!(driver = testXLInitDriver()))
|
2013-03-05 23:17:24 +08:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2017-11-03 20:09:47 +08:00
|
|
|
#define DO_TEST_PARSE(name) \
|
|
|
|
do { \
|
|
|
|
struct testInfo info0 = { name, 0 }; \
|
|
|
|
if (virTestRun("Xen XM-2-XML Parse " name, \
|
|
|
|
testCompareHelper, &info0) < 0) \
|
|
|
|
ret = -1; \
|
2014-12-23 14:36:05 +08:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
2017-11-03 20:09:47 +08:00
|
|
|
#define DO_TEST_FORMAT(name) \
|
|
|
|
do { \
|
|
|
|
struct testInfo info1 = { name, 1 }; \
|
|
|
|
if (virTestRun("Xen XM-2-XML Format " name, \
|
|
|
|
testCompareHelper, &info1) < 0) \
|
|
|
|
ret = -1; \
|
2008-04-18 23:28:33 +08:00
|
|
|
} while (0)
|
|
|
|
|
2014-12-23 14:36:05 +08:00
|
|
|
|
2017-11-03 20:09:47 +08:00
|
|
|
#define DO_TEST(name) \
|
|
|
|
do { \
|
|
|
|
DO_TEST_PARSE(name); \
|
|
|
|
DO_TEST_FORMAT(name); \
|
2014-12-23 14:36:05 +08:00
|
|
|
} while (0)
|
|
|
|
|
2015-12-05 09:09:28 +08:00
|
|
|
DO_TEST("paravirt-new-pvfb");
|
|
|
|
DO_TEST("paravirt-new-pvfb-vncdisplay");
|
|
|
|
DO_TEST("paravirt-net-e1000");
|
2019-01-19 04:46:56 +08:00
|
|
|
DO_TEST("paravirt-net-fakemodel");
|
2015-12-05 09:09:28 +08:00
|
|
|
DO_TEST("paravirt-net-vifname");
|
|
|
|
DO_TEST("paravirt-vcpu");
|
2015-12-16 05:47:40 +08:00
|
|
|
DO_TEST("paravirt-maxvcpus");
|
2018-05-24 05:09:45 +08:00
|
|
|
DO_TEST_FORMAT("paravirt-root");
|
|
|
|
DO_TEST_FORMAT("paravirt-extra-root");
|
2015-12-05 09:09:28 +08:00
|
|
|
DO_TEST("fullvirt-new-cdrom");
|
|
|
|
DO_TEST("fullvirt-utc");
|
|
|
|
DO_TEST("fullvirt-localtime");
|
|
|
|
DO_TEST("fullvirt-usbtablet");
|
|
|
|
DO_TEST("fullvirt-usbmouse");
|
|
|
|
DO_TEST("fullvirt-serial-file");
|
|
|
|
DO_TEST("fullvirt-serial-null");
|
|
|
|
DO_TEST("fullvirt-serial-pipe");
|
|
|
|
DO_TEST("fullvirt-serial-pty");
|
|
|
|
DO_TEST("fullvirt-serial-stdio");
|
|
|
|
DO_TEST("fullvirt-serial-tcp");
|
|
|
|
DO_TEST("fullvirt-serial-tcp-telnet");
|
|
|
|
DO_TEST("fullvirt-serial-udp");
|
|
|
|
DO_TEST("fullvirt-serial-unix");
|
|
|
|
|
|
|
|
DO_TEST("fullvirt-force-hpet");
|
|
|
|
DO_TEST("fullvirt-force-nohpet");
|
2016-02-23 09:50:19 +08:00
|
|
|
DO_TEST("fullvirt-nohap");
|
2015-12-05 09:09:28 +08:00
|
|
|
|
|
|
|
DO_TEST("fullvirt-parallel-tcp");
|
|
|
|
|
|
|
|
DO_TEST("fullvirt-sound");
|
|
|
|
|
|
|
|
DO_TEST("fullvirt-net-netfront");
|
|
|
|
|
|
|
|
DO_TEST_FORMAT("fullvirt-default-feature");
|
|
|
|
|
|
|
|
DO_TEST("escape-paths");
|
|
|
|
DO_TEST("no-source-cdrom");
|
|
|
|
DO_TEST("pci-devs");
|
2020-08-11 06:58:59 +08:00
|
|
|
DO_TEST_FORMAT("pci-dev-syntax");
|
2008-07-25 21:39:02 +08:00
|
|
|
|
2016-05-19 14:24:56 +08:00
|
|
|
DO_TEST("disk-drv-blktap-raw");
|
|
|
|
DO_TEST("disk-drv-blktap2-raw");
|
|
|
|
|
2019-12-03 18:49:49 +08:00
|
|
|
testXLFreeDriver(driver);
|
2008-07-25 21:39:02 +08:00
|
|
|
|
2014-03-17 17:38:38 +08:00
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
2007-01-20 04:30:05 +08:00
|
|
|
}
|
2008-05-29 23:31:49 +08:00
|
|
|
|
2019-12-03 18:49:49 +08:00
|
|
|
VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("xl"))
|