2007-01-19 20:30:05 +00:00
|
|
|
/*
|
|
|
|
* xmconfigtest.c: Test backend for xm_internal config file handling
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Red Hat
|
|
|
|
*
|
|
|
|
* 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-01-29 18:15:54 +00:00
|
|
|
#include <config.h>
|
2007-11-26 12:03:34 +00:00
|
|
|
|
2007-01-19 20:30:05 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2008-04-18 15:28:33 +00:00
|
|
|
#include <unistd.h>
|
2007-01-19 20:30:05 +00:00
|
|
|
|
2007-03-15 07:43:16 +00:00
|
|
|
#ifdef WITH_XEN
|
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 13:56:22 +00:00
|
|
|
|
|
|
|
#include "internal.h"
|
2008-11-04 23:22:06 +00:00
|
|
|
#include "datatypes.h"
|
2007-04-04 14:19:49 +00:00
|
|
|
#include "xen_unified.h"
|
2007-01-19 20:30:05 +00:00
|
|
|
#include "xm_internal.h"
|
|
|
|
#include "testutils.h"
|
2008-07-25 13:39:02 +00:00
|
|
|
#include "testutilsxen.h"
|
|
|
|
#include "memory.h"
|
2007-01-19 20:30:05 +00:00
|
|
|
|
|
|
|
static char *progname;
|
2008-04-18 15:28:33 +00:00
|
|
|
static char *abs_srcdir;
|
2008-07-25 13:39:02 +00:00
|
|
|
static virCapsPtr caps;
|
2007-01-19 20:30:05 +00:00
|
|
|
|
|
|
|
#define MAX_FILE 4096
|
|
|
|
|
2008-04-18 15:28:33 +00:00
|
|
|
static int testCompareParseXML(const char *xmcfg, const char *xml,
|
2007-11-14 10:35:58 +00:00
|
|
|
int xendConfigVersion) {
|
2007-01-19 20:30:05 +00:00
|
|
|
char xmlData[MAX_FILE];
|
|
|
|
char xmcfgData[MAX_FILE];
|
|
|
|
char gotxmcfgData[MAX_FILE];
|
|
|
|
char *xmlPtr = &(xmlData[0]);
|
|
|
|
char *xmcfgPtr = &(xmcfgData[0]);
|
|
|
|
char *gotxmcfgPtr = &(gotxmcfgData[0]);
|
|
|
|
virConfPtr conf = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
virConnectPtr conn;
|
|
|
|
int wrote = MAX_FILE;
|
2007-04-04 14:19:49 +00:00
|
|
|
struct _xenUnifiedPrivate priv;
|
2008-07-25 13:39:02 +00:00
|
|
|
virDomainDefPtr def = NULL;
|
2007-01-19 20:30:05 +00:00
|
|
|
|
2008-11-21 12:16:08 +00:00
|
|
|
conn = virGetConnect();
|
2007-04-04 14:19:49 +00:00
|
|
|
if (!conn) goto fail;
|
2007-01-19 20:30:05 +00:00
|
|
|
|
|
|
|
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (virtTestLoadFile(xmcfg, &xmcfgPtr, MAX_FILE) < 0)
|
|
|
|
goto fail;
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
/* Many puppies died to bring you this code. */
|
|
|
|
priv.xendConfigVersion = xendConfigVersion;
|
2008-07-25 13:39:02 +00:00
|
|
|
priv.caps = caps;
|
2007-04-04 14:19:49 +00:00
|
|
|
conn->privateData = &priv;
|
2007-01-19 20:30:05 +00:00
|
|
|
|
2008-07-25 13:39:02 +00:00
|
|
|
if (!(def = virDomainDefParseString(NULL, caps, xmlPtr)))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!(conf = xenXMDomainConfigFormat(conn, def)))
|
2007-01-19 20:30:05 +00:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (virConfWriteMem(gotxmcfgPtr, &wrote, conf) < 0)
|
|
|
|
goto fail;
|
|
|
|
gotxmcfgPtr[wrote] = '\0';
|
|
|
|
|
2008-04-18 15:28:33 +00:00
|
|
|
if (STRNEQ(xmcfgData, gotxmcfgData)) {
|
|
|
|
virtTestDifference(stderr, xmcfgData, gotxmcfgData);
|
2007-01-19 20:30:05 +00:00
|
|
|
goto fail;
|
2007-07-16 21:30:30 +00:00
|
|
|
}
|
2007-01-19 20:30:05 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (conf)
|
|
|
|
virConfFree(conf);
|
2008-07-25 13:39:02 +00:00
|
|
|
virDomainDefFree(def);
|
2008-11-21 12:16:08 +00:00
|
|
|
virUnrefConnect(conn);
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-01-19 20:30:05 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-04-18 15:28:33 +00:00
|
|
|
static int testCompareFormatXML(const char *xmcfg, const char *xml,
|
2007-11-14 10:35:58 +00:00
|
|
|
int xendConfigVersion) {
|
2007-01-19 20:30:05 +00:00
|
|
|
char xmlData[MAX_FILE];
|
|
|
|
char xmcfgData[MAX_FILE];
|
|
|
|
char *xmlPtr = &(xmlData[0]);
|
|
|
|
char *xmcfgPtr = &(xmcfgData[0]);
|
|
|
|
char *gotxml = NULL;
|
|
|
|
virConfPtr conf = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
virConnectPtr conn;
|
2007-04-04 14:19:49 +00:00
|
|
|
struct _xenUnifiedPrivate priv;
|
2008-07-25 13:39:02 +00:00
|
|
|
virDomainDefPtr def = NULL;
|
2007-01-19 20:30:05 +00:00
|
|
|
|
2008-11-21 12:16:08 +00:00
|
|
|
conn = virGetConnect();
|
2007-04-04 14:19:49 +00:00
|
|
|
if (!conn) goto fail;
|
2007-01-19 20:30:05 +00:00
|
|
|
|
|
|
|
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (virtTestLoadFile(xmcfg, &xmcfgPtr, MAX_FILE) < 0)
|
|
|
|
goto fail;
|
|
|
|
|
2007-04-04 14:19:49 +00:00
|
|
|
/* Many puppies died to bring you this code. */
|
|
|
|
priv.xendConfigVersion = xendConfigVersion;
|
2008-07-25 13:39:02 +00:00
|
|
|
priv.caps = caps;
|
2007-04-04 14:19:49 +00:00
|
|
|
conn->privateData = &priv;
|
2007-01-19 20:30:05 +00:00
|
|
|
|
|
|
|
if (!(conf = virConfReadMem(xmcfgPtr, strlen(xmcfgPtr))))
|
|
|
|
goto fail;
|
|
|
|
|
2008-07-25 13:39:02 +00:00
|
|
|
if (!(def = xenXMDomainConfigParse(conn, conf)))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!(gotxml = virDomainDefFormat(conn, def, VIR_DOMAIN_XML_SECURE)))
|
2007-01-19 20:30:05 +00:00
|
|
|
goto fail;
|
|
|
|
|
2008-04-26 14:22:02 +00:00
|
|
|
if (STRNEQ(xmlData, gotxml)) {
|
|
|
|
virtTestDifference(stderr, xmlData, gotxml);
|
2007-01-19 20:30:05 +00:00
|
|
|
goto fail;
|
2007-07-16 21:30:30 +00:00
|
|
|
}
|
2007-01-19 20:30:05 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (conf)
|
|
|
|
virConfFree(conf);
|
2008-07-25 13:39:02 +00:00
|
|
|
VIR_FREE(gotxml);
|
|
|
|
virDomainDefFree(def);
|
2008-11-21 12:16:08 +00:00
|
|
|
virUnrefConnect(conn);
|
2007-04-04 14:19:49 +00:00
|
|
|
|
2007-01-19 20:30:05 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-07-16 21:30:30 +00:00
|
|
|
|
2008-04-18 15:28:33 +00:00
|
|
|
struct testInfo {
|
|
|
|
const char *name;
|
|
|
|
int version;
|
|
|
|
int mode;
|
|
|
|
};
|
2007-07-18 21:08:22 +00:00
|
|
|
|
2008-04-18 15:28:33 +00:00
|
|
|
static int testCompareHelper(const void *data) {
|
|
|
|
const struct testInfo *info = data;
|
|
|
|
char xml[PATH_MAX];
|
|
|
|
char cfg[PATH_MAX];
|
|
|
|
snprintf(xml, PATH_MAX, "%s/xmconfigdata/test-%s.xml",
|
|
|
|
abs_srcdir, info->name);
|
|
|
|
snprintf(cfg, PATH_MAX, "%s/xmconfigdata/test-%s.cfg",
|
|
|
|
abs_srcdir, info->name);
|
|
|
|
if (info->mode == 0)
|
|
|
|
return testCompareParseXML(cfg, xml, info->version);
|
|
|
|
else
|
|
|
|
return testCompareFormatXML(cfg, xml, info->version);
|
2007-07-18 21:08:22 +00:00
|
|
|
}
|
|
|
|
|
2007-01-19 20:30:05 +00:00
|
|
|
|
2008-05-29 15:31:49 +00:00
|
|
|
static int
|
|
|
|
mymain(int argc, char **argv)
|
2007-01-19 20:30:05 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2008-04-18 15:28:33 +00:00
|
|
|
char cwd[PATH_MAX];
|
2007-01-19 20:30:05 +00:00
|
|
|
|
|
|
|
progname = argv[0];
|
|
|
|
|
|
|
|
if (argc > 1) {
|
|
|
|
fprintf(stderr, "Usage: %s\n", progname);
|
2008-05-29 15:31:49 +00:00
|
|
|
return(EXIT_FAILURE);
|
2007-01-19 20:30:05 +00:00
|
|
|
}
|
|
|
|
|
2008-04-18 15:28:33 +00:00
|
|
|
abs_srcdir = getenv("abs_srcdir");
|
|
|
|
if (!abs_srcdir)
|
|
|
|
abs_srcdir = getcwd(cwd, sizeof(cwd));
|
|
|
|
|
2008-07-25 13:39:02 +00:00
|
|
|
if (!(caps = testXenCapsInit()))
|
|
|
|
return(EXIT_FAILURE);
|
2008-04-18 15:28:33 +00:00
|
|
|
|
|
|
|
#define DO_TEST(name, version) \
|
|
|
|
do { \
|
|
|
|
struct testInfo info0 = { name, version, 0 }; \
|
|
|
|
struct testInfo info1 = { name, version, 1 }; \
|
|
|
|
if (virtTestRun("Xen XM-2-XML Parse " name, \
|
|
|
|
1, testCompareHelper, &info0) < 0) \
|
|
|
|
ret = -1; \
|
|
|
|
if (virtTestRun("Xen XM-2-XML Format " name, \
|
|
|
|
1, testCompareHelper, &info1) < 0) \
|
|
|
|
ret = -1; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
DO_TEST("paravirt-old-pvfb", 2);
|
2008-09-09 13:53:58 +00:00
|
|
|
DO_TEST("paravirt-old-pvfb-vncdisplay", 2);
|
2008-04-18 15:28:33 +00:00
|
|
|
DO_TEST("paravirt-new-pvfb", 3);
|
2008-09-09 13:53:58 +00:00
|
|
|
DO_TEST("paravirt-new-pvfb-vncdisplay", 3);
|
2008-04-30 12:30:55 +00:00
|
|
|
DO_TEST("paravirt-net-e1000", 3);
|
2008-04-18 15:28:33 +00: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 14:22:02 +00:00
|
|
|
DO_TEST("fullvirt-serial-file", 2);
|
|
|
|
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);
|
|
|
|
|
|
|
|
DO_TEST("fullvirt-parallel-tcp", 2);
|
2007-01-19 20:30:05 +00:00
|
|
|
|
2008-05-07 14:04:40 +00:00
|
|
|
DO_TEST("fullvirt-sound", 2);
|
|
|
|
|
2008-06-25 08:59:37 +00:00
|
|
|
DO_TEST("escape-paths", 2);
|
2008-07-25 13:39:02 +00:00
|
|
|
|
|
|
|
virCapabilitiesFree(caps);
|
|
|
|
|
2008-05-29 15:31:49 +00:00
|
|
|
return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
2007-01-19 20:30:05 +00:00
|
|
|
}
|
2008-05-29 15:31:49 +00:00
|
|
|
|
|
|
|
VIRT_TEST_MAIN(mymain)
|
|
|
|
|
2007-03-15 07:43:16 +00:00
|
|
|
#else /* WITHOUT_XEN */
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "libvirt compiled without Xen support\n");
|
2007-03-16 14:55:51 +00:00
|
|
|
return(0);
|
2007-03-15 07:43:16 +00:00
|
|
|
}
|
|
|
|
#endif /* WITH_XEN */
|