Use a squashfs attached as /dev/sdd during the C API tests.
authorRichard W.M. Jones <rjones@redhat.com>
Fri, 29 May 2009 11:59:32 +0000 (12:59 +0100)
committerRichard W.M. Jones <rjones@redhat.com>
Fri, 29 May 2009 11:59:32 +0000 (12:59 +0100)
.gitignore
README
capitests/tests.c
configure.ac
images/Makefile.am
images/empty [new file with mode: 0644]
images/known-1 [new file with mode: 0644]
images/known-2 [new file with mode: 0644]
images/known-3 [new file with mode: 0644]
src/generator.ml

index 10faaab..296db62 100644 (file)
@@ -55,6 +55,7 @@ html/guestfish.1.html
 html/guestfs.3.html
 html/recipes.html
 html/virt-inspector.1.html
 html/guestfs.3.html
 html/recipes.html
 html/virt-inspector.1.html
+images/test.sqsh
 initramfs
 initramfs.timestamp
 inspector/virt-inspector.1
 initramfs
 initramfs.timestamp
 inspector/virt-inspector.1
diff --git a/README b/README
index f167021..299b9c9 100644 (file)
--- a/README
+++ b/README
@@ -39,6 +39,8 @@ Requirements
 
 - XDR, rpcgen (on Linux these are provided by glibc)
 
 
 - XDR, rpcgen (on Linux these are provided by glibc)
 
+- squashfs-tools (mksquashfs only)
+
 - (Optional) Augeas (http://augeas.net/)
 
 - perldoc (pod2man, pod2text) to generate the manual pages and
 - (Optional) Augeas (http://augeas.net/)
 
 - perldoc (pod2man, pod2text) to generate the manual pages and
index 959d09b..5b6356f 100644 (file)
@@ -5729,6 +5729,111 @@ static int test_checksum_7 (void)
   return 0;
 }
 
   return 0;
 }
 
+static int test_checksum_8_skip (void)
+{
+  const char *str;
+
+  str = getenv ("SKIP_TEST_CHECKSUM_8");
+  if (str && strcmp (str, "1") == 0) return 1;
+  str = getenv ("SKIP_TEST_CHECKSUM");
+  if (str && strcmp (str, "1") == 0) return 1;
+  return 0;
+}
+
+static int test_checksum_8 (void)
+{
+  if (test_checksum_8_skip ()) {
+    printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_checksum_8");
+    return 0;
+  }
+
+  /* InitBasicFS for test_checksum_8: create ext2 on /dev/sda1 */
+  {
+    char device[] = "/dev/sda";
+    device[5] = devchar;
+    int r;
+    suppress_error = 0;
+    r = guestfs_blockdev_setrw (g, device);
+    if (r == -1)
+      return -1;
+  }
+  {
+    int r;
+    suppress_error = 0;
+    r = guestfs_umount_all (g);
+    if (r == -1)
+      return -1;
+  }
+  {
+    int r;
+    suppress_error = 0;
+    r = guestfs_lvm_remove_all (g);
+    if (r == -1)
+      return -1;
+  }
+  {
+    char device[] = "/dev/sda";
+    device[5] = devchar;
+    char lines_0[] = ",";
+    char *lines[] = {
+      lines_0,
+      NULL
+    };
+    int r;
+    suppress_error = 0;
+    r = guestfs_sfdisk (g, device, 0, 0, 0, lines);
+    if (r == -1)
+      return -1;
+  }
+  {
+    char fstype[] = "ext2";
+    char device[] = "/dev/sda1";
+    device[5] = devchar;
+    int r;
+    suppress_error = 0;
+    r = guestfs_mkfs (g, fstype, device);
+    if (r == -1)
+      return -1;
+  }
+  {
+    char device[] = "/dev/sda1";
+    device[5] = devchar;
+    char mountpoint[] = "/";
+    int r;
+    suppress_error = 0;
+    r = guestfs_mount (g, device, mountpoint);
+    if (r == -1)
+      return -1;
+  }
+  /* TestOutput for checksum (8) */
+  char expected[] = "46d6ca27ee07cdc6fa99c2e138cc522c";
+  {
+    char device[] = "/dev/sdd";
+    device[5] = devchar;
+    char mountpoint[] = "/";
+    int r;
+    suppress_error = 0;
+    r = guestfs_mount (g, device, mountpoint);
+    if (r == -1)
+      return -1;
+  }
+  {
+    char csumtype[] = "md5";
+    char path[] = "/known-3";
+    char *r;
+    suppress_error = 0;
+    r = guestfs_checksum (g, csumtype, path);
+    if (r == NULL)
+      return -1;
+    if (strcmp (r, expected) != 0) {
+      fprintf (stderr, "test_checksum_8: expected \"%s\" but got \"%s\"\n", expected, r);
+      return -1;
+    }
+    free (r);
+  }
+  return 0;
+}
+
 static int test_download_0_skip (void)
 {
   const char *str;
 static int test_download_0_skip (void)
 {
   const char *str;
@@ -15358,7 +15463,20 @@ static int test_list_devices_0 (void)
         return -1;
       }
     }
         return -1;
       }
     }
