Add a test to check node device XML parsing by first parsing
the XML, then re-formatting as XML and finally comparing the
resulting XML to the original XML.
Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
---
tests/.cvsignore | 1 +
tests/.gitignore | 1 +
tests/Makefile.am | 9 ++
tests/nodedevschemadata/DVD_GCC_4247N.xml | 2 -
tests/nodedevschemadata/computer.xml | 2 -
tests/nodedevschemadata/net_00_13_02_b9_f9_d3.xml | 2 -
tests/nodedevschemadata/net_00_15_58_2f_e9_55.xml | 2 -
tests/nodedevschemadata/pci_1002_71c4.xml | 2 -
.../nodedevschemadata/pci_8086_27c5_scsi_host.xml | 2 -
.../pci_8086_27c5_scsi_host_0.xml | 2 -
.../pci_8086_27c5_scsi_host_scsi_device_lun0.xml | 2 -
.../pci_8086_27c5_scsi_host_scsi_host.xml | 2 -
..._serial_SATA_HTS721010G9SA00_MPCZ12Y0GNGWSE.xml | 2 -
.../usb_device_1d6b_1_0000_00_1d_0.xml | 2 -
.../usb_device_1d6b_1_0000_00_1d_0_if0.xml | 2 -
tests/nodedevxml2xmltest.c | 97 ++++++++++++++++++++
16 files changed, 108 insertions(+), 24 deletions(-)
create mode 100644 tests/nodedevxml2xmltest.c
diff --git a/tests/.cvsignore b/tests/.cvsignore
index 679cc20..9d809c9 100644
--- a/tests/.cvsignore
+++ b/tests/.cvsignore
@@ -11,6 +11,7 @@ xmconfigtest
xencapstest
qemuxml2xmltest
qemuxml2argvtest
+nodedevxml2xmltest
nodeinfotest
statstest
qparamtest
diff --git a/tests/.gitignore b/tests/.gitignore
index 679cc20..9d809c9 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -11,6 +11,7 @@ xmconfigtest
xencapstest
qemuxml2xmltest
qemuxml2argvtest
+nodedevxml2xmltest
nodeinfotest
statstest
qparamtest
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 877884f..bec4f60 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -64,6 +64,8 @@ if WITH_QEMU
noinst_PROGRAMS += qemuxml2argvtest qemuxml2xmltest
endif
+noinst_PROGRAMS += nodedevxml2xmltest
+
test_scripts = \
capabilityschematest \
networkschematest \
@@ -110,6 +112,8 @@ if WITH_QEMU
TESTS += qemuxml2argvtest qemuxml2xmltest
endif
+TESTS += nodedevxml2xmltest
+
path_add = $$abs_top_builddir/src$(PATH_SEPARATOR)$$abs_top_builddir/qemud
# NB, automake < 1.10 does not provide the real
@@ -175,6 +179,11 @@ else
EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c testutilsqemu.c testutilsqemu.h
endif
+nodedevxml2xmltest_SOURCES = \
+ nodedevxml2xmltest.c \
+ testutils.c testutils.h
+nodedevxml2xmltest_LDADD = ../src/libvirt_driver_qemu.la $(LDADDS)
+
virshtest_SOURCES = \
virshtest.c \
testutils.c testutils.h
diff --git a/tests/nodedevschemadata/DVD_GCC_4247N.xml
b/tests/nodedevschemadata/DVD_GCC_4247N.xml
index d81e983..aed787a 100644
--- a/tests/nodedevschemadata/DVD_GCC_4247N.xml
+++ b/tests/nodedevschemadata/DVD_GCC_4247N.xml
@@ -13,5 +13,3 @@
</capability>
</capability>
</device>
-
-
diff --git a/tests/nodedevschemadata/computer.xml b/tests/nodedevschemadata/computer.xml
index 4172c0c..4e4b918 100644
--- a/tests/nodedevschemadata/computer.xml
+++ b/tests/nodedevschemadata/computer.xml
@@ -14,5 +14,3 @@
</firmware>
</capability>
</device>
-
-
diff --git a/tests/nodedevschemadata/net_00_13_02_b9_f9_d3.xml
b/tests/nodedevschemadata/net_00_13_02_b9_f9_d3.xml
index 9a09246..970ccca 100644
--- a/tests/nodedevschemadata/net_00_13_02_b9_f9_d3.xml
+++ b/tests/nodedevschemadata/net_00_13_02_b9_f9_d3.xml
@@ -7,5 +7,3 @@
<capability type='80211'/>
</capability>
</device>
-
-
diff --git a/tests/nodedevschemadata/net_00_15_58_2f_e9_55.xml
b/tests/nodedevschemadata/net_00_15_58_2f_e9_55.xml
index b13215c..741c959 100644
--- a/tests/nodedevschemadata/net_00_15_58_2f_e9_55.xml
+++ b/tests/nodedevschemadata/net_00_15_58_2f_e9_55.xml
@@ -7,5 +7,3 @@
<capability type='80203'/>
</capability>
</device>
-
-
diff --git a/tests/nodedevschemadata/pci_1002_71c4.xml
b/tests/nodedevschemadata/pci_1002_71c4.xml
index 305ca32..6de09c1 100644
--- a/tests/nodedevschemadata/pci_1002_71c4.xml
+++ b/tests/nodedevschemadata/pci_1002_71c4.xml
@@ -10,5 +10,3 @@
<vendor id='0x1002'>ATI Technologies Inc</vendor>
</capability>
</device>
-
-
diff --git a/tests/nodedevschemadata/pci_8086_27c5_scsi_host.xml
b/tests/nodedevschemadata/pci_8086_27c5_scsi_host.xml
index 47937f1..3b377a3 100644
--- a/tests/nodedevschemadata/pci_8086_27c5_scsi_host.xml
+++ b/tests/nodedevschemadata/pci_8086_27c5_scsi_host.xml
@@ -5,5 +5,3 @@
<host>0</host>
</capability>
</device>
-
-
diff --git a/tests/nodedevschemadata/pci_8086_27c5_scsi_host_0.xml
b/tests/nodedevschemadata/pci_8086_27c5_scsi_host_0.xml
index b58ee73..a160167 100644
--- a/tests/nodedevschemadata/pci_8086_27c5_scsi_host_0.xml
+++ b/tests/nodedevschemadata/pci_8086_27c5_scsi_host_0.xml
@@ -5,5 +5,3 @@
<host>1</host>
</capability>
</device>
-
-
diff --git a/tests/nodedevschemadata/pci_8086_27c5_scsi_host_scsi_device_lun0.xml
b/tests/nodedevschemadata/pci_8086_27c5_scsi_host_scsi_device_lun0.xml
index 09887a8..5c2dff7 100644
--- a/tests/nodedevschemadata/pci_8086_27c5_scsi_host_scsi_device_lun0.xml
+++ b/tests/nodedevschemadata/pci_8086_27c5_scsi_host_scsi_device_lun0.xml
@@ -9,5 +9,3 @@
<type>disk</type>
</capability>
</device>
-
-
diff --git a/tests/nodedevschemadata/pci_8086_27c5_scsi_host_scsi_host.xml
b/tests/nodedevschemadata/pci_8086_27c5_scsi_host_scsi_host.xml
index 18f9500..8ffb0a5 100644
--- a/tests/nodedevschemadata/pci_8086_27c5_scsi_host_scsi_host.xml
+++ b/tests/nodedevschemadata/pci_8086_27c5_scsi_host_scsi_host.xml
@@ -5,5 +5,3 @@
<host>0</host>
</capability>
</device>
-
-
diff --git
a/tests/nodedevschemadata/storage_serial_SATA_HTS721010G9SA00_MPCZ12Y0GNGWSE.xml
b/tests/nodedevschemadata/storage_serial_SATA_HTS721010G9SA00_MPCZ12Y0GNGWSE.xml
index 43294ac..3595a0b 100644
--- a/tests/nodedevschemadata/storage_serial_SATA_HTS721010G9SA00_MPCZ12Y0GNGWSE.xml
+++ b/tests/nodedevschemadata/storage_serial_SATA_HTS721010G9SA00_MPCZ12Y0GNGWSE.xml
@@ -10,5 +10,3 @@
<size>100030242816</size>
</capability>
</device>
-
-
diff --git a/tests/nodedevschemadata/usb_device_1d6b_1_0000_00_1d_0.xml
b/tests/nodedevschemadata/usb_device_1d6b_1_0000_00_1d_0.xml
index 05999e8..29533e7 100644
--- a/tests/nodedevschemadata/usb_device_1d6b_1_0000_00_1d_0.xml
+++ b/tests/nodedevschemadata/usb_device_1d6b_1_0000_00_1d_0.xml
@@ -8,5 +8,3 @@
<vendor id='0x1d6b'>Linux Foundation</vendor>
</capability>
</device>
-
-
diff --git a/tests/nodedevschemadata/usb_device_1d6b_1_0000_00_1d_0_if0.xml
b/tests/nodedevschemadata/usb_device_1d6b_1_0000_00_1d_0_if0.xml
index bc951ff..9de35c7 100644
--- a/tests/nodedevschemadata/usb_device_1d6b_1_0000_00_1d_0_if0.xml
+++ b/tests/nodedevschemadata/usb_device_1d6b_1_0000_00_1d_0_if0.xml
@@ -8,5 +8,3 @@
<protocol>0</protocol>
</capability>
</device>
-
-
diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c
new file mode 100644
index 0000000..29cdb9e
--- /dev/null
+++ b/tests/nodedevxml2xmltest.c
@@ -0,0 +1,97 @@
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include "internal.h"
+#include "testutils.h"
+#include "node_device_conf.h"
+#include "testutilsqemu.h"
+
+static char *progname;
+static char *abs_srcdir;
+
+#define MAX_FILE 4096
+
+
+static int testCompareXMLToXMLFiles(const char *xml) {
+ char xmlData[MAX_FILE];
+ char *xmlPtr = &(xmlData[0]);
+ char *actual = NULL;
+ int ret = -1;
+ virNodeDeviceDefPtr dev = NULL;
+
+ if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
+ goto fail;
+
+ if (!(dev = virNodeDeviceDefParseString(NULL, xmlData)))
+ goto fail;
+
+ if (!(actual = virNodeDeviceDefFormat(NULL, dev)))
+ goto fail;
+
+ if (STRNEQ(xmlData, actual)) {
+ virtTestDifference(stderr, xmlData, actual);
+ goto fail;
+ }
+
+ ret = 0;
+
+ fail:
+ free(actual);
+ virNodeDeviceDefFree(dev);
+ return ret;
+}
+
+static int testCompareXMLToXMLHelper(const void *data) {
+ char xml[PATH_MAX];
+ snprintf(xml, PATH_MAX, "%s/nodedevschemadata/%s.xml",
+ abs_srcdir, (const char*)data);
+ return testCompareXMLToXMLFiles(xml);
+}
+
+
+static int
+mymain(int argc, char **argv)
+{
+ int ret = 0;
+ char cwd[PATH_MAX];
+
+ progname = argv[0];
+
+ if (argc > 1) {
+ fprintf(stderr, "Usage: %s\n", progname);
+ return (EXIT_FAILURE);
+ }
+
+ abs_srcdir = getenv("abs_srcdir");
+ if (!abs_srcdir)
+ abs_srcdir = getcwd(cwd, sizeof(cwd));
+
+#define DO_TEST(name) \
+ if (virtTestRun("Node device XML-2-XML " name, \
+ 1, testCompareXMLToXMLHelper, (name)) < 0) \
+ ret = -1
+
+ DO_TEST("computer");
+ DO_TEST("DVD_GCC_4247N");
+ DO_TEST("net_00_13_02_b9_f9_d3");
+ DO_TEST("net_00_15_58_2f_e9_55");
+ DO_TEST("pci_1002_71c4");
+ DO_TEST("pci_8086_27c5_scsi_host_0");
+ DO_TEST("pci_8086_27c5_scsi_host_scsi_device_lun0");
+ DO_TEST("pci_8086_27c5_scsi_host_scsi_host");
+ DO_TEST("pci_8086_27c5_scsi_host");
+ DO_TEST("storage_serial_SATA_HTS721010G9SA00_MPCZ12Y0GNGWSE");
+ DO_TEST("usb_device_1d6b_1_0000_00_1d_0_if0");
+ DO_TEST("usb_device_1d6b_1_0000_00_1d_0");
+
+ return (ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
+}
+
+VIRT_TEST_MAIN(mymain)
--
1.6.0.6