[Pkg-libvirt-commits] [libguestfs] 84/384: tests: Enable and fix test-add-libvirt-dom test.

Hilko Bengen bengen at moszumanska.debian.org
Sun Mar 29 16:55:47 UTC 2015


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch experimental
in repository libguestfs.

commit df9782ec3a12ac46e1b8ffa31630c7a1e64162fe
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Fri Dec 12 13:31:08 2014 +0000

    tests: Enable and fix test-add-libvirt-dom test.
    
    Commit 96158d42f5cb9b6c472b4630f2c97edae600f6d3 enabled the previously
    private guestfs_add_libvirt_dom API.  It also tried to enable the
    existing test for this API, but failed to do that correctly.  Also the
    test was broken.  Fix all of this.
    
    This fixes commit 96158d42f5cb9b6c472b4630f2c97edae600f6d3.
---
 bootstrap                          |  1 +
 m4/.gitignore                      |  1 +
 tests/c-api/Makefile.am            | 13 ++++----
 tests/c-api/test-add-libvirt-dom.c | 65 ++++++++++++++++++++++----------------
 4 files changed, 46 insertions(+), 34 deletions(-)

diff --git a/bootstrap b/bootstrap
index 9900991..5df6f0f 100755
--- a/bootstrap
+++ b/bootstrap
@@ -96,6 +96,7 @@ vc-list-files
 warnings
 xalloc
 xalloc-die
+xgetcwd
 xstrtol
 xstrtoll
 xvasprintf
diff --git a/m4/.gitignore b/m4/.gitignore
index b0f8d4b..0a6163a 100644
--- a/m4/.gitignore
+++ b/m4/.gitignore
@@ -180,6 +180,7 @@
 /readlink.m4
 /read.m4
 /realloc.m4
+/rewinddir.m4
 /rmdir.m4
 /safe-read.m4
 /safe-write.m4
diff --git a/tests/c-api/Makefile.am b/tests/c-api/Makefile.am
index 57f75fe..0b0296f 100644
--- a/tests/c-api/Makefile.am
+++ b/tests/c-api/Makefile.am
@@ -67,11 +67,10 @@ check_PROGRAMS += test-just-header-cxx
 TESTS += test-just-header-cxx
 endif
 
-# The API behind this test is not baked yet.
-#if HAVE_LIBVIRT
-#check_PROGRAMS += test-add-libvirt-dom
-#TESTS += test-add-libvirt-dom
-#endif
+if HAVE_LIBVIRT
+check_PROGRAMS += test-add-libvirt-dom
+TESTS += test-add-libvirt-dom
+endif
 EXTRA_DIST += test-add-libvirt-dom.c
 
 TESTS_ENVIRONMENT = \
@@ -243,7 +242,9 @@ test_event_string_LDADD = \
 if HAVE_LIBVIRT
 test_add_libvirt_dom_SOURCES = test-add-libvirt-dom.c
 test_add_libvirt_dom_CPPFLAGS = \
-	-I$(top_srcdir)/src -I$(top_builddir)/src -I$(top_srcdir)/gnulib/lib
+	-I$(top_srcdir)/src -I$(top_builddir)/src \
+	-I$(top_srcdir)/gnulib/lib \
+	-I$(top_builddir)/gnulib/lib
 test_add_libvirt_dom_CFLAGS = \
 	$(LIBVIRT_CFLAGS) \
 	$(WARN_CFLAGS) $(WERROR_CFLAGS)
diff --git a/tests/c-api/test-add-libvirt-dom.c b/tests/c-api/test-add-libvirt-dom.c
index 952b9a8..51db6c3 100644
--- a/tests/c-api/test-add-libvirt-dom.c
+++ b/tests/c-api/test-add-libvirt-dom.c
@@ -23,11 +23,11 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "xgetcwd.h"
-
 #include <libvirt/libvirt.h>
 #include <libvirt/virterror.h>
 