-    if (r[3] != NULL) {
+    if (!r[3]) {
+      fprintf (stderr, "test_list_devices_0: short list returned from command\n");
+      print_strings (r);
+      return -1;
+    }
+    {
+      char expected[] = "/dev/sdd";
+      expected[5] = devchar;
+      if (strcmp (r[3], expected) != 0) {
+        fprintf (stderr, "test_list_devices_0: expected \"%s\" but got \"%s\"\n", expected, r[3]);
+        return -1;
+      }
+    }
+    if (r[4] != NULL) {
       fprintf (stderr, "test_list_devices_0: extra elements returned from command\n");
       print_strings (r);
       return -1;
       fprintf (stderr, "test_list_devices_0: extra elements returned from command\n");
       print_strings (r);
       return -1;
@@ -16004,6 +16122,11 @@ int main (int argc, char *argv[])
     exit (1);
   }
 
     exit (1);
   }
 
+  if (guestfs_add_drive (g, "../images/test.sqsh") == -1) {
+    printf ("guestfs_add_drive %s FAILED\n", filename);
+    exit (1);
+  }
+
   if (guestfs_launch (g) == -1) {
     printf ("guestfs_launch FAILED\n");
     exit (1);
   if (guestfs_launch (g) == -1) {
     printf ("guestfs_launch FAILED\n");
     exit (1);
@@ -16035,7 +16158,7 @@ int main (int argc, char *argv[])
     free (devs[i]);
   free (devs);
 
     free (devs[i]);
   free (devs);
 
-  nr_tests = 142;
+  nr_tests = 143;
 
   test_num++;
   printf ("%3d/%3d test_find_0\n", test_num, nr_tests);
 
   test_num++;
   printf ("%3d/%3d test_find_0\n", test_num, nr_tests);
@@ -16344,6 +16467,12 @@ int main (int argc, char *argv[])
     failed++;
   }
   test_num++;
     failed++;
   }
   test_num++;
