]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Added test suite for the XML <-> XM config file conversion
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 19 Jan 2007 20:30:05 +0000 (20:30 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 19 Jan 2007 20:30:05 +0000 (20:30 +0000)
16 files changed:
ChangeLog
configure.in
tests/.cvsignore
tests/Makefile.am
tests/testutils.c
tests/xmconfigdata/.cvsignore [new file with mode: 0644]
tests/xmconfigdata/Makefile.am [new file with mode: 0644]
tests/xmconfigdata/test-fullvirt-new-cdrom.cfg [new file with mode: 0755]
tests/xmconfigdata/test-fullvirt-new-cdrom.xml [new file with mode: 0644]
tests/xmconfigdata/test-fullvirt-old-cdrom.cfg [new file with mode: 0755]
tests/xmconfigdata/test-fullvirt-old-cdrom.xml [new file with mode: 0644]
tests/xmconfigdata/test-paravirt-new-pvfb.cfg [new file with mode: 0755]
tests/xmconfigdata/test-paravirt-new-pvfb.xml [new file with mode: 0644]
tests/xmconfigdata/test-paravirt-old-pvfb.cfg [new file with mode: 0755]
tests/xmconfigdata/test-paravirt-old-pvfb.xml [new file with mode: 0644]
tests/xmconfigtest.c [new file with mode: 0644]

index 5a92b114a212c5e59ae03bb8533d051b379d1aa3..653763284205635f1bf53457d0d93d0bda71d006 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Fri Jan 19 15:28:13 EST 2007 Daniel Berrange <berrange@redhat.com>
+
+       * tests/xmconfigtest.c: Test suite to check conversion from
+       XML to XM config files, and the reverse
+       * tests/xmconfigdata/*.xml: Source XML files for the test
+       suite
+       * tests/xmconfigdata/*.cfg: Source XM config files for the
+       test suite
+       * configure.ac, tests/Makefile.am: Added xmconfigdata subdir
+       * tests/xmconfigdata/Makefile.am: Include config files when
+       doing a make dist.
+
 Fri Jan 19 15:23:13 EST 2007 Daniel Berrange <berrange@redhat.com>
 
        * src/xm_internal.c: Finished off the conversion from XML
index 43ef604fd459407a365c9305988fd3f9a72d282d..aae3217cb130c7964b21db23035cfdacd8a39ec8 100644 (file)
@@ -269,4 +269,5 @@ AC_OUTPUT(Makefile src/Makefile include/Makefile docs/Makefile \
           tests/Makefile proxy/Makefile \
           tests/xml2sexprdata/Makefile \
           tests/sexpr2xmldata/Makefile \
+          tests/xmconfigdata/Makefile \
           tests/virshdata/Makefile tests/confdata/Makefile)
index 5057aeab33277a73e6904b283c83558705c3b0d3..1fd64b3b0eb55d3d3ad8783ddf37c75320dee345 100644 (file)
@@ -8,3 +8,4 @@ xml2sexprtest
 virshtest
 conftest
 reconnect
+xmconfigtest
index 8ee3cf3217a8f2968b1fdedefa812d3200914114..b045cef3cceed8a48a9f2a7f65c51ee66ed6cf7c 100644 (file)
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in
 
-SUBDIRS = virshdata confdata sexpr2xmldata xml2sexprdata
+SUBDIRS = virshdata confdata sexpr2xmldata xml2sexprdata xmconfigdata
 
 LIBVIRT = $(top_builddir)/src/.libs/libvirt.a
 
@@ -20,9 +20,9 @@ LDADDS = \
 EXTRA_DIST = xmlrpcserver.py test_conf.sh
 
 noinst_PROGRAMS = xmlrpctest xml2sexprtest sexpr2xmltest virshtest conftest \
-       reconnect
+       reconnect xmconfigtest
 
-TESTS = xml2sexprtest sexpr2xmltest virshtest test_conf.sh reconnect
+TESTS = xml2sexprtest sexpr2xmltest virshtest test_conf.sh reconnect xmconfigtest
 
 valgrind:
        $(MAKE) check TESTS_ENVIRONMENT="valgrind --quiet --leak-check=full"
@@ -49,6 +49,12 @@ sexpr2xmltest_SOURCES = \
 sexpr2xmltest_LDFLAGS =
 sexpr2xmltest_LDADD = $(LDADDS)
 
+xmconfigtest_SOURCES = \
+       xmconfigtest.c \
+       testutils.c testutils.h
+xmconfigtest_LDFLAGS =
+xmconfigtest_LDADD = $(LDADDS)
+
 virshtest_SOURCES = \
        virshtest.c \
        testutils.c testutils.h
index d6af4965cbd92b89e6b0418af04423ab775b9a82..b32716aaa5ea02e300b11818baed01fca171b17d 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * utils.c: basic test utils
+ * testutils.c: basic test utils
  *
- * Copyright (C) 2005 Red Hat, Inc.
+ * Copyright (C) 2005-2007 Red Hat, Inc.
  *
  * See COPYING.LIB for the License of this software
  *
 #include "testutils.h"
 
 #define GETTIMEOFDAY(T) gettimeofday(T, NULL)
-#define DIFF_MSEC(T, U) \
-               ((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 + \
-                  ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
+#define DIFF_MSEC(T, U)                                 \
+    ((((int) ((T)->tv_sec - (U)->tv_sec)) * 1000000.0 +        \
+      ((int) ((T)->tv_usec - (U)->tv_usec))) / 1000.0)
 
 double
 virtTestCountAverage(double *items, int nitems)
 {
-       long double sum = 0;
-       int i;
+    long double sum = 0;
+    int i;
 
-       for (i=1; i < nitems; i++)
-               sum += items[i];
+    for (i=1; i < nitems; i++)
+        sum += items[i];
 
-       return (double) (sum / nitems);
+    return (double) (sum / nitems);
 }
 
-/* 
+/*
  * Runs test and count average time (if the nloops is grater than 1)
- * 
- * returns: -1 = error, 0 = success 
+ *
+ * returns: -1 = error, 0 = success
  */
 int
 virtTestRun(const char *title, int nloops, int (*body)(void *data), void *data)
 {
-       int i, ret = 0;
-       double *ts = NULL;
-       
-       if (nloops > 1 && (ts = calloc(nloops, 
-                               sizeof(double)))==NULL)
-               return -1;
-       
-       for (i=0; i < nloops; i++) {
-               struct timeval before, after;
-
-               if (ts)
-                       GETTIMEOFDAY(&before);
-               if ((ret = body(data)) != 0)
-                       break;
-               if (ts) {
-                       GETTIMEOFDAY(&after);
-                       ts[i] = DIFF_MSEC(&after, &before);
-               }
-       }
-       if (ret == 0 && ts)
-               fprintf(stderr, "%-50s ... OK     [%.5f ms]\n", title, 
-                               virtTestCountAverage(ts, nloops));
-       else if (ret == 0)
-               fprintf(stderr, "%-50s ... OK\n", title);
-       else
-               fprintf(stderr, "%-50s ... FAILED\n", title);
-
-       if (ts)
-               free(ts);
-       return ret;  
+    int i, ret = 0;
+    double *ts = NULL;
+
+    if (nloops > 1 && (ts = calloc(nloops,
+                                   sizeof(double)))==NULL)
+        return -1;
+
+    for (i=0; i < nloops; i++) {
+        struct timeval before, after;
+
+        if (ts)
+            GETTIMEOFDAY(&before);
+        if ((ret = body(data)) != 0)
+            break;
+        if (ts)        {
+            GETTIMEOFDAY(&after);
+            ts[i] = DIFF_MSEC(&after, &before);
+        }
+    }
+    if (ret == 0 && ts)
+        fprintf(stderr, "%-50s ... OK     [%.5f ms]\n", title,
+                virtTestCountAverage(ts, nloops));
+    else if (ret == 0)
+        fprintf(stderr, "%-50s ... OK\n", title);
+    else
+        fprintf(stderr, "%-50s ... FAILED\n", title);
+
+    if (ts)
+        free(ts);
+    return ret;
 }
 
 int virtTestLoadFile(const char *name,
-                    char **buf,
-                    int buflen) {
+                     char **buf,
+                     int buflen) {
     FILE *fp = fopen(name, "r");
     struct stat st;
-    
+
     if (!fp)
         return -1;
 
@@ -98,9 +98,11 @@ int virtTestLoadFile(const char *name,
         return -1;
     }
 
-    if (fread(*buf, st.st_size, 1, fp) != 1) {
-        fclose(fp);
-        return -1;
+    if (st.st_size) {
+        if (fread(*buf, st.st_size, 1, fp) != 1) {
+            fclose(fp);
+            return -1;
+        }
     }
     (*buf)[st.st_size] = '\0';
 
@@ -110,89 +112,99 @@ int virtTestLoadFile(const char *name,
 
 static
 void virtTestCaptureProgramExecChild(const char *const argv[],
-                                    int pipefd) {
-  int i;
-  int open_max;
-  int stdinfd = -1;
-  int stderrfd = -1;
-  const char *const env[] = {
-    "LANG=C",
-    NULL
-  };
-  
-  if ((stdinfd = open(_PATH_DEVNULL, O_RDONLY)) < 0)
-    goto cleanup;
-  if ((stderrfd = open(_PATH_DEVNULL, O_WRONLY)) < 0)
-    goto cleanup;
-
-  open_max = sysconf (_SC_OPEN_MAX);
-  for (i = 0; i < open_max; i++) {
-    if (i != stdinfd &&
-       i != stderrfd &&
-       i != pipefd)
-      close(i);
-  }
-
-  if (dup2(stdinfd, STDIN_FILENO) != STDIN_FILENO)
-    goto cleanup;
-  if (dup2(pipefd, STDOUT_FILENO) != STDOUT_FILENO)
-    goto cleanup;
-  if (dup2(stderrfd, STDERR_FILENO) != STDERR_FILENO)
-    goto cleanup;
-  
-  /* SUS is crazy here, hence the cast */
-  execve(argv[0], (char *const*)argv, (char *const*)env);
+                                     int pipefd) {
+    int i;
+    int open_max;
+    int stdinfd = -1;
+    int stderrfd = -1;
+    const char *const env[] = {
+        "LANG=C",
+        NULL
+    };
+
+    if ((stdinfd = open(_PATH_DEVNULL, O_RDONLY)) < 0)
+        goto cleanup;
+    if ((stderrfd = open(_PATH_DEVNULL, O_WRONLY)) < 0)
+        goto cleanup;
+
+    open_max = sysconf (_SC_OPEN_MAX);
+    for (i = 0; i < open_max; i++) {
+        if (i != stdinfd &&
+            i != stderrfd &&
+            i != pipefd)
+            close(i);
+    }
+
+    if (dup2(stdinfd, STDIN_FILENO) != STDIN_FILENO)
+        goto cleanup;
+    if (dup2(pipefd, STDOUT_FILENO) != STDOUT_FILENO)
+        goto cleanup;
+    if (dup2(stderrfd, STDERR_FILENO) != STDERR_FILENO)
+        goto cleanup;
+
+    /* SUS is crazy here, hence the cast */
+    execve(argv[0], (char *const*)argv, (char *const*)env);
 
  cleanup:
-  if (stdinfd != -1)
-    close(stdinfd);
-  if (stderrfd != -1)
-    close(stderrfd);
+    if (stdinfd != -1)
+        close(stdinfd);
+    if (stderrfd != -1)
+        close(stderrfd);
 }
 
 
 int virtTestCaptureProgramOutput(const char *const argv[],
-                                char **buf,
-                                int buflen) {
-  int pipefd[2];
-  
-  if (pipe(pipefd) < 0)
-    return -1;
-
-  int pid = fork();
-  switch (pid) {
+                                 char **buf,
+                                 int buflen) {
+    int pipefd[2];
+
+    if (pipe(pipefd) < 0)
+        return -1;
+
+    int pid = fork();
+    switch (pid) {
     case 0:
         close(pipefd[0]);
-       virtTestCaptureProgramExecChild(argv, pipefd[1]);
-       
-       close(pipefd[1]);
-       _exit(1);
-       
+        virtTestCaptureProgramExecChild(argv, pipefd[1]);
+
+        close(pipefd[1]);
+        _exit(1);
+
     case -1:
         return -1;
-      
+
     default:
-      {
-       int got = 0;
-       int ret = -1;
-       int want = buflen-1;
+        {
+            int got = 0;
+            int ret = -1;
+            int want = buflen-1;
 
-       close(pipefd[1]);
+            close(pipefd[1]);
 
-       while (want) {
-         if ((ret = read(pipefd[0], (*buf)+got, want)) <= 0)
-           break;
-         got += ret;
-         want -= ret;
-       }
-       close(pipefd[0]);
+            while (want) {
+                if ((ret = read(pipefd[0], (*buf)+got, want)) <= 0)
+                    break;
+                got += ret;
+                want -= ret;
+            }
+            close(pipefd[0]);
 
-       if (!ret)
-         (*buf)[got] = '\0';
+            if (!ret)
+                (*buf)[got] = '\0';
 
-       waitpid(pid, NULL, 0);
+            waitpid(pid, NULL, 0);
 
-       return ret;
-      }
-  }
+            return ret;
+        }
+    }
 }
+
+
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ *  tab-width: 4
+ * End:
+ */
diff --git a/tests/xmconfigdata/.cvsignore b/tests/xmconfigdata/.cvsignore
new file mode 100644 (file)
index 0000000..282522d
--- /dev/null
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
diff --git a/tests/xmconfigdata/Makefile.am b/tests/xmconfigdata/Makefile.am
new file mode 100644 (file)
index 0000000..05201a0
--- /dev/null
@@ -0,0 +1,2 @@
+
+EXTRA_DIST = $(wildcard *.xml) $(wildcard *.cfg)
diff --git a/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg b/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg
new file mode 100755 (executable)
index 0000000..8c10865
--- /dev/null
@@ -0,0 +1,22 @@
+name = "XenGuest2"
+uuid = "c7a5fdb2cdaf9455926ad65c16db1809"
+maxmem = 579
+memory = 394
+vcpus = 1
+builder = "hvm"
+kernel = "/usr/lib/xen/boot/hvmloader"
+boot = "d"
+pae = 1
+acpi = 1
+apic = 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"
+vncpasswd = "123poi"
+disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ]
+vif = [ "mac=00:16:3E:66:92:9C,type=ioemu" ]
diff --git a/tests/xmconfigdata/test-fullvirt-new-cdrom.xml b/tests/xmconfigdata/test-fullvirt-new-cdrom.xml
new file mode 100644 (file)
index 0000000..1d4313a
--- /dev/null
@@ -0,0 +1,38 @@
+<domain type='xen'>
+  <name>XenGuest2</name>
+  <uuid>c7a5fdb2cdaf9455926ad65c16db1809</uuid>
+  <os>
+    <type>hvm</type>
+    <loader>/usr/lib/xen/boot/hvmloader</loader>
+    <boot>cdrom</boot>
+  </os>
+  <currentMemory>403456</currentMemory>
+  <memory>592896</memory>
+  <vcpu>1</vcpu>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <features>
+    <pae/>
+    <acpi/>
+    <apic/>
+  </features>
+  <devices>
+    <emulator>/usr/lib/xen/bin/qemu-dm</emulator>
+    <disk type='block' device='disk'>
+      <driver name='phy'/>
+      <source dev='/dev/HostVG/XenGuest2'/>
+      <target dev='hda'/>
+    </disk>
+    <disk type='file' device='cdrom'>
+      <driver name='file'/>
+      <source file='/root/boot.iso'/>
+      <target dev='hdc'/>
+      <readonly/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='00:16:3E:66:92:9C'/>
+    </interface>
+    <graphics type='vnc' port='-1' listen='127.0.0.1' passwd='123poi'/>
+  </devices>
+</domain>
diff --git a/tests/xmconfigdata/test-fullvirt-old-cdrom.cfg b/tests/xmconfigdata/test-fullvirt-old-cdrom.cfg
new file mode 100755 (executable)
index 0000000..1ea6d4e
--- /dev/null
@@ -0,0 +1,23 @@
+name = "XenGuest2"
+uuid = "c7a5fdb2cdaf9455926ad65c16db1809"
+maxmem = 579
+memory = 394
+vcpus = 1
+builder = "hvm"
+kernel = "/usr/lib/xen/boot/hvmloader"
+boot = "d"
+pae = 1
+acpi = 1
+apic = 1
+cdrom = "/root/boot.iso"
+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"
+vncpasswd = "123poi"
+disk = [ "phy:/dev/HostVG/XenGuest2,ioemu:hda,w" ]
+vif = [ "mac=00:16:3E:66:92:9C,type=ioemu" ]
diff --git a/tests/xmconfigdata/test-fullvirt-old-cdrom.xml b/tests/xmconfigdata/test-fullvirt-old-cdrom.xml
new file mode 100644 (file)
index 0000000..1d4313a
--- /dev/null
@@ -0,0 +1,38 @@
+<domain type='xen'>
+  <name>XenGuest2</name>
+  <uuid>c7a5fdb2cdaf9455926ad65c16db1809</uuid>
+  <os>
+    <type>hvm</type>
+    <loader>/usr/lib/xen/boot/hvmloader</loader>
+    <boot>cdrom</boot>
+  </os>
+  <currentMemory>403456</currentMemory>
+  <memory>592896</memory>
+  <vcpu>1</vcpu>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <features>
+    <pae/>
+    <acpi/>
+    <apic/>
+  </features>
+  <devices>
+    <emulator>/usr/lib/xen/bin/qemu-dm</emulator>
+    <disk type='block' device='disk'>
+      <driver name='phy'/>
+      <source dev='/dev/HostVG/XenGuest2'/>
+      <target dev='hda'/>
+    </disk>
+    <disk type='file' device='cdrom'>
+      <driver name='file'/>
+      <source file='/root/boot.iso'/>
+      <target dev='hdc'/>
+      <readonly/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='00:16:3E:66:92:9C'/>
+    </interface>
+    <graphics type='vnc' port='-1' listen='127.0.0.1' passwd='123poi'/>
+  </devices>
+</domain>
diff --git a/tests/xmconfigdata/test-paravirt-new-pvfb.cfg b/tests/xmconfigdata/test-paravirt-new-pvfb.cfg
new file mode 100755 (executable)
index 0000000..0d71266
--- /dev/null
@@ -0,0 +1,12 @@
+name = "XenGuest1"
+uuid = "c7a5fdb0cdaf9455926ad65c16db1809"
+maxmem = 579
+memory = 394
+vcpus = 1
+bootloader = "/usr/bin/pygrub"
+on_poweroff = "destroy"
+on_reboot = "restart"
+on_crash = "restart"
+vfb = [ "type=vnc,vncunused=1,vnclisten=127.0.0.1,vncpasswd=123poi" ]
+disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ]
+vif = [ "mac=00:16:3E:66:94:9C,ip=192.168.0.9" ]
diff --git a/tests/xmconfigdata/test-paravirt-new-pvfb.xml b/tests/xmconfigdata/test-paravirt-new-pvfb.xml
new file mode 100644 (file)
index 0000000..ba768ad
--- /dev/null
@@ -0,0 +1,24 @@
+<domain type='xen'>
+  <name>XenGuest1</name>
+  <uuid>c7a5fdb0cdaf9455926ad65c16db1809</uuid>
+  <bootloader>/usr/bin/pygrub</bootloader>
+  <currentMemory>403456</currentMemory>
+  <memory>592896</memory>
+  <vcpu>1</vcpu>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <devices>
+    <disk type='block' device='disk'>
+      <driver name='phy'/>
+      <source dev='/dev/HostVG/XenGuest1'/>
+      <target dev='xvda'/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='00:16:3E:66:94:9C'/>
+      <ip address='192.168.0.9'/>
+    </interface>
+    <graphics type='vnc' port='-1' listen='127.0.0.1' passwd='123poi'/>
+    <console/>
+  </devices>
+</domain>
diff --git a/tests/xmconfigdata/test-paravirt-old-pvfb.cfg b/tests/xmconfigdata/test-paravirt-old-pvfb.cfg
new file mode 100755 (executable)
index 0000000..fb112a1
--- /dev/null
@@ -0,0 +1,16 @@
+name = "XenGuest1"
+uuid = "c7a5fdb0cdaf9455926ad65c16db1809"
+maxmem = 579
+memory = 394
+vcpus = 1
+bootloader = "/usr/bin/pygrub"
+on_poweroff = "destroy"
+on_reboot = "restart"
+on_crash = "restart"
+sdl = 0
+vnc = 1
+vncunused = 1
+vnclisten = "127.0.0.1"
+vncpasswd = "123poi"
+disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ]
+vif = [ "mac=00:16:3E:66:94:9C,ip=192.168.0.9" ]
diff --git a/tests/xmconfigdata/test-paravirt-old-pvfb.xml b/tests/xmconfigdata/test-paravirt-old-pvfb.xml
new file mode 100644 (file)
index 0000000..ba768ad
--- /dev/null
@@ -0,0 +1,24 @@
+<domain type='xen'>
+  <name>XenGuest1</name>
+  <uuid>c7a5fdb0cdaf9455926ad65c16db1809</uuid>
+  <bootloader>/usr/bin/pygrub</bootloader>
+  <currentMemory>403456</currentMemory>
+  <memory>592896</memory>
+  <vcpu>1</vcpu>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <devices>
+    <disk type='block' device='disk'>
+      <driver name='phy'/>
+      <source dev='/dev/HostVG/XenGuest1'/>
+      <target dev='xvda'/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='00:16:3E:66:94:9C'/>
+      <ip address='192.168.0.9'/>
+    </interface>
+    <graphics type='vnc' port='-1' listen='127.0.0.1' passwd='123poi'/>
+    <console/>
+  </devices>
+</domain>
diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c
new file mode 100644 (file)
index 0000000..4feff5f
--- /dev/null
@@ -0,0 +1,226 @@
+/*
+ * xmconfigtest.c: Test backend for xm_internal config file handling
+ *
+ * Copyright (C) 2007 Red Hat
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ * Author: Daniel P. Berrange <berrange@redhat.com>
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "xm_internal.h"
+#include "testutils.h"
+#include "internal.h"
+#include "conf.h"
+
+static char *progname;
+
+#define MAX_FILE 4096
+
+static int testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion) {
+    char xmlData[MAX_FILE];
+    char xmcfgData[MAX_FILE];
+    char gotxmcfgData[MAX_FILE];
+    char *xmlPtr = &(xmlData[0]);
+    char *xmcfgPtr = &(xmcfgData[0]);
+    char *gotxmcfgPtr = &(gotxmcfgData[0]);
+    virConfPtr conf = NULL;
+    int ret = -1;
+    virConnectPtr conn;
+    int wrote = MAX_FILE;
+
+    conn = virConnectOpen("test:///default");
+
+    if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
+        goto fail;
+
+    if (virtTestLoadFile(xmcfg, &xmcfgPtr, MAX_FILE) < 0)
+        goto fail;
+
+    /* Yes, a nasty hack, but this is only a test suite */
+    conn->xendConfigVersion = xendConfigVersion;
+
+    if (!(conf = xenXMParseXMLToConfig(conn, xmlPtr)))
+        goto fail;
+
+    if (virConfWriteMem(gotxmcfgPtr, &wrote, conf) < 0)
+        goto fail;
+    gotxmcfgPtr[wrote] = '\0';
+
+    if (getenv("DEBUG_TESTS")) {
+        printf("Expect %d '%s'\n", (int)strlen(xmcfgData), xmcfgData);
+        printf("Actual %d '%s'\n", (int)strlen(gotxmcfgData), gotxmcfgData);
+    }
+    if (strcmp(xmcfgData, gotxmcfgData))
+        goto fail;
+
+    ret = 0;
+
+ fail:
+    if (conf)
+        virConfFree(conf);
+
+    virConnectClose(conn);
+    return ret;
+}
+
+static int testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion) {
+    char xmlData[MAX_FILE];
+    char xmcfgData[MAX_FILE];
+    char *xmlPtr = &(xmlData[0]);
+    char *xmcfgPtr = &(xmcfgData[0]);
+    char *gotxml = NULL;
+    virConfPtr conf = NULL;
+    int ret = -1;
+    virConnectPtr conn;
+
+    conn = virConnectOpen("test:///default");
+
+    if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
+        goto fail;
+
+    if (virtTestLoadFile(xmcfg, &xmcfgPtr, MAX_FILE) < 0)
+        goto fail;
+
+    /* Yes, a nasty hack, but this is only a test suite */
+    conn->xendConfigVersion = xendConfigVersion;
+
+    if (!(conf = virConfReadMem(xmcfgPtr, strlen(xmcfgPtr))))
+        goto fail;
+
+    if (!(gotxml = xenXMDomainFormatXML(conn, conf)))
+        goto fail;
+
+    if (getenv("DEBUG_TESTS")) {
+        printf("Expect %d '%s'\n", (int)strlen(xmlData), xmlData);
+        printf("Actual %d '%s'\n", (int)strlen(gotxml), gotxml);
+    }
+    if (strcmp(xmlData, gotxml))
+        goto fail;
+
+    ret = 0;
+
+ fail:
+    if (conf)
+        virConfFree(conf);
+    if (gotxml)
+        free(gotxml);
+
+    virConnectClose(conn);
+    return ret;
+}
+
+static int testCompareParavirtOldPVFBFormat(void *data ATTRIBUTE_UNUSED) {
+    return testCompareFormatXML("xmconfigdata/test-paravirt-old-pvfb.cfg",
+                                "xmconfigdata/test-paravirt-old-pvfb.xml",
+                                2);
+}
+static int testCompareParavirtOldPVFBParse(void *data ATTRIBUTE_UNUSED) {
+    return testCompareParseXML("xmconfigdata/test-paravirt-old-pvfb.cfg",
+                               "xmconfigdata/test-paravirt-old-pvfb.xml",
+                               2);
+}
+
+static int testCompareParavirtNewPVFBFormat(void *data ATTRIBUTE_UNUSED) {
+    return testCompareFormatXML("xmconfigdata/test-paravirt-new-pvfb.cfg",
+                                "xmconfigdata/test-paravirt-new-pvfb.xml",
+                                3);
+}
+static int testCompareParavirtNewPVFBParse(void *data ATTRIBUTE_UNUSED) {
+    return testCompareParseXML("xmconfigdata/test-paravirt-new-pvfb.cfg",
+                               "xmconfigdata/test-paravirt-new-pvfb.xml",
+                               3);
+}
+
+static int testCompareFullvirtOldCDROMFormat(void *data ATTRIBUTE_UNUSED) {
+    return testCompareFormatXML("xmconfigdata/test-fullvirt-old-cdrom.cfg",
+                                "xmconfigdata/test-fullvirt-old-cdrom.xml",
+                                1);
+}
+static int testCompareFullvirtOldCDROMParse(void *data ATTRIBUTE_UNUSED) {
+    return testCompareParseXML("xmconfigdata/test-fullvirt-old-cdrom.cfg",
+                               "xmconfigdata/test-fullvirt-old-cdrom.xml",
+                               1);
+}
+
+static int testCompareFullvirtNewCDROMFormat(void *data ATTRIBUTE_UNUSED) {
+    return testCompareFormatXML("xmconfigdata/test-fullvirt-new-cdrom.cfg",
+                                "xmconfigdata/test-fullvirt-new-cdrom.xml",
+                                2);
+}
+static int testCompareFullvirtNewCDROMParse(void *data ATTRIBUTE_UNUSED) {
+    return testCompareParseXML("xmconfigdata/test-fullvirt-new-cdrom.cfg",
+                               "xmconfigdata/test-fullvirt-new-cdrom.xml",
+                               2);
+}
+
+
+int
+main(int argc, char **argv)
+{
+    int ret = 0;
+
+    progname = argv[0];
+
+    if (argc > 1) {
+        fprintf(stderr, "Usage: %s\n", progname);
+        exit(EXIT_FAILURE);
+    }
+
+    if (virtTestRun("Paravirt old PVFB (Format)",
+                    1, testCompareParavirtOldPVFBFormat, NULL) != 0)
+        ret = -1;
+
+    if (virtTestRun("Paravirt new PVFB (Format)",
+                    1, testCompareParavirtNewPVFBFormat, NULL) != 0)
+        ret = -1;
+
+    if (virtTestRun("Fullvirt old PVFB (Format)",
+                    1, testCompareFullvirtOldCDROMFormat, NULL) != 0)
+        ret = -1;
+
+    if (virtTestRun("Fullvirt new PVFB (Format)",
+                    1, testCompareFullvirtNewCDROMFormat, NULL) != 0)
+        ret = -1;
+
+    if (virtTestRun("Paravirt old PVFB (Parse)",
+                    1, testCompareParavirtOldPVFBParse, NULL) != 0)
+        ret = -1;
+    if (virtTestRun("Paravirt new PVFB (Parse)",
+                    1, testCompareParavirtNewPVFBParse, NULL) != 0)
+        ret = -1;
+    if (virtTestRun("Fullvirt old PVFB (Parse)",
+                    1, testCompareFullvirtOldCDROMParse, NULL) != 0)
+        ret = -1;
+    if (virtTestRun("Fullvirt new PVFB (Parse)",
+                    1, testCompareFullvirtNewCDROMParse, NULL) != 0)
+        ret = -1;
+
+    exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
+}
+
+
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ *  tab-width: 4
+ * End:
+ */