summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore5
-rw-r--r--capitests/tests.c104
-rw-r--r--images/Makefile.am32
-rwxr-xr-xsrc/generator.ml8
4 files changed, 146 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index 8d76ffcc..bbb1045b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -62,6 +62,11 @@ html/guestfish.1.html
html/guestfs.3.html
html/recipes.html
html/virt-inspector.1.html
+images/100kallzeroes
+images/100kallnewlines
+images/100kallspaces
+images/100krandom
+images/10klines
images/test.sqsh
initramfs
initramfs.timestamp
diff --git a/capitests/tests.c b/capitests/tests.c
index 9e3c04ba..dffa5003 100644
--- a/capitests/tests.c
+++ b/capitests/tests.c
@@ -1797,6 +1797,102 @@ static int test_hexdump_0 (void)
return 0;
}
+static int test_hexdump_1_skip (void)
+{
+ const char *str;
+
+ str = getenv ("SKIP_TEST_HEXDUMP_1");
+ if (str && strcmp (str, "1") == 0) return 1;
+ str = getenv ("SKIP_TEST_HEXDUMP");
+ if (str && strcmp (str, "1") == 0) return 1;
+ return 0;
+}
+
+static int test_hexdump_1 (void)
+{
+ if (test_hexdump_1_skip ()) {
+ printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_hexdump_1");
+ return 0;
+ }
+
+ /* InitBasicFS for test_hexdump_1: create ext2 on /dev/sda1 */
+ {
+ char device[] = "/dev/sda";
+ 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";
+ 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";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkfs (g, fstype, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda1";
+ char mountpoint[] = "/";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mount (g, device, mountpoint);
+ if (r == -1)
+ return -1;
+ }
+ /* TestRun for hexdump (1) */
+ {
+ char options[] = "ro";
+ char vfstype[] = "squashfs";
+ char device[] = "/dev/sdd";
+ char mountpoint[] = "/";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mount_vfs (g, options, vfstype, device, mountpoint);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char path[] = "/100krandom";
+ char *r;
+ suppress_error = 0;
+ r = guestfs_hexdump (g, path);
+ if (r == NULL)
+ return -1;
+ free (r);
+ }
+ return 0;
+}
+
static int test_strings_e_0_skip (void)
{
const char *str;
@@ -16406,7 +16502,7 @@ int main (int argc, char *argv[])
/* Cancel previous alarm. */
alarm (0);
- nr_tests = 152;
+ nr_tests = 153;
test_num++;
printf ("%3d/%3d test_mkdtemp_0\n", test_num, nr_tests);
@@ -16499,6 +16595,12 @@ int main (int argc, char *argv[])
failed++;
}
test_num++;
+ printf ("%3d/%3d test_hexdump_1\n", test_num, nr_tests);
+ if (test_hexdump_1 () == -1) {
+ printf ("test_hexdump_1 FAILED\n");
+ failed++;
+ }
+ test_num++;
printf ("%3d/%3d test_strings_e_0\n", test_num, nr_tests);
if (test_strings_e_0 () == -1) {
printf ("test_strings_e_0 FAILED\n");
diff --git a/images/Makefile.am b/images/Makefile.am
index dcdf51f8..46488ebe 100644
--- a/images/Makefile.am
+++ b/images/Makefile.am
@@ -25,8 +25,38 @@ noinst_DATA = test.sqsh
CLEANFILES = test.sqsh
-squash_files = helloworld.tar helloworld.tar.gz empty known-1 known-2 known-3
+squash_files = helloworld.tar helloworld.tar.gz empty known-1 known-2 known-3 \
+ 100kallzeroes 100kallnewlines 100kallspaces 100krandom 10klines
test.sqsh: $(squash_files)
rm -f $@
$(MKSQUASHFS) $(squash_files) $@
+
+100kallzeroes:
+ rm -f $@ $@-t
+ dd if=/dev/zero of=$@-t bs=1024 count=100
+ mv $@-t $@
+
+100kallnewlines: 100kallzeroes
+ rm -f $@ $@-t
+ tr '\0' '\n' < $< > $@-t
+ mv $@-t $@
+
+100kallspaces: 100kallzeroes
+ rm -f $@ $@-t
+ tr '\0' ' ' < $< > $@-t
+ mv $@-t $@
+
+100krandom:
+ rm -f $@ $@-t
+ dd if=/dev/urandom of=$@-t bs=1024 count=100
+ mv $@-t $@
+
+10klines:
+ rm -f $@ $@-t
+ i=0; \
+ while [ $$i -lt 10000 ]; do \
+ echo "abcdefghijklmnopqrstuvwxyz"; \
+ i=$$(($$i+1)); \
+ done > $@-t
+ mv $@-t $@
diff --git a/src/generator.ml b/src/generator.ml
index 1342c38e..7905c367 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -2131,7 +2131,13 @@ The returned strings are transcoded to UTF-8.");
("hexdump", (RString "dump", [String "path"]), 96, [ProtocolLimitWarning],
[InitBasicFS, Always, TestOutput (
[["write_file"; "/new"; "hello\nworld\n"; "12"];
- ["hexdump"; "/new"]], "00000000 68 65 6c 6c 6f 0a 77 6f 72 6c 64 0a |hello.world.|\n0000000c\n")],
+ ["hexdump"; "/new"]], "00000000 68 65 6c 6c 6f 0a 77 6f 72 6c 64 0a |hello.world.|\n0000000c\n");
+ (* Test for RHBZ#501888c2 regression which caused large hexdump
+ * commands to segfault.
+ *)
+ InitBasicFS, Always, TestRun (
+ [["mount_vfs"; "ro"; "squashfs"; "/dev/sdd"; "/"];
+ ["hexdump"; "/100krandom"]])],
"dump a file in hexadecimal",
"\
This runs C<hexdump -C> on the given C<path>. The result is