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

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



add tests for the xen_xl config parser

Signed-off-by: Kiarie Kahurani <davidkiarie4 gmail com>
---
 tests/Makefile.am                                |   9 +-
 tests/testutilsxen.c                             |  50 +++++
 tests/testutilsxen.h                             |   9 +-
 tests/xlconfigdata/test-disk-key-value.cfg       |  27 +++
 tests/xlconfigdata/test-disk-key-value.xml       |  48 +++++
 tests/xlconfigdata/test-fullvirt-cdrom-empty.cfg |  23 +++
 tests/xlconfigdata/test-fullvirt-cdrom-empty.xml |   0
 tests/xlconfigdata/test-fullvirt-new-disk.cfg    |  28 +++
 tests/xlconfigdata/test-fullvirt-new-disk.xml    |  46 +++++
 tests/xlconfigdata/test-fullvirt-spice.cfg       |  32 ++++
 tests/xlconfigdata/test-fullvirt-spice.xml       |  48 +++++
 tests/xlconfigdata/test.cfg                      |  48 +++++
 tests/xlconfigdata/test.xml                      |  48 +++++
 tests/xlconfigtest.c                             | 222 +++++++++++++++++++++++
 14 files changed, 636 insertions(+), 2 deletions(-)
 create mode 100644 tests/xlconfigdata/test-disk-key-value.cfg
 create mode 100644 tests/xlconfigdata/test-disk-key-value.xml
 create mode 100644 tests/xlconfigdata/test-fullvirt-cdrom-empty.cfg
 create mode 100644 tests/xlconfigdata/test-fullvirt-cdrom-empty.xml
 create mode 100644 tests/xlconfigdata/test-fullvirt-new-disk.cfg
 create mode 100644 tests/xlconfigdata/test-fullvirt-new-disk.xml
 create mode 100644 tests/xlconfigdata/test-fullvirt-spice.cfg
 create mode 100644 tests/xlconfigdata/test-fullvirt-spice.xml
 create mode 100644 tests/xlconfigdata/test.cfg
 create mode 100644 tests/xlconfigdata/test.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-disk-key-value.cfg b/tests/xlconfigdata/test-disk-key-value.cfg