+  printf ("%3d/%3d test_checksum_8\n", test_num, nr_tests);
+  if (test_checksum_8 () == -1) {
+    printf ("test_checksum_8 FAILED\n");
+    failed++;
+  }
+  test_num++;
   printf ("%3d/%3d test_download_0\n", test_num, nr_tests);
   if (test_download_0 () == -1) {
     printf ("test_download_0 FAILED\n");
   printf ("%3d/%3d test_download_0\n", test_num, nr_tests);
   if (test_download_0 () == -1) {
     printf ("test_download_0 FAILED\n");
index d3dc0ed..ef315e6 100644 (file)
@@ -56,6 +56,11 @@ AC_CHECK_PROG([POD2TEXT],[pod2text],[pod2text],[no])
 test "x$POD2TEXT" = "xno" &&
      AC_MSG_ERROR([pod2text must be installed])
 
 test "x$POD2TEXT" = "xno" &&
      AC_MSG_ERROR([pod2text must be installed])
 
+dnl Check for mksquashfs.
+AC_PATH_PROGS([MKSQUASHFS],[mksquashfs],[no],
+       [$PATH$PATH_SEPARATOR/usr/sbin$PATH_SEPARATOR/sbin])
+test "x$MKSQUASHFS" = "xno" && AC_MSG_ERROR([mksquashfs must be installed])
+
 dnl Check for QEMU for running binaries on this $host_cpu, fall
 dnl back to basic 'qemu'.  Allow the user to override it.
 default_qemu="qemu-kvm qemu-system-$host_cpu qemu"
 dnl Check for QEMU for running binaries on this $host_cpu, fall
 dnl back to basic 'qemu'.  Allow the user to override it.
 default_qemu="qemu-kvm qemu-system-$host_cpu qemu"
index 6811107..dcdf51f 100644 (file)
 EXTRA_DIST     = \
        helloworld.tar \
        helloworld.tar.gz \
 EXTRA_DIST     = \
        helloworld.tar \
        helloworld.tar.gz \
-       mbr-ext2-empty.img.gz
+       mbr-ext2-empty.img.gz \
+       empty known-1 known-2 known-3
+
+noinst_DATA = test.sqsh
+
+CLEANFILES = test.sqsh
+
+squash_files = helloworld.tar helloworld.tar.gz empty known-1 known-2 known-3
+
+test.sqsh: $(squash_files)
+       rm -f $@
+       $(MKSQUASHFS) $(squash_files) $@
diff --git a/images/empty b/images/empty
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/images/known-1 b/images/known-1
new file mode 100644 (file)
index 0000000..8baef1b
--- /dev/null
@@ -0,0 +1 @@
+abc
diff --git a/images/known-2 b/images/known-2
new file mode 100644 (file)
index 0000000..0373d93
--- /dev/null
@@ -0,0 +1 @@
+abcdef
diff --git a/images/known-3 b/images/known-3
new file mode 100644 (file)
index 0000000..3ac370d
--- /dev/null
@@ -0,0 +1,27 @@
+         I WANDERED lonely as a cloud
+          That floats on high o'er vales and hills,
+          When all at once I saw a crowd,
+          A host, of golden daffodils;
+          Beside the lake, beneath the trees,
+          Fluttering and dancing in the breeze.
+
+          Continuous as the stars that shine
+          And twinkle on the milky way,
+          They stretched in never-ending line
+          Along the margin of a bay:
+          Ten thousand saw I at a glance,
+          Tossing their heads in sprightly dance.
+
+          The waves beside them danced; but they
+          Out-did the sparkling waves in glee:
+          A poet could not but be gay,
+          In such a jocund company:
+          I gazed--and gazed--but little thought
+          What wealth the show to me had brought:
+
+          For oft, when on my couch I lie
+          In vacant or in pensive mood,
+          They flash upon that inward eye
+          Which is the bliss of solitude;
+          And then my heart with pleasure fills,
+          And dances with the daffodils.
index 9f01904..a80e846 100755 (executable)
@@ -130,9 +130,13 @@ can easily destroy all your data>."
 (* You can supply zero or as many tests as you want per API call.
  *
  * Note that the test environment has 3 block devices, of size 500MB,
 (* You can supply zero or as many tests as you want per API call.
  *
  * Note that the test environment has 3 block devices, of size 500MB,
- * 50MB and 10MB (respectively /dev/sda, /dev/sdb, /dev/sdc).
+ * 50MB and 10MB (respectively /dev/sda, /dev/sdb, /dev/sdc), and
+ * a fourth squashfs block device with some known files on it (/dev/sdd).
+ *
  * Note for partitioning purposes, the 500MB device has 63 cylinders.
  *
  * Note for partitioning purposes, the 500MB device has 63 cylinders.
  *
+ * The squashfs block device (/dev/sdd) comes from images/test.sqsh.
+ *
  * To be able to run the tests in a reasonable amount of time,
  * the virtual machine and block devices are reused between tests.
  * So don't try testing kill_subprocess :-x
  * To be able to run the tests in a reasonable amount of time,
  * the virtual machine and block devices are reused between tests.
  * So don't try testing kill_subprocess :-x
@@ -659,7 +663,7 @@ should probably use C<guestfs_readdir> instead.");
 
   ("list_devices", (RStringList "devices", []), 7, [],
    [InitEmpty, Always, TestOutputList (
 
   ("list_devices", (RStringList "devices", []), 7, [],
    [InitEmpty, Always, TestOutputList (
-      [["list_devices"]], ["/dev/sda"; "/dev/sdb"; "/dev/sdc"])],
+      [["list_devices"]], ["/dev/sda"; "/dev/sdb"; "/dev/sdc"; "/dev/sdd"])],
    "list the block devices",
    "\
 List all the block devices.
    "list the block devices",
    "\
 List all the block devices.
@@ -1619,7 +1623,10 @@ See also C<guestfs_upload>, C<guestfs_cat>.");
        ["checksum"; "sha384"; "/new"]], "109bb6b5b6d5547c1ce03c7a8bd7d8f80c1cb0957f50c4f7fda04692079917e4f9cad52b878f3d8234e1a170b154b72d");
     InitBasicFS, Always, TestOutput (
       [["write_file"; "/new"; "test\n"; "0"];
        ["checksum"; "sha384"; "/new"]], "109bb6b5b6d5547c1ce03c7a8bd7d8f80c1cb0957f50c4f7fda04692079917e4f9cad52b878f3d8234e1a170b154b72d");
     InitBasicFS, Always, TestOutput (
       [["write_file"; "/new"; "test\n"; "0"];
-       ["checksum"; "sha512"; "/new"]], "0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123")],
+       ["checksum"; "sha512"; "/new"]], "0e3e75234abc68f4378a86b3f4b32a198ba301845b0cd6e50106e874345700cc6663a86c1ea125dc5e92be17c98f9a0f85ca9d5f595db2012f7cc3571945c123");
+    InitBasicFS, Always, TestOutput (
+      [["mount"; "/dev/sdd"; "/"];
+       ["checksum"; "md5"; "/known-3"]], "46d6ca27ee07cdc6fa99c2e138cc522c")],
    "compute MD5, SHAx or CRC checksum of file",
    "\
 This call computes the MD5, SHAx or CRC checksum of the
    "compute MD5, SHAx or CRC checksum of file",
    "\
 This call computes the MD5, SHAx or CRC checksum of the
@@ -3903,6 +3910,11 @@ int main (int argc, char *argv[])
     exit (1);
   }
 
     exit (1);
   }
 
+  if (guestfs_add_drive (g, \"../images/test.sqsh\") == -1) {
+    printf (\"guestfs_add_drive %%s FAILED\\n\", filename);
+    exit (1);
+  }
+
   if (guestfs_launch (g) == -1) {
     printf (\"guestfs_launch FAILED\\n\");
     exit (1);
   if (guestfs_launch (g) == -1) {
     printf (\"guestfs_launch FAILED\\n\");
     exit (1);