summaryrefslogtreecommitdiffstats
path: root/tests/ts/cramfs
diff options
context:
space:
mode:
authorRuediger Meier2018-01-23 16:59:24 +0100
committerKarel Zak2018-01-24 12:53:33 +0100
commitc990f94cbcc68c7bab47458a09e361ce0791b6d8 (patch)
tree0b2a537653b476bb97e57184119717f3568887d3 /tests/ts/cramfs
parentfsck.cramfs: fix crash when superblock size is too small (diff)
downloadkernel-qcow2-util-linux-c990f94cbcc68c7bab47458a09e361ce0791b6d8.tar.gz
kernel-qcow2-util-linux-c990f94cbcc68c7bab47458a09e361ce0791b6d8.tar.xz
kernel-qcow2-util-linux-c990f94cbcc68c7bab47458a09e361ce0791b6d8.zip
tests: rewrite fsck-bad-header
Fix test for systems with pagesize != 4096 Loop over many combinations of sizes, endianness and blocksizes. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Diffstat (limited to 'tests/ts/cramfs')
-rwxr-xr-xtests/ts/cramfs/fsck-bad-header74
1 files changed, 69 insertions, 5 deletions
diff --git a/tests/ts/cramfs/fsck-bad-header b/tests/ts/cramfs/fsck-bad-header
index add388577..c71782bde 100755
--- a/tests/ts/cramfs/fsck-bad-header
+++ b/tests/ts/cramfs/fsck-bad-header
@@ -25,14 +25,78 @@ ts_check_test_command "$TS_CMD_MKCRAMFS"
ts_check_test_command "$TS_CMD_FSCKCRAMFS"
ts_check_prog "dd"
-IMAGE_SOURCE="$TS_OUTDIR/${TS_TESTNAME}-data/root"
+function num2binary()
+{
+ local num=$1
+ local endian=$2
+
+ test "$num" -ge 0 -a "$num" -le 4294967295 || return 1
+ test "$endian" = "be" -o "$endian" = "le" || return 1
+
+ # how to do that easier?
+ if test "$endian" = "be"; then
+ echo -en "$(printf "%08x" "$1" | sed 's/\(..\)/\\x\1/g')"
+ else
+ echo -en "$(printf "%08x" "$1" | sed 's/^\(..\)\(..\)\(..\)\(..\)$/\\x\4\\x\3\\x\2\\x\1/')"
+ fi
+}
+
+function fsck_loop_sizes()
+{
+ local endian=$1 # be, le
+ local seek=$2 # 4 for nopad, 516 for pad
+ shift 2 # the rest are sizes to loop over
+
+ for size in "$@"; do
+ ts_log "## size: $size"
+ cp -a "$IMAGE_FILE" "$IMAGE_FILE.tmp"
+ num2binary "$size" $endian |
+ dd of="$IMAGE_FILE.tmp" bs=1 seek="$seek" count=4 conv=notrunc &> /dev/null
+ $TS_CMD_FSCKCRAMFS "$IMAGE_FILE.tmp" >> $TS_OUTPUT 2>&1
+ ts_log "ret: $?
+"
+ done
+ rm -f "$IMAGE_FILE"
+}
+
+
+IMAGE_SOURCE="$TS_OUTDIR/${TS_TESTNAME}-data"
IMAGE_FILE="$TS_OUTDIR/${TS_TESTNAME}-cramfs.img"
mkdir -p "${IMAGE_SOURCE}/subdir" &> /dev/null
-$TS_CMD_MKCRAMFS -p -N big $IMAGE_SOURCE $IMAGE_FILE &> /dev/null
-echo -ne \\00\\x4c |
- dd of=$IMAGE_FILE bs=1 seek=518 count=2 conv=notrunc &> /dev/null
-$TS_CMD_FSCKCRAMFS $IMAGE_FILE >> $TS_OUTPUT 2>&1
+
+ts_init_subtest "nopad-4K-be"
+$TS_CMD_MKCRAMFS -N big -b 4096 $IMAGE_SOURCE $IMAGE_FILE &> /dev/null
+fsck_loop_sizes be 4 0 75 76 4095 4096 4097 4294967295
+rm -f "$IMAGE_FILE"
+ts_finalize_subtest
+
+ts_init_subtest "nopad-4K-le"
+$TS_CMD_MKCRAMFS -N little -b 4096 $IMAGE_SOURCE $IMAGE_FILE &> /dev/null
+fsck_loop_sizes le 4 0 75 76 4095 4096 4097 4294967295
+ts_finalize_subtest
+
+ts_init_subtest "pad-4K-be"
+$TS_CMD_MKCRAMFS -p -N big -b 4096 $IMAGE_SOURCE $IMAGE_FILE &> /dev/null
+fsck_loop_sizes be 516 76 587 588 4095 4096 4097 4294967295
+ts_finalize_subtest
+
+ts_init_subtest "pad-4K-le"
+$TS_CMD_MKCRAMFS -p -N little -b 4096 $IMAGE_SOURCE $IMAGE_FILE &> /dev/null
+fsck_loop_sizes le 516 76 587 588 4095 4096 4097 4294967295
+ts_finalize_subtest
+
+ts_init_subtest "pad-64K-be"
+$TS_CMD_MKCRAMFS -p -N big -b 65536 $IMAGE_SOURCE $IMAGE_FILE &> /dev/null
+fsck_loop_sizes be 516 76 587 588 65535 65536 65537 4294967295
+ts_finalize_subtest
+
+ts_init_subtest "pad-64K-le"
+$TS_CMD_MKCRAMFS -p -N little -b 65536 $IMAGE_SOURCE $IMAGE_FILE &> /dev/null
+fsck_loop_sizes le 516 76 587 588 65535 65536 65537 4294967295
+ts_finalize_subtest
+
+rm -rf "$IMAGE_SOURCE" "$IMAGE_FILE.tmp"
ts_finalize