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;
/* Cancel previous alarm. */
alarm (0);
- nr_tests = 152;
+ nr_tests = 153;
test_num++;
printf ("%3d/%3d test_mkdtemp_0\n", test_num, nr_tests);
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");
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 $@
("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