2014-12-16 04:30:05 +00:00
|
|
|
/*
|
2016-02-16 02:42:27 +00:00
|
|
|
* xlconfigtest.c: Test xl.cfg(5) <-> domXML config conversions
|
2014-12-16 04:30:05 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2007, 2010-2011, 2014 Red Hat, Inc.
|
|
|
|
* Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
* Author: Kiarie Kahurani <davidkiarie4@gmail.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
#include "datatypes.h"
|
|
|
|
#include "xenconfig/xen_xl.h"
|
|
|
|
#include "viralloc.h"
|
|
|
|
#include "virstring.h"
|
|
|
|
#include "testutils.h"
|
|
|
|
#include "testutilsxen.h"
|
2015-01-20 23:45:09 +00:00
|
|
|
#include "libxl/libxl_conf.h"
|
2014-12-16 04:30:05 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
|
|
|
static virCapsPtr caps;
|
|
|
|
static virDomainXMLOptionPtr xmlopt;
|
2016-02-16 02:42:27 +00:00
|
|
|
|
2016-04-20 21:14:34 +00: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 04:30:05 +00:00
|
|
|
/*
|
2016-02-16 02:42:27 +00:00
|
|
|
* Parses domXML to virDomainDef object, which is then converted to xl.cfg(5)
|
|
|
|
* config and compared with expected config.
|
2014-12-16 04:30:05 +00:00
|
|
|
*/
|
|
|
|
static int
|
2016-04-20 21:14:34 +00:00
|
|
|
testCompareParseXML(const char *xlcfg, const char *xml, bool replaceVars)
|
2014-12-16 04:30:05 +00:00
|
|
|
{
|
2016-02-16 02:42:27 +00:00
|
|
|
char *gotxlcfgData = NULL;
|
2014-12-16 04:30:05 +00:00
|
|
|
virConfPtr conf = NULL;
|
|
|
|
virConnectPtr conn = NULL;
|
|
|
|
int wrote = 4096;
|
|
|
|
int ret = -1;
|
|
|
|
virDomainDefPtr def = NULL;
|
2016-04-20 21:14:34 +00:00
|
|
|
char *replacedXML = NULL;
|
2014-12-16 04:30:05 +00:00
|
|
|
|
2016-02-16 02:42:27 +00:00
|
|
|
if (VIR_ALLOC_N(gotxlcfgData, wrote) < 0)
|
2014-12-16 04:30:05 +00:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
conn = virGetConnect();
|
|
|
|
if (!conn) goto fail;
|
|
|
|
|
2016-04-20 21:14:34 +00:00
|
|
|
if (replaceVars) {
|
|
|
|
if (!(replacedXML = testReplaceVarsXML(xml)))
|
|
|
|
goto fail;
|
|
|
|
if (!(def = virDomainDefParseString(replacedXML, caps, xmlopt,
|
2016-09-22 15:14:17 +00:00
|
|
|
NULL, VIR_DOMAIN_XML_INACTIVE)))
|
2016-04-20 21:14:34 +00:00
|
|
|
goto fail;
|
|
|
|
} else {
|
|
|
|
if (!(def = virDomainDefParseFile(xml, caps, xmlopt,
|
2016-09-22 15:14:17 +00:00
|
|
|
NULL, VIR_DOMAIN_XML_INACTIVE)))
|
2016-04-20 21:14:34 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
2014-12-16 04:30:05 +00:00
|
|
|
|
|
|
|
if (!virDomainDefCheckABIStability(def, def)) {
|
|
|
|
fprintf(stderr, "ABI stability check failed on %s", xml);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2015-12-05 02:11:39 +00:00
|
|
|
if (!(conf = xenFormatXL(def, conn)))
|
2014-12-16 04:30:05 +00:00
|
|
|
goto fail;
|
|
|
|
|
2016-02-16 02:42:27 +00:00
|
|
|
if (virConfWriteMem(gotxlcfgData, &wrote, conf) < 0)
|
2014-12-16 04:30:05 +00:00
|
|
|
goto fail;
|
2016-02-16 02:42:27 +00:00
|
|
|
gotxlcfgData[wrote] = '\0';
|
2014-12-16 04:30:05 +00:00
|
|
|
|
2016-05-26 15:01:53 +00:00
|
|
|
if (virTestCompareToFile(gotxlcfgData, xlcfg) < 0)
|
2014-12-16 04:30:05 +00:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
fail:
|
2016-04-20 21:14:34 +00:00
|
|
|
VIR_FREE(replacedXML);
|
2016-02-16 02:42:27 +00:00
|
|
|
VIR_FREE(gotxlcfgData);
|
2014-12-16 04:30:05 +00:00
|
|
|
if (conf)
|
|
|
|
virConfFree(conf);
|
|
|
|
virDomainDefFree(def);
|
|
|
|
virObjectUnref(conn);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2016-02-16 02:42:27 +00:00
|
|
|
|
2014-12-16 04:30:05 +00:00
|
|
|
/*
|
2016-02-16 02:42:27 +00:00
|
|
|
* Parses xl.cfg(5) config to virDomainDef object, which is then converted to
|
|
|
|
* domXML and compared to expected XML.
|
2014-12-16 04:30:05 +00:00
|
|
|
*/
|
|
|
|
static int
|
2016-04-20 21:14:34 +00:00
|
|
|
testCompareFormatXML(const char *xlcfg, const char *xml, bool replaceVars)
|
2014-12-16 04:30:05 +00:00
|
|
|
{
|
2016-02-16 02:42:27 +00:00
|
|
|
char *xlcfgData = NULL;
|
2014-12-16 04:30:05 +00:00
|
|
|
char *gotxml = NULL;
|
|
|
|
virConfPtr conf = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
virConnectPtr conn;
|
|
|
|
virDomainDefPtr def = NULL;
|
2016-04-20 21:14:34 +00:00
|
|
|
char *replacedXML = NULL;
|
2014-12-16 04:30:05 +00:00
|
|
|
|
|
|
|
conn = virGetConnect();
|
|
|
|
if (!conn) goto fail;
|
|
|
|
|
2016-05-26 15:01:52 +00:00
|
|
|
if (virTestLoadFile(xlcfg, &xlcfgData) < 0)
|
2014-12-16 04:30:05 +00:00
|
|
|
goto fail;
|
|
|
|
|
2016-02-16 02:42:27 +00:00
|
|
|
if (!(conf = virConfReadMem(xlcfgData, strlen(xlcfgData), 0)))
|
2014-12-16 04:30:05 +00:00
|
|
|
goto fail;
|
|
|
|
|
2015-12-05 02:11:39 +00:00
|
|
|
if (!(def = xenParseXL(conf, caps, xmlopt)))
|
2014-12-16 04:30:05 +00:00
|
|
|
goto fail;
|
|
|
|
|
2016-02-03 21:40:35 +00:00
|
|
|
if (!(gotxml = virDomainDefFormat(def, caps, VIR_DOMAIN_XML_INACTIVE |
|
2014-12-16 04:30:05 +00:00
|
|
|
VIR_DOMAIN_XML_SECURE)))
|
|
|
|
goto fail;
|
|
|
|
|
2016-04-20 21:14:34 +00: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 04:30:05 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (conf)
|
|
|
|
virConfFree(conf);
|
2016-04-20 21:14:34 +00:00
|
|
|
VIR_FREE(replacedXML);
|
2016-02-16 02:42:27 +00:00
|
|
|
VIR_FREE(xlcfgData);
|
2014-12-16 04:30:05 +00:00
|
|
|
VIR_FREE(gotxml);
|
|
|
|
virDomainDefFree(def);
|
|
|
|
virObjectUnref(conn);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct testInfo {
|
|
|
|
const char *name;
|
|
|
|
int mode;
|
2016-04-20 21:14:34 +00:00
|
|
|
bool replaceVars;
|
2014-12-16 04:30:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
testCompareHelper(const void *data)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
const struct testInfo *info = data;
|
|
|
|
char *xml = NULL;
|
|
|
|
char *cfg = NULL;
|
|
|
|
|
|
|
|
if (virAsprintf(&xml, "%s/xlconfigdata/test-%s.xml",
|
|
|
|
abs_srcdir, info->name) < 0 ||
|
|
|
|
virAsprintf(&cfg, "%s/xlconfigdata/test-%s.cfg",
|
|
|
|
abs_srcdir, info->name) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (info->mode == 0)
|
2016-04-20 21:14:34 +00:00
|
|
|
result = testCompareParseXML(cfg, xml, info->replaceVars);
|
2014-12-16 04:30:05 +00:00
|
|
|
else
|
2016-04-20 21:14:34 +00:00
|
|
|
result = testCompareFormatXML(cfg, xml, info->replaceVars);
|
2014-12-16 04:30:05 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(xml);
|
|
|
|
VIR_FREE(cfg);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!(caps = testXLInitCaps()))
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2015-01-20 23:45:09 +00:00
|
|
|
if (!(xmlopt = libxlCreateXMLConf()))
|
2014-12-16 04:30:05 +00:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2016-04-20 21:14:34 +00:00
|
|
|
#define DO_TEST_PARSE(name, replace) \
|
2014-12-16 04:30:05 +00:00
|
|
|
do { \
|
2016-04-20 21:14:34 +00:00
|
|
|
struct testInfo info0 = { name, 0, replace }; \
|
2016-05-26 15:01:50 +00:00
|
|
|
if (virTestRun("Xen XL-2-XML Parse " name, \
|
|
|
|
testCompareHelper, &info0) < 0) \
|
2014-12-16 04:30:05 +00:00
|
|
|
ret = -1; \
|
2016-01-21 12:29:29 +00:00
|
|
|
} while (0)
|
|
|
|
|
2016-04-20 21:14:34 +00:00
|
|
|
#define DO_TEST_FORMAT(name, replace) \
|
2016-01-21 12:29:29 +00:00
|
|
|
do { \
|
2016-04-20 21:14:34 +00:00
|
|
|
struct testInfo info1 = { name, 1, replace }; \
|
2016-05-26 15:01:50 +00:00
|
|
|
if (virTestRun("Xen XL-2-XML Format " name, \
|
|
|
|
testCompareHelper, &info1) < 0) \
|
2014-12-16 04:30:05 +00:00
|
|
|
ret = -1; \
|
|
|
|
} while (0)
|
|
|
|
|
2016-01-21 12:29:29 +00:00
|
|
|
#define DO_TEST(name) \
|
|
|
|
do { \
|
2016-04-20 21:14:34 +00:00
|
|
|
DO_TEST_PARSE(name, false); \
|
|
|
|
DO_TEST_FORMAT(name, false); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define DO_TEST_REPLACE_VARS(name) \
|
|
|
|
do { \
|
|
|
|
DO_TEST_PARSE(name, true); \
|
|
|
|
DO_TEST_FORMAT(name, true); \
|
2016-01-21 12:29:29 +00:00
|
|
|
} while (0)
|
|
|
|
|
2016-04-20 21:14:34 +00:00
|
|
|
DO_TEST_REPLACE_VARS("fullvirt-ovmf");
|
2015-12-15 21:47:40 +00:00
|
|
|
DO_TEST("paravirt-maxvcpus");
|
2015-12-05 01:09:28 +00:00
|
|
|
DO_TEST("new-disk");
|
2016-04-20 21:14:34 +00:00
|
|
|
DO_TEST_FORMAT("disk-positional-parms-full", false);
|
|
|
|
DO_TEST_FORMAT("disk-positional-parms-partial", false);
|
2016-12-19 09:13:35 +00:00
|
|
|
#ifdef LIBXL_HAVE_QED
|
|
|
|
DO_TEST_FORMAT("disk-qed", false);
|
|
|
|
#endif
|
2015-12-05 01:09:28 +00:00
|
|
|
DO_TEST("spice");
|
|
|
|
DO_TEST("spice-features");
|
2015-12-28 22:26:17 +00:00
|
|
|
DO_TEST("vif-rate");
|
2016-02-23 01:50:19 +00:00
|
|
|
DO_TEST("fullvirt-nohap");
|
2017-01-20 00:19:18 +00:00
|
|
|
DO_TEST("fullvirt-hpet-timer");
|
|
|
|
DO_TEST("fullvirt-tsc-timer");
|
|
|
|
DO_TEST("fullvirt-multi-timer");
|
2015-04-02 12:57:54 +00:00
|
|
|
|
2016-01-21 12:29:29 +00:00
|
|
|
DO_TEST("paravirt-cmdline");
|
2016-04-20 21:14:34 +00:00
|
|
|
DO_TEST_FORMAT("paravirt-cmdline-extra-root", false);
|
|
|
|
DO_TEST_FORMAT("paravirt-cmdline-bogus-extra-root", false);
|
2016-02-11 00:39:18 +00:00
|
|
|
DO_TEST("rbd-multihost-noauth");
|
2016-01-21 12:29:29 +00:00
|
|
|
|
2016-09-26 17:33:18 +00:00
|
|
|
#ifdef LIBXL_HAVE_DEVICE_CHANNEL
|
|
|
|
DO_TEST("channel-pty");
|
|
|
|
DO_TEST("channel-unix");
|
|
|
|
#endif
|
2016-08-18 02:20:50 +00:00
|
|
|
#ifdef LIBXL_HAVE_BUILDINFO_SERIAL_LIST
|
|
|
|
DO_TEST("fullvirt-multiserial");
|
|
|
|
#endif
|
2015-04-02 12:57:54 +00:00
|
|
|
#ifdef LIBXL_HAVE_BUILDINFO_USBDEVICE_LIST
|
2015-12-05 01:09:28 +00:00
|
|
|
DO_TEST("fullvirt-multiusb");
|
2015-04-02 12:57:54 +00:00
|
|
|
#endif
|
2015-03-20 04:16:11 +00:00
|
|
|
#ifdef LIBXL_HAVE_BUILDINFO_KERNEL
|
2015-12-05 01:09:28 +00:00
|
|
|
DO_TEST("fullvirt-direct-kernel-boot");
|
2016-04-20 21:14:34 +00:00
|
|
|
DO_TEST_FORMAT("fullvirt-direct-kernel-boot-extra", false);
|
|
|
|
DO_TEST_FORMAT("fullvirt-direct-kernel-boot-bogus-extra", false);
|
2015-03-20 04:16:11 +00:00
|
|
|
#endif
|
2016-05-17 09:34:46 +00:00
|
|
|
DO_TEST("vif-typename");
|
2016-05-19 08:14:36 +00:00
|
|
|
DO_TEST("usb");
|
2016-06-15 06:00:12 +00:00
|
|
|
DO_TEST("usbctrl");
|
2014-12-16 04:30:05 +00:00
|
|
|
|
|
|
|
virObjectUnref(caps);
|
|
|
|
virObjectUnref(xmlopt);
|
|
|
|
|
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIRT_TEST_MAIN(mymain)
|