diff --git a/tests/Makefile.am b/tests/Makefile.am
index e9418ea74e9976534ef418b8d10516e5b003b710..b16d3d5a4c61f23b0d12c1e779e4b8819edf32dc 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -138,6 +138,7 @@ EXTRA_DIST = \
vmx2xmldata \
xencapsdata \
xmconfigdata \
+ xlconfigdata \
xml2sexprdata \
xml2vmxdata \
vmwareverdata \
@@ -227,6 +228,11 @@ if WITH_XEN
test_programs += xml2sexprtest sexpr2xmltest \
xmconfigtest xencapstest statstest reconnect
endif WITH_XEN
+
+if WITH_LIBXL
+test_programs += xlconfigtest
+endif WITH_LIBXL
+
if WITH_QEMU
test_programs += qemuxml2argvtest qemuxml2xmltest qemuxmlnstest \
qemuargv2xmltest qemuhelptest domainsnapshotxml2xmltest \
@@ -477,6 +483,11 @@ sexpr2xmltest_SOURCES = \
testutils.c testutils.h
sexpr2xmltest_LDADD = $(xen_LDADDS)
+xlconfigtest_SOURCES = \
+ xlconfigtest.c testutilsxen.c testutilsxen.h \
+ testutils.c testutils.h
+xlconfigtest_LDADD =$(xen_LDADDS)
+
xmconfigtest_SOURCES = \
xmconfigtest.c testutilsxen.c testutilsxen.h \
testutils.c testutils.h
diff --git a/tests/testutilsxen.c b/tests/testutilsxen.c
index a50a8a2af754c0caf481f484b0214854e76b7a37..df1d1243b2e7ea1a92bb1426dd2cb468c52e8262 100644
--- a/tests/testutilsxen.c
+++ b/tests/testutilsxen.c
@@ -69,3 +69,53 @@ virCapsPtr testXenCapsInit(void)
virObjectUnref(caps);
return NULL;
}
+
+
+virCapsPtr
+testXLInitCaps(void)
+{
+ virCapsPtr caps;
+ virCapsGuestPtr guest;
+ virCapsGuestMachinePtr *machines;
+ int nmachines;
+ static const char *const x86_machines[] = {
+ "xenfv"
+ };
+ static const char *const xen_machines[] = {
+ "xenpv"
+ };
+
+ if ((caps = virCapabilitiesNew(virArchFromHost(),
+ false, false)) == NULL)
+ return NULL;
+ nmachines = ARRAY_CARDINALITY(x86_machines);
+ if ((machines = virCapabilitiesAllocMachines(x86_machines, nmachines)) == NULL)
+ goto cleanup;
+ if ((guest = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_X86_64,
+ "/usr/lib/xen/bin/qemu-dm", NULL,
+ nmachines, machines)) == NULL)
+ goto cleanup;
+ machines = NULL;
+ if (virCapabilitiesAddGuestDomain(guest, "xen", NULL,
+ NULL, 0, NULL) == NULL)
+ goto cleanup;
+ nmachines = ARRAY_CARDINALITY(xen_machines);
+ if ((machines = virCapabilitiesAllocMachines(xen_machines, nmachines)) == NULL)
+ goto cleanup;
+
+ if ((guest = virCapabilitiesAddGuest(caps, "xen", VIR_ARCH_X86_64,
+ "/usr/lib/xen/bin/qemu-dm", NULL,
+ nmachines, machines)) == NULL)
+ goto cleanup;
+ machines = NULL;
+
+ if (virCapabilitiesAddGuestDomain(guest, "xen", NULL,
+ NULL, 0, NULL) == NULL)
+ goto cleanup;
+ return caps;
+
+ cleanup:
+ virCapabilitiesFreeMachines(machines, nmachines);
+ virObjectUnref(caps);
+ return NULL;
+}
diff --git a/tests/testutilsxen.h b/tests/testutilsxen.h
index 54155e5e76f82c35bf344f4ea79feade2f603852..c78350d2d6c9291f290e44d234f62bd3d3f6399b 100644
--- a/tests/testutilsxen.h
+++ b/tests/testutilsxen.h
@@ -1,3 +1,10 @@
-#include "capabilities.h"
+#ifndef _TESTUTILSXEN_H_
+# define _TESTUTILSXEN_H_
+
+# include "capabilities.h"
virCapsPtr testXenCapsInit(void);
+
+virCapsPtr testXLInitCaps(void);
+
+#endif /* _TESTUTILSXEN_H_ */
diff --git a/tests/xlconfigdata/test-new-disk.cfg b/tests/xlconfigdata/test-new-disk.cfg
new file mode 100644
index 0000000000000000000000000000000000000000..b672b4ad32e26a3e39fd8695c9e10d8b0adc2c00
--- /dev/null
+++ b/tests/xlconfigdata/test-new-disk.cfg
@@ -0,0 +1,26 @@
+name = "XenGuest2"
+uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
+maxmem = 579
+memory = 394
+vcpus = 1
+builder = "hvm"
+kernel = "/usr/lib/xen/boot/hvmloader"
+boot = "d"
+pae = 1
+acpi = 1
+apic = 1
+hap = 0
+viridian = 0
+localtime = 0
+on_poweroff = "destroy"
+on_reboot = "restart"
+on_crash = "restart"
+device_model = "/usr/lib/xen/bin/qemu-dm"
+sdl = 0
+vnc = 1
+vncunused = 1
+vnclisten = "127.0.0.1"
+vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ]
+parallel = "none"
+serial = "none"
+disk = [ "/dev/HostVG/XenGuest2,raw,hda,w,backendtype=phy", "/var/lib/libvirt/images/XenGuest2-home,qcow2,hdb,w,backendtype=qdisk", "/root/boot.iso,raw,hdc,r,backendtype=qdisk,devtype=cdrom" ]
diff --git a/tests/xlconfigdata/test-new-disk.xml b/tests/xlconfigdata/test-new-disk.xml
new file mode 100644
index 0000000000000000000000000000000000000000..1c96a62e54219491741d1c861ffc96ffb5d73a96
--- /dev/null
+++ b/tests/xlconfigdata/test-new-disk.xml
@@ -0,0 +1,51 @@
+
+ XenGuest2
+ c7a5fdb2-cdaf-9455-926a-d65c16db1809
+ 592896
+ 403456
+ 1
+
+ hvm
+ /usr/lib/xen/boot/hvmloader
+
+
+
+
+
+
+
+
+ destroy
+ restart
+ restart
+
+ /usr/lib/xen/bin/qemu-dm
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/xlconfigdata/test-spice.cfg b/tests/xlconfigdata/test-spice.cfg
new file mode 100644
index 0000000000000000000000000000000000000000..49aff631a0364b60e2ae1d17789ca9c85be9be1e
--- /dev/null
+++ b/tests/xlconfigdata/test-spice.cfg
@@ -0,0 +1,31 @@
+name = "XenGuest2"
+uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809"
+maxmem = 579
+memory = 394
+vcpus = 1
+builder = "hvm"
+kernel = "/usr/lib/xen/boot/hvmloader"
+boot = "d"
+pae = 1
+acpi = 1
+apic = 1
+hap = 0
+viridian = 0
+localtime = 0
+on_poweroff = "destroy"
+on_reboot = "restart"
+on_crash = "restart"
+device_model = "/usr/lib/xen/bin/qemu-dm"
+vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ]
+parallel = "none"
+serial = "none"
+disk = [ "/dev/HostVG/XenGuest2,raw,hda,w,backendtype=phy", "/root/boot.iso,raw,hdc,r,backendtype=qdisk,devtype=cdrom" ]
+sdl = 0
+vnc = 0
+spice = 1
+spiceport = 590
+spicetls_port = 500
+spicedisable_ticketing = 1
+spicepasswd = "thebeast"
+spicehost = "127.0.0.1"
+spiceagent_mouse = 0
diff --git a/tests/xlconfigdata/test-spice.xml b/tests/xlconfigdata/test-spice.xml
new file mode 100644
index 0000000000000000000000000000000000000000..bd004fcd48cf4a90798db06b17b26fcf1764f347
--- /dev/null
+++ b/tests/xlconfigdata/test-spice.xml
@@ -0,0 +1,46 @@
+
+ XenGuest2
+ c7a5fdb2-cdaf-9455-926a-d65c16db1809
+ 592896
+ 403456
+ 1
+
+ hvm
+ /usr/lib/xen/boot/hvmloader
+
+
+
+
+
+
+
+
+ destroy
+ restart
+ restart
+
+ /usr/lib/xen/bin/qemu-dm
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c
new file mode 100644
index 0000000000000000000000000000000000000000..c2763c03f1e5b4636a7fe3ae9901d86308f3d536
--- /dev/null
+++ b/tests/xlconfigtest.c
@@ -0,0 +1,225 @@
+/*
+ * xlconfigtest.c: Test backend for xl_internal config file handling
+ *
+ * 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
+ * .
+ *
+ * Author: Daniel P. Berrange
+ * Author: Kiarie Kahurani
+ *
+ */
+
+#include
+
+#include
+#include
+#include
+
+#include "internal.h"
+#include "datatypes.h"
+#include "xenconfig/xen_xl.h"
+#include "viralloc.h"
+#include "virstring.h"
+#include "testutils.h"
+#include "testutilsxen.h"
+#include "xen/xen_driver.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+static virCapsPtr caps;
+static virDomainXMLOptionPtr xmlopt;
+/*
+ * parses the xml, creates a domain def and compare with equivalent xm config
+ */
+static int
+testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
+{
+ char *xmlData = NULL;
+ char *xmcfgData = NULL;
+ char *gotxmcfgData = NULL;
+ virConfPtr conf = NULL;
+ virConnectPtr conn = NULL;
+ int wrote = 4096;
+ int ret = -1;
+ virDomainDefPtr def = NULL;
+
+ if (VIR_ALLOC_N(gotxmcfgData, wrote) < 0)
+ goto fail;
+
+ conn = virGetConnect();
+ if (!conn) goto fail;
+
+ if (virtTestLoadFile(xml, &xmlData) < 0)
+ goto fail;
+
+ if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
+ goto fail;
+
+ if (!(def = virDomainDefParseString(xmlData, caps, xmlopt,
+ 1 << VIR_DOMAIN_VIRT_XEN,
+ VIR_DOMAIN_XML_INACTIVE)))
+ goto fail;
+
+ if (!virDomainDefCheckABIStability(def, def)) {
+ fprintf(stderr, "ABI stability check failed on %s", xml);
+ goto fail;
+ }
+
+ if (!(conf = xenFormatXL(def, conn, xendConfigVersion)))
+ goto fail;
+
+ if (virConfWriteMem(gotxmcfgData, &wrote, conf) < 0)
+ goto fail;
+ gotxmcfgData[wrote] = '\0';
+
+ if (STRNEQ(xmcfgData, gotxmcfgData)) {
+ virtTestDifference(stderr, xmcfgData, gotxmcfgData);
+ goto fail;
+ }
+
+ ret = 0;
+
+ fail:
+ VIR_FREE(xmlData);
+ VIR_FREE(xmcfgData);
+ VIR_FREE(gotxmcfgData);
+ if (conf)
+ virConfFree(conf);
+ virDomainDefFree(def);
+ virObjectUnref(conn);
+
+ return ret;
+}
+/*
+ * parses the xl config, develops domain def and compares with equivalent xm config
+ */
+static int
+testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion)
+{
+ char *xmlData = NULL;
+ char *xmcfgData = NULL;
+ char *gotxml = NULL;
+ virConfPtr conf = NULL;
+ int ret = -1;
+ virConnectPtr conn;
+ virDomainDefPtr def = NULL;
+
+ conn = virGetConnect();
+ if (!conn) goto fail;
+
+ if (virtTestLoadFile(xml, &xmlData) < 0)
+ goto fail;
+
+ if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
+ goto fail;
+
+ if (!(conf = virConfReadMem(xmcfgData, strlen(xmcfgData), 0)))
+ goto fail;
+
+ if (!(def = xenParseXL(conf, caps, xendConfigVersion)))
+ goto fail;
+
+ if (!(gotxml = virDomainDefFormat(def, VIR_DOMAIN_XML_INACTIVE |
+ VIR_DOMAIN_XML_SECURE)))
+ goto fail;
+
+ if (STRNEQ(xmlData, gotxml)) {
+ virtTestDifference(stderr, xmlData, gotxml);
+ goto fail;
+ }
+
+ ret = 0;
+
+ fail:
+ if (conf)
+ virConfFree(conf);
+ VIR_FREE(xmlData);
+ VIR_FREE(xmcfgData);
+ VIR_FREE(gotxml);
+ virDomainDefFree(def);
+ virObjectUnref(conn);
+
+ return ret;
+}
+
+
+struct testInfo {
+ const char *name;
+ int version;
+ int mode;
+};
+
+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)
+ result = testCompareParseXML(cfg, xml, info->version);
+ else
+ result = testCompareFormatXML(cfg, xml, info->version);
+
+ cleanup:
+ VIR_FREE(xml);
+ VIR_FREE(cfg);
+
+ return result;
+}
+
+
+static int
+mymain(void)
+{
+ int ret = 0;
+
+ if (!(caps = testXLInitCaps()))
+ return EXIT_FAILURE;
+
+ if (!(xmlopt = xenDomainXMLConfInit()))
+ return EXIT_FAILURE;
+
+#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, \
+ testCompareHelper, &info0) < 0) \
+ ret = -1; \
+ if (virtTestRun("Xen XM-2-XML Format " name, \
+ testCompareHelper, &info1) < 0) \
+ ret = -1; \
+ } while (0)
+
+ DO_TEST("new-disk", 3);
+ DO_TEST("spice", 3);
+
+ virObjectUnref(caps);
+ virObjectUnref(xmlopt);
+
+ return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIRT_TEST_MAIN(mymain)