new file mode 100644
index 0000000..cbe9b71
--- /dev/null
+++ b/tests/xlconfigdata/test-disk-key-value.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 = [ "format=raw, vdev=hda, backendtype=qdisk, access=rw, target=/dev/HostVG/XenGuest2", "format=raw, vdev=hdc, backendtype=qdisk, access=ro, devtype=cdrom, target=/root/boot.iso" ]
diff --git a/tests/xlconfigdata/test-disk-key-value.xml b/tests/xlconfigdata/test-disk-key-value.xml
new file mode 100644
index 0000000..bf5e756
--- /dev/null
+++ b/tests/xlconfigdata/test-disk-key-value.xml
@@ -0,0 +1,48 @@
+<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='file' device='disk'>
+      <driver name='qemu' type='raw'/>
+      <source file='/dev/HostVG/XenGuest2'/>
+      <target dev='hda' bus='ide'/>
+      <shareable/>
+    </disk>
+    <disk type='file' device='cdrom'>
+      <driver name='qemu' type='raw'/>
+      <source file='/root/boot.iso'/>
+      <target dev='hdc' bus='ide'/>
+      <readonly/>
+    </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-fullvirt-cdrom-empty.cfg b/tests/xlconfigdata/test-fullvirt-cdrom-empty.cfg
new file mode 100644
index 0000000..6626134
--- /dev/null
+++ b/tests/xlconfigdata/test-fullvirt-cdrom-empty.cfg
@@ -0,0 +1,23 @@
+name = "test"
+uuid = "cc2315e7-d26a-307a-438c-6d188ec4c09c"
+maxmem = 382
+memory = 350
+vcpus = 1
+builder = "hvm"
+kernel = "/usr/lib/xen/boot/hvmloader"
+boot = "c"
+pae = 1
+acpi = 1
+apic = 1
+localtime = 0
+on_poweroff = "destroy"
+on_reboot = "destroy"
+on_crash = "destroy"
+device_model = "/usr/lib/xen/bin/qemu-dm"
+sdl = 0
+vnc = 1
+vncunused = 1
+vif = [ "mac=00:16:3e:0a:7b:39,bridge=xenbr0,script=vif-bridge,model=e1000,type=ioemu" ]
+parallel = "none"
+serial = "pty"
+disk = [ "/dev/sda8,w,hda", "r,hdc,cdrom" ]
diff --git a/tests/xlconfigdata/test-fullvirt-cdrom-empty.xml b/tests/xlconfigdata/test-fullvirt-cdrom-empty.xml
new file mode 100644
index 0000000..e69de29
diff --git a/tests/xlconfigdata/test-fullvirt-new-disk.cfg b/tests/xlconfigdata/test-fullvirt-new-disk.cfg
new file mode 100644
index 0000000..31bc189
--- /dev/null
+++ b/tests/xlconfigdata/test-fullvirt-new-disk.cfg
@@ -0,0 +1,28 @@
+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,r,devtype=cdrom" ]
+
diff --git a/tests/xlconfigdata/test-fullvirt-new-disk.xml b/tests/xlconfigdata/test-fullvirt-new-disk.xml
new file mode 100644
index 0000000..330be5c
--- /dev/null
+++ b/tests/xlconfigdata/test-fullvirt-new-disk.xml
@@ -0,0 +1,46 @@
+<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='cdrom'>
+      <driver name='phy' type='raw'/>
+      <source dev='/root/boot.iso'/>
+      <target dev='hdc' bus='ide'/>
+      <readonly/>
+    </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-fullvirt-spice.cfg b/tests/xlconfigdata/test-fullvirt-spice.cfg
new file mode 100644
index 0000000..dd7eb48
--- /dev/null
+++ b/tests/xlconfigdata/test-fullvirt-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,devtype=disk", "/root/boot.iso,raw,hdc,r,devtype=cdrom," ]
+spice = 1
+spicehost = "127.0.0.1"
+spiceport = 590
+spicetls_port = 500
+spicedisable_ticketing = 1
+spicepasswd = "thebeast"
+spiceagent_mouse = 1
+spicevdagent = 1
+spice_clibboard_sharing = 1
diff --git a/tests/xlconfigdata/test-fullvirt-spice.xml b/tests/xlconfigdata/test-fullvirt-spice.xml
new file mode 100644
index 0000000..7008950
--- /dev/null
+++ b/tests/xlconfigdata/test-fullvirt-spice.xml
@@ -0,0 +1,48 @@
+<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'/>
+      <shareable/>
+    </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'/>
+      <mouse mode='server'/>
+    </graphics>
+  </devices>
+</domain>
+
diff --git a/tests/xlconfigdata/test.cfg b/tests/xlconfigdata/test.cfg
new file mode 100644
index 0000000..bf5e756
--- /dev/null
+++ b/tests/xlconfigdata/test.cfg
@@ -0,0 +1,48 @@
+<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='file' device='disk'>
+      <driver name='qemu' type='raw'/>
+      <source file='/dev/HostVG/XenGuest2'/>
+      <target dev='hda' bus='ide'/>
+      <shareable/>
+    </disk>
+    <disk type='file' device='cdrom'>
+      <driver name='qemu' type='raw'/>
+      <source file='/root/boot.iso'/>
+      <target dev='hdc' bus='ide'/>
+      <readonly/>
+    </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.xml b/tests/xlconfigdata/test.xml
new file mode 100644
index 0000000..bf5e756
--- /dev/null
+++ b/tests/xlconfigdata/test.xml
@@ -0,0 +1,48 @@
+<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='file' device='disk'>
+      <driver name='qemu' type='raw'/>
+      <source file='/dev/HostVG/XenGuest2'/>
+      <target dev='hda' bus='ide'/>
+      <shareable/>
+    </disk>
+    <disk type='file' device='cdrom'>
+      <driver name='qemu' type='raw'/>
+      <source file='/root/boot.iso'/>
+      <target dev='hdc' bus='ide'/>
+      <readonly/>
+    </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/xlconfigtest.c b/tests/xlconfigtest.c
new file mode 100644
index 0000000..7b2a143
--- /dev/null
+++ b/tests/xlconfigtest.c
@@ -0,0 +1,222 @@
+/*
+ * 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 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"
+#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_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("fullvirt-new-disk", 7);
+
+    virObjectUnref(caps);
+    virObjectUnref(xmlopt);
+
+    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIRT_TEST_MAIN(mymain)
-- 
1.8.4.5


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