From e02066bcb33a2aed5f23dd18c3168dc66efddb18 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 29 May 2009 12:59:32 +0100 Subject: [PATCH] Use a squashfs attached as /dev/sdd during the C API tests. --- .gitignore | 1 + README | 2 + capitests/tests.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++- configure.ac | 5 ++ images/Makefile.am | 13 +++++- images/empty | 0 images/known-1 | 1 + images/known-2 | 1 + images/known-3 | 27 +++++++++++ src/generator.ml | 18 ++++++-- 10 files changed, 195 insertions(+), 6 deletions(-) create mode 100644 images/empty create mode 100644 images/known-1 create mode 100644 images/known-2 create mode 100644 images/known-3 diff --git a/.gitignore b/.gitignore index 10faaab..296db62 100644 --- a/.gitignore +++ b/.gitignore @@ -55,6 +55,7 @@ html/guestfish.1.html html/guestfs.3.html html/recipes.html html/virt-inspector.1.html +images/test.sqsh initramfs initramfs.timestamp inspector/virt-inspector.1 diff --git a/README b/README index f167021..299b9c9 100644 --- a/README +++ b/README @@ -39,6 +39,8 @@ Requirements - 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 diff --git a/capitests/tests.c b/capitests/tests.c index 959d09b..5b6356f 100644 --- a/capitests/tests.c +++ b/capitests/tests.c @@ -5729,6 +5729,111 @@ static int test_checksum_7 (void) 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; @@ -15358,7 +15463,20 @@ static int test_list_devices_0 (void) 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; @@ -16004,6 +16122,11 @@ int main (int argc, char *argv[]) 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); @@ -16035,7 +16158,7 @@ int main (int argc, char *argv[]) free (devs[i]); free (devs); - nr_tests = 142; + nr_tests = 143; 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++; + 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"); diff --git a/configure.ac b/configure.ac index d3dc0ed..ef315e6 100644 --- a/configure.ac +++ b/configure.ac @@ -56,6 +56,11 @@ AC_CHECK_PROG([POD2TEXT],[pod2text],[pod2text],[no]) 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" diff --git a/images/Makefile.am b/images/Makefile.am index 6811107..dcdf51f 100644 --- a/images/Makefile.am +++ b/images/Makefile.am @@ -18,4 +18,15 @@ 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 index 0000000..e69de29 diff --git a/images/known-1 b/images/known-1 new file mode 100644 index 0000000..8baef1b --- /dev/null +++ b/images/known-1 @@ -0,0 +1 @@ +abc diff --git a/images/known-2 b/images/known-2 new file mode 100644 index 0000000..0373d93 --- /dev/null +++ b/images/known-2 @@ -0,0 +1 @@ +abcdef diff --git a/images/known-3 b/images/known-3 new file mode 100644 index 0000000..3ac370d --- /dev/null +++ b/images/known-3 @@ -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. diff --git a/src/generator.ml b/src/generator.ml index 9f01904..a80e846 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -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, - * 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. * + * 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 @@ -659,7 +663,7 @@ should probably use C instead."); ("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. @@ -1619,7 +1623,10 @@ See also C, C."); ["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 @@ -3903,6 +3910,11 @@ int main (int argc, char *argv[]) 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); -- 1.8.3.1