+#include "xgetcwd.h"
+
 #include "guestfs.h"
 #include "guestfs-internal-frontend.h"
 
@@ -73,13 +73,29 @@ main (int argc, char *argv[])
   virDomainPtr dom;
   virErrorPtr err;
   int r;
-  const char *test_xml;
+  char *backend;
   char *cwd;
   FILE *fp;
   char libvirt_uri[1024];
 
   cwd = xgetcwd ();
 
+  /* Create the guestfs handle. */
+  g = guestfs_create ();
+  if (g == NULL) {
+    fprintf (stderr, "failed to create handle\n");
+    exit (EXIT_FAILURE);
+  }
+
+  backend = guestfs_get_backend (g);
+  if (STREQ (backend, "uml")) {
+    printf ("%s: test skipped because UML backend does not support qcow2\n",
+            argv[0]);
+    free (backend);
+    exit (77);
+  }
+  free (backend);
+
   /* Create the libvirt XML and test images in the current
    * directory.
    */
@@ -91,41 +107,26 @@ main (int argc, char *argv[])
   make_test_xml (fp, cwd);
   fclose (fp);
 
-  fp = fopen ("test-add-libvirt-dom-1.img", "w");
-  if (fp == NULL) {
-    perror ("test-add-libvirt-dom-1.img");
-    exit (EXIT_FAILURE);
-  }
-  fclose (fp);
-
-  fp = fopen ("test-add-libvirt-dom-2.img", "w");
-  if (fp == NULL) {
-    perror ("test-add-libvirt-dom-2.img");
+  if (guestfs_disk_create (g, "test-add-libvirt-dom-1.img", "raw",
+                           1024*1024, -1) == -1)
     exit (EXIT_FAILURE);
-  }
-  fclose (fp);
 
-  fp = fopen ("test-add-libvirt-dom-3.img", "w");
-  if (fp == NULL) {
-    perror ("test-add-libvirt-dom-3.img");
+  if (guestfs_disk_create (g, "test-add-libvirt-dom-2.img", "raw",
+                           1024*1024, -1) == -1)
     exit (EXIT_FAILURE);
-  }
-  fclose (fp);
 
-  /* Create the guestfs handle. */
-  g = guestfs_create ();
-  if (g == NULL) {
-    fprintf (stderr, "failed to create handle\n");
+  if (guestfs_disk_create (g, "test-add-libvirt-dom-3.img", "qcow2",
+                           1024*1024, -1) == -1)
     exit (EXIT_FAILURE);
-  }
 
   /* Create the libvirt connection. */
   snprintf (libvirt_uri, sizeof libvirt_uri, "test://%s/test-add-libvirt-dom.xml", cwd);
   conn = virConnectOpenReadOnly (libvirt_uri);
   if (!conn) {
     err = virGetLastError ();
-    fprintf (stderr, "could not connect to libvirt (code %d, domain %d): %s\n",
-             err->code, err->domain, err->message);
+    fprintf (stderr,
+             "%s: could not connect to libvirt (code %d, domain %d): %s\n",
+             argv[0], err->code, err->domain, err->message);
     exit (EXIT_FAILURE);
   }
 
@@ -133,7 +134,8 @@ main (int argc, char *argv[])
   if (!dom) {
     err = virGetLastError ();
     fprintf (stderr,
-             "no libvirt domain called '%s': %s\n", "guest", err->message);
+             "%s: no libvirt domain called '%s': %s\n",
+             argv[0], "guest", err->message);
     exit (EXIT_FAILURE);
   }
 
@@ -143,6 +145,13 @@ main (int argc, char *argv[])
   if (r == -1)
     exit (EXIT_FAILURE);
 
+  if (r != 3) {
+    fprintf (stderr,
+             "%s: incorrect number of disks added (%d, expected 3)\n",
+             argv[0], r);
+    exit (EXIT_FAILURE);
+  }
+
   guestfs_close (g);
 
   unlink ("test-add-libvirt-dom.xml");

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list