diff --git a/bootstrap b/bootstrap index 990099152..5df6f0f5a 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 b0f8d4b8f..0a6163adb 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 57f75fe47..0b0296fac 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 952b9a866..51db6c36e 100644 --- a/tests/c-api/test-add-libvirt-dom.c +++ b/tests/c-api/test-add-libvirt-dom.c @@ -23,11 +23,11 @@ #include #include -#include "xgetcwd.h" - #include #include +#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"); + 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-2.img", "w"); - if (fp == NULL) { - perror ("test-add-libvirt-dom-2.img"); + if (guestfs_disk_create (g, "test-add-libvirt-dom-2.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-3.img", "qcow2", + 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"); - 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");