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
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-01-30 02:15:54 +08:00
|
|
|
#include <config.h>
|
2007-11-26 20:03:34 +08:00
|
|
|
|
2007-01-20 04:30:05 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
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"
|
Move xen driver code into src/xen/ directory
* src/Makefile.am, src/proxy_internal.c, src/proxy_internal.h
src/sexpr.c, src/sexpr.h, src/xen_unified.c, src/xen_unified.h,
src/xen_internal.c, src/xen_internal.h, src/xen_inotify.c,
src/xen_inotify.h, src/xend_internal.c, src/xend_internal.h,
src/xm_internal.c, src/xm_internal.h, src/xs_internal.c,
src/xs_internal.h: Move to src/xen/ directory
* proxy/Makefile.am, proxy/libvirt_proxy.c, src/Makefile.am,
src/libvirt.c, tests/sexpr2xmltest.c, tests/statstest.c,
tests/xencapstest.c, tests/xmconfigtest.c, tests/xml2sexprtest.c:
Adapt to changed xen location
* src/stats_linux.h, src/stats_linux.c: Remove xen specific block
stats APIs
* src/qemu_driver.c, src/uml_driver.c: Add missing sys/un.h include
uncovered after change to stats_linux.h
* src/xen/block_stats.h, src/xen/block_stats.c: Add xen specific
block stats APIs
2009-09-15 23:38:33 +08:00
|
|
|
#include "xen/xen_driver.h"
|
|
|
|
#include "xen/xm_internal.h"
|
2014-08-15 02:43:32 +08:00
|
|
|
#include "xenconfig/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"
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2013-06-07 16:37:25 +08:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
2008-07-25 21:39:02 +08:00
|
|
|
static virCapsPtr caps;
|
2013-04-01 02:03:42 +08:00
|
|
|
static virDomainXMLOptionPtr xmlopt;
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2011-04-25 06:25:10 +08:00
|
|
|
static int
|
|
|
|
testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
|
|
|
{
|
|
|
|
char *gotxmcfgData = NULL;
|
2007-01-20 04:30:05 +08:00
|
|
|
virConfPtr conf = NULL;
|
|
|
|
int ret = -1;
|
2011-05-03 07:35:18 +08:00
|
|
|
virConnectPtr conn = NULL;
|
2011-04-25 06:25:10 +08:00
|
|
|
int wrote = 4096;
|
2007-04-04 22:19:49 +08:00
|
|
|
struct _xenUnifiedPrivate priv;
|
2008-07-25 21:39:02 +08:00
|
|
|
virDomainDefPtr def = NULL;
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2011-04-25 06:25:10 +08:00
|
|
|
if (VIR_ALLOC_N(gotxmcfgData, wrote) < 0)
|
|
|
|
goto fail;
|
|
|
|
|
2008-11-21 20:16:08 +08:00
|
|
|
conn = virGetConnect();
|
2007-04-04 22:19:49 +08:00
|
|
|
if (!conn) goto fail;
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2007-04-04 22:19:49 +08:00
|
|
|
/* Many puppies died to bring you this code. */
|
|
|
|
priv.xendConfigVersion = xendConfigVersion;
|
2008-07-25 21:39:02 +08:00
|
|
|
priv.caps = caps;
|
2007-04-04 22:19:49 +08:00
|
|
|
conn->privateData = &priv;
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2015-04-23 23:10:15 +08:00
|
|
|
if (!(def = virDomainDefParseFile(xml, caps, xmlopt,
|
|
|
|
VIR_DOMAIN_DEF_PARSE_INACTIVE)))
|
2008-07-25 21:39:02 +08:00
|
|
|
goto fail;
|
|
|
|
|
2014-01-11 01:18:03 +08:00
|
|
|
if (!virDomainDefCheckABIStability(def, def)) {
|
|
|
|
fprintf(stderr, "ABI stability check failed on %s", xml);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2011-02-21 21:40:12 +08:00
|
|
|
if (!(conf = xenFormatXM(conn, def, xendConfigVersion)))
|
2007-01-20 04:30:05 +08:00
|
|
|
goto fail;
|
|
|
|
|
2011-04-25 06:25:10 +08:00
|
|
|
if (virConfWriteMem(gotxmcfgData, &wrote, conf) < 0)
|
2007-01-20 04:30:05 +08:00
|
|
|
goto fail;
|
2011-04-25 06:25:10 +08:00
|
|
|
gotxmcfgData[wrote] = '\0';
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2015-04-23 23:14:26 +08:00
|
|
|
if (virtTestCompareToFile(gotxmcfgData, xmcfg) < 0)
|
2007-01-20 04:30:05 +08:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
fail:
|
2012-02-03 07:16:43 +08:00
|
|
|
VIR_FREE(gotxmcfgData);
|
2007-01-20 04:30:05 +08:00
|
|
|
if (conf)
|
|
|
|
virConfFree(conf);
|
2008-07-25 21:39:02 +08:00
|
|
|
virDomainDefFree(def);
|
Convert public datatypes to inherit from virObject
This converts the following public API datatypes to use the
virObject infrastructure:
virConnectPtr
virDomainPtr
virDomainSnapshotPtr
virInterfacePtr
virNetworkPtr
virNodeDevicePtr
virNWFilterPtr
virSecretPtr
virStreamPtr
virStorageVolPtr
virStoragePoolPtr
The code is significantly simplified, since the mutex in the
virConnectPtr object now only needs to be held when accessing
the per-connection virError object instance. All other operations
are completely lock free.
* src/datatypes.c, src/datatypes.h, src/libvirt.c: Convert
public datatypes to use virObject
* src/conf/domain_event.c, src/phyp/phyp_driver.c,
src/qemu/qemu_command.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c, src/storage/storage_driver.c,
src/vbox/vbox_tmpl.c, src/xen/xend_internal.c,
tests/qemuxml2argvtest.c, tests/qemuxmlnstest.c,
tests/sexpr2xmltest.c, tests/xmconfigtest.c: Convert
to use virObjectUnref/virObjectRef
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-01 00:55:36 +08:00
|
|
|
virObjectUnref(conn);
|
2007-04-04 22:19:49 +08:00
|
|
|
|
2007-01-20 04:30:05 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-04-25 06:25:10 +08:00
|
|
|
static int
|
|
|
|
testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion)
|
|
|
|
{
|
|
|
|
char *xmcfgData = NULL;
|
2007-01-20 04:30:05 +08:00
|
|
|
char *gotxml = NULL;
|
|
|
|
virConfPtr conf = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
virConnectPtr conn;
|
2007-04-04 22:19:49 +08:00
|
|
|
struct _xenUnifiedPrivate priv;
|
2008-07-25 21:39:02 +08:00
|
|
|
virDomainDefPtr def = NULL;
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2008-11-21 20:16:08 +08:00
|
|
|
conn = virGetConnect();
|
2007-04-04 22:19:49 +08:00
|
|
|
if (!conn) goto fail;
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2011-04-25 06:25:10 +08:00
|
|
|
if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
|
2007-01-20 04:30:05 +08:00
|
|
|
goto fail;
|
|
|
|
|
2007-04-04 22:19:49 +08:00
|
|
|
/* Many puppies died to bring you this code. */
|
|
|
|
priv.xendConfigVersion = xendConfigVersion;
|
2008-07-25 21:39:02 +08:00
|
|
|
priv.caps = caps;
|
2007-04-04 22:19:49 +08:00
|
|
|
conn->privateData = &priv;
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2011-04-25 06:25:10 +08:00
|
|
|
if (!(conf = virConfReadMem(xmcfgData, strlen(xmcfgData), 0)))
|
2007-01-20 04:30:05 +08:00
|
|
|
goto fail;
|
|
|
|
|
2011-02-21 21:40:12 +08:00
|
|
|
if (!(def = xenParseXM(conf, priv.xendConfigVersion, priv.caps)))
|
2008-07-25 21:39:02 +08:00
|
|
|
goto fail;
|
|
|
|
|
2014-11-19 00:44:00 +08:00
|
|
|
if (!(gotxml = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_SECURE)))
|
2007-01-20 04:30:05 +08:00
|
|
|
goto fail;
|
|
|
|
|
2015-04-23 23:14:26 +08:00
|
|
|
if (virtTestCompareToFile(gotxml, xml) < 0)
|
2007-01-20 04:30:05 +08:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (conf)
|
|
|
|
virConfFree(conf);
|
2011-04-25 06:25:10 +08:00
|
|
|
VIR_FREE(xmcfgData);
|
2008-07-25 21:39:02 +08:00
|
|
|
VIR_FREE(gotxml);
|
|
|
|
virDomainDefFree(def);
|
Convert public datatypes to inherit from virObject
This converts the following public API datatypes to use the
virObject infrastructure:
virConnectPtr
virDomainPtr
virDomainSnapshotPtr
virInterfacePtr
virNetworkPtr
virNodeDevicePtr
virNWFilterPtr
virSecretPtr
virStreamPtr
virStorageVolPtr
virStoragePoolPtr
The code is significantly simplified, since the mutex in the
virConnectPtr object now only needs to be held when accessing
the per-connection virError object instance. All other operations
are completely lock free.
* src/datatypes.c, src/datatypes.h, src/libvirt.c: Convert
public datatypes to use virObject
* src/conf/domain_event.c, src/phyp/phyp_driver.c,
src/qemu/qemu_command.c, src/qemu/qemu_migration.c,
src/qemu/qemu_process.c, src/storage/storage_driver.c,
src/vbox/vbox_tmpl.c, src/xen/xend_internal.c,
tests/qemuxml2argvtest.c, tests/qemuxmlnstest.c,
tests/sexpr2xmltest.c, tests/xmconfigtest.c: Convert
to use virObjectUnref/virObjectRef
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-08-01 00:55:36 +08:00
|
|
|
virObjectUnref(conn);
|
2007-04-04 22:19:49 +08:00
|
|
|
|
2007-01-20 04:30:05 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-07-17 05:30:30 +08:00
|
|
|
|
2008-04-18 23:28:33 +08:00
|
|
|
struct testInfo {
|
|
|
|
const char *name;
|
|
|
|
int version;
|
|
|
|
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;
|
2011-04-25 06:25:10 +08:00
|
|
|
char *xml = NULL;
|
|
|
|
char *cfg = NULL;
|
2014-12-23 14:36:05 +08:00
|
|
|
char *cfgout = NULL;
|
2011-04-25 06:25:10 +08:00
|
|
|
|
|
|
|
if (virAsprintf(&xml, "%s/xmconfigdata/test-%s.xml",
|
|
|
|
abs_srcdir, info->name) < 0 ||
|
|
|
|
virAsprintf(&cfg, "%s/xmconfigdata/test-%s.cfg",
|
|
|
|
abs_srcdir, info->name) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2008-04-18 23:28:33 +08:00
|
|
|
if (info->mode == 0)
|
2011-04-25 06:25:10 +08:00
|
|
|
result = testCompareParseXML(cfg, xml, info->version);
|
2008-04-18 23:28:33 +08:00
|
|
|
else
|
2011-04-25 06:25:10 +08:00
|
|
|
result = testCompareFormatXML(cfg, xml, info->version);
|
|
|
|
|
2014-03-25 14:53:44 +08:00
|
|
|
cleanup:
|
2012-02-03 07:16:43 +08:00
|
|
|
VIR_FREE(xml);
|
|
|
|
VIR_FREE(cfg);
|
2014-12-23 14:36:05 +08:00
|
|
|
VIR_FREE(cfgout);
|
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
|
|
|
|
2008-07-25 21:39:02 +08:00
|
|
|
if (!(caps = testXenCapsInit()))
|
2012-03-22 19:33:35 +08:00
|
|
|
return EXIT_FAILURE;
|
2008-04-18 23:28:33 +08:00
|
|
|
|
2013-03-14 04:39:34 +08:00
|
|
|
if (!(xmlopt = xenDomainXMLConfInit()))
|
2013-03-05 23:17:24 +08:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2014-12-23 14:36:05 +08:00
|
|
|
#define DO_TEST_PARSE(name, version) \
|
2008-04-18 23:28:33 +08:00
|
|
|
do { \
|
|
|
|
struct testInfo info0 = { name, version, 0 }; \
|
|
|
|
if (virtTestRun("Xen XM-2-XML Parse " name, \
|
2013-09-21 02:13:35 +08:00
|
|
|
testCompareHelper, &info0) < 0) \
|
2008-04-18 23:28:33 +08:00
|
|
|
ret = -1; \
|
2014-12-23 14:36:05 +08:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
|
|
#define DO_TEST_FORMAT(name, version) \
|
|
|
|
do { \
|
|
|
|
struct testInfo info1 = { name, version, 1 }; \
|
2008-04-18 23:28:33 +08:00
|
|
|
if (virtTestRun("Xen XM-2-XML Format " name, \
|
2013-09-21 02:13:35 +08:00
|
|
|
testCompareHelper, &info1) < 0) \
|
2008-04-18 23:28:33 +08:00
|
|
|
ret = -1; \
|
|
|
|
} while (0)
|
|
|
|
|
2014-12-23 14:36:05 +08:00
|
|
|
|
|
|
|
#define DO_TEST(name, version) \
|
|
|
|
do { \
|
|
|
|
DO_TEST_PARSE(name, version); \
|
|
|
|
DO_TEST_FORMAT(name, version); \
|
|
|
|
} while (0)
|
|
|
|
|
2010-08-23 21:43:51 +08:00
|
|
|
DO_TEST("paravirt-old-pvfb", 1);
|
|
|
|
DO_TEST("paravirt-old-pvfb-vncdisplay", 1);
|
2008-04-18 23:28:33 +08:00
|
|
|
DO_TEST("paravirt-new-pvfb", 3);
|
2008-09-09 21:53:58 +08:00
|
|
|
DO_TEST("paravirt-new-pvfb-vncdisplay", 3);
|
2008-04-30 20:30:55 +08:00
|
|
|
DO_TEST("paravirt-net-e1000", 3);
|
2009-04-01 18:16:05 +08:00
|
|
|
DO_TEST("paravirt-net-vifname", 3);
|
2010-10-05 22:18:52 +08:00
|
|
|
DO_TEST("paravirt-vcpu", 2);
|
2008-04-18 23:28:33 +08:00
|
|
|
DO_TEST("fullvirt-old-cdrom", 1);
|
|
|
|
DO_TEST("fullvirt-new-cdrom", 2);
|
|
|
|
DO_TEST("fullvirt-utc", 2);
|
|
|
|
DO_TEST("fullvirt-localtime", 2);
|
|
|
|
DO_TEST("fullvirt-usbtablet", 2);
|
|
|
|
DO_TEST("fullvirt-usbmouse", 2);
|
2008-04-26 22:22:02 +08:00
|
|
|
DO_TEST("fullvirt-serial-file", 2);
|
2011-02-25 22:41:12 +08:00
|
|
|
DO_TEST("fullvirt-serial-dev-2-ports", 2);
|
|
|
|
DO_TEST("fullvirt-serial-dev-2nd-port", 2);
|
2008-04-26 22:22:02 +08:00
|
|
|
DO_TEST("fullvirt-serial-null", 2);
|
|
|
|
DO_TEST("fullvirt-serial-pipe", 2);
|
|
|
|
DO_TEST("fullvirt-serial-pty", 2);
|
|
|
|
DO_TEST("fullvirt-serial-stdio", 2);
|
|
|
|
DO_TEST("fullvirt-serial-tcp", 2);
|
|
|
|
DO_TEST("fullvirt-serial-tcp-telnet", 2);
|
|
|
|
DO_TEST("fullvirt-serial-udp", 2);
|
|
|
|
DO_TEST("fullvirt-serial-unix", 2);
|
|
|
|
|
2011-05-10 19:24:14 +08:00
|
|
|
DO_TEST("fullvirt-force-hpet", 2);
|
|
|
|
DO_TEST("fullvirt-force-nohpet", 2);
|
|
|
|
|
2008-04-26 22:22:02 +08:00
|
|
|
DO_TEST("fullvirt-parallel-tcp", 2);
|
2007-01-20 04:30:05 +08:00
|
|
|
|
2008-05-07 22:04:40 +08:00
|
|
|
DO_TEST("fullvirt-sound", 2);
|
|
|
|
|
2009-12-05 00:01:34 +08:00
|
|
|
DO_TEST("fullvirt-net-ioemu", 2);
|
|
|
|
DO_TEST("fullvirt-net-netfront", 2);
|
|
|
|
|
2014-12-23 14:36:05 +08:00
|
|
|
DO_TEST_FORMAT("fullvirt-default-feature", 2);
|
|
|
|
|
2008-06-25 16:59:37 +08:00
|
|
|
DO_TEST("escape-paths", 2);
|
2008-11-28 19:23:34 +08:00
|
|
|
DO_TEST("no-source-cdrom", 2);
|
2009-04-03 20:38:52 +08:00
|
|
|
DO_TEST("pci-devs", 2);
|
2008-07-25 21:39:02 +08:00
|
|
|
|
2013-02-01 20:26:18 +08:00
|
|
|
virObjectUnref(caps);
|
2013-04-01 02:03:42 +08:00
|
|
|
virObjectUnref(xmlopt);
|
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
|
|
|
|
|
|
|
VIRT_TEST_MAIN(mymain)
|