[PATCH V2 4/4] tests: Tests for the xen-xl parser

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



add tests for the xen_xl config parser

Signed-off-by: Kiarie Kahurani <davidkiarie4@xxxxxxxxx>
---
 tests/Makefile.am                    |   9 +-
 tests/testutilsxen.c                 |  50 ++++++++
 tests/testutilsxen.h                 |   9 +-
 tests/xlconfigdata/test-new-disk.cfg |  27 +++++
 tests/xlconfigdata/test-new-disk.xml |  45 +++++++
 tests/xlconfigdata/test-spice.cfg    |  32 +++++
 tests/xlconfigdata/test-spice.xml    |  45 +++++++
 tests/xlconfigtest.c                 | 224 +++++++++++++++++++++++++++++++++++
 8 files changed, 439 insertions(+), 2 deletions(-)
 create mode 100644 tests/xlconfigdata/test-new-disk.cfg
 create mode 100644 tests/xlconfigdata/test-new-disk.xml
 create mode 100644 tests/xlconfigdata/test-spice.cfg
 create mode 100644 tests/xlconfigdata/test-spice.xml
 create mode 100644 tests/xlconfigtest.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index d6c3cfb..82b0099 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -136,6 +136,7 @@ EXTRA_DIST =		\
 	vmx2xmldata \
 	xencapsdata \
 	xmconfigdata \
+	xlconfigdata \
 	xml2sexprdata \
 	xml2vmxdata \
 	vmwareverdata \
@@ -220,7 +221,8 @@ ssh_LDADD = $(COVERAGE_LDFLAGS)
 
 if WITH_XEN
 test_programs += xml2sexprtest sexpr2xmltest \
-	xmconfigtest xencapstest statstest reconnect
+	xmconfigtest xencapstest statstest reconnect \
+	xlconfigtest
 endif WITH_XEN
 if WITH_QEMU
 test_programs += qemuxml2argvtest qemuxml2xmltest qemuxmlnstest \
@@ -468,6 +470,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 a50a8a2..df1d124 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 54155e5..c78350d 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 0000000..d83c181
--- /dev/null
+++ b/tests/xlconfigdata/test-new-disk.cfg
@@ -0,0 +1,27 @@
+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
+rtc_timeoffset = 0
+localtime = 1
+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" ]
+parallel = "none"
+serial = "none"
+disk = [ "/dev/HostVG/XenGuest2,raw,hda,w,", "/root/boot.iso,raw,hdc,w," ]
diff --git a/tests/xlconfigdata/test-new-disk.xml b/tests/xlconfigdata/test-new-disk.xml
new file mode 100644
index 0000000..504d4df
--- /dev/null
+++ b/tests/xlconfigdata/test-new-disk.xml
@@ -0,0 +1,45 @@
+<domain type='xen'>
+  <name>XenGuest2</name>
+  <uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>592896</memory>
+  <currentMemory unit='KiB'>403456</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='xenfv'>hvm</type>
+    <loader>/usr/lib/xen/boot/hvmloader</loader>
+    <boot dev='cdrom'/>
+  </os>
+  <features>
+    <acpi/>
+    <apic/>
+    <pae/>
+  </features>
+  <clock offset='variable' adjustment='0' basis='localtime'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <devices>
+    <emulator>/usr/lib/xen/bin/qemu-dm</emulator>
+    <disk type='block' device='disk'>
+      <driver name='phy' type='raw'/>
+      <source dev='/dev/HostVG/XenGuest2'/>
+      <target dev='hda' bus='ide'/>
+    </disk>
+    <disk type='block' device='disk'>
+      <driver name='phy' type='raw'/>
+      <source dev='/root/boot.iso'/>
+      <target dev='hdc' bus='ide'/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='00:16:3e:66:92:9c'/>
+      <source bridge='xenbr1'/>
+      <script path='vif-bridge'/>
+      <model type='e1000'/>
+    </interface>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
+      <listen type='address' address='127.0.0.1'/>
+    </graphics>
+  </devices>
+</domain>
diff --git a/tests/xlconfigdata/test-spice.cfg b/tests/xlconfigdata/test-spice.cfg
new file mode 100644
index 0000000..f7aa55c
--- /dev/null
+++ b/tests/xlconfigdata/test-spice.cfg
@@ -0,0 +1,32 @@
+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
+rtc_timeoffset = 0
+localtime = 1
+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" ]
+parallel = "none"
+serial = "none"
+disk = [ "/dev/HostVG/XenGuest2,raw,hda,w,", "/root/boot.iso,raw,hdc,w," ]
+sdl = 0
+vnc = 0
+spice = 1
+spicehost = "127.0.0.1"
+spiceport = 590
+spicetls_port = 500
+spicedisable_ticketing = 1
+spicepasswd = "thebeast"
+spiceagent_mouse = 0
diff --git a/tests/xlconfigdata/test-spice.xml b/tests/xlconfigdata/test-spice.xml
new file mode 100644
index 0000000..1e3f78d
--- /dev/null
+++ b/tests/xlconfigdata/test-spice.xml
@@ -0,0 +1,45 @@
+<domain type='xen'>
+  <name>XenGuest2</name>
+  <uuid>c7a5fdb2-cdaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>592896</memory>
+  <currentMemory unit='KiB'>403456</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='xenfv'>hvm</type>
+    <loader>/usr/lib/xen/boot/hvmloader</loader>
+    <boot dev='cdrom'/>
+  </os>
+  <features>
+    <acpi/>
+    <apic/>
+    <pae/>
+  </features>
+  <clock offset='variable' adjustment='0' basis='localtime'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <devices>
+    <emulator>/usr/lib/xen/bin/qemu-dm</emulator>
+    <disk type='block' device='disk'>
+      <driver name='phy' type='raw'/>
+      <source dev='/dev/HostVG/XenGuest2'/>
+      <target dev='hda' bus='ide'/>
+    </disk>
+    <disk type='block' device='disk'>
+      <driver name='phy' type='raw'/>
+      <source dev='/root/boot.iso'/>
+      <target dev='hdc' bus='ide'/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='00:16:3e:66:92:9c'/>
+      <source bridge='xenbr1'/>
+      <script path='vif-bridge'/>
+      <model type='e1000'/>
+    </interface>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <graphics type='spice' port='590' tlsPort='500' autoport='no' listen='127.0.0.1' passwd='thebeast'>
+      <listen type='address' address='127.0.0.1'/>
+    </graphics>
+  </devices>
+</domain>
diff --git a/tests/xlconfigtest.c b/tests/xlconfigtest.c
new file mode 100644
index 0000000..b966c15
--- /dev/null
+++ b/tests/xlconfigtest.c
@@ -0,0 +1,224 @@
+/*
+ * xlconfigtest.c: Test backend for xl_internal config file handling
+ *
+ * Copyright (C) 2007, 2010-2011, 2014 Red Hat, Inc.
+ *
+ * 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@xxxxxxxxxx>
+ * Author: Kiarie Kahurani <davidkiarie4@xxxxxxxxx>
+ *
+ */
+
+#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"
+#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)
-- 
1.8.4.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]