diff options
Diffstat (limited to 'tests/ts/cramfs')
-rw-r--r-- | tests/ts/cramfs/cramfs-big.img | bin | 0 -> 4096 bytes | |||
-rw-r--r-- | tests/ts/cramfs/cramfs-little.img | bin | 0 -> 4096 bytes | |||
-rwxr-xr-x | tests/ts/cramfs/doubles | 55 | ||||
-rwxr-xr-x | tests/ts/cramfs/fsck-bad-header | 102 | ||||
-rwxr-xr-x | tests/ts/cramfs/fsck-endianness | 58 | ||||
-rwxr-xr-x | tests/ts/cramfs/mkfs | 119 | ||||
-rwxr-xr-x | tests/ts/cramfs/mkfs-endianness | 59 |
7 files changed, 393 insertions, 0 deletions
diff --git a/tests/ts/cramfs/cramfs-big.img b/tests/ts/cramfs/cramfs-big.img Binary files differnew file mode 100644 index 0000000..2ea516e --- /dev/null +++ b/tests/ts/cramfs/cramfs-big.img diff --git a/tests/ts/cramfs/cramfs-little.img b/tests/ts/cramfs/cramfs-little.img Binary files differnew file mode 100644 index 0000000..a1dfab5 --- /dev/null +++ b/tests/ts/cramfs/cramfs-little.img diff --git a/tests/ts/cramfs/doubles b/tests/ts/cramfs/doubles new file mode 100755 index 0000000..8a1b7bb --- /dev/null +++ b/tests/ts/cramfs/doubles @@ -0,0 +1,55 @@ +#!/bin/bash + +# +# Copyright (C) 2011 Karel Zak <kzak@redhat.com> +# +# This file is part of util-linux. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +TS_TOPDIR="${0%/*}/../.." +TS_DESC="mkfs doubles" + +. $TS_TOPDIR/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_CMD_MKCRAMFS" +ts_check_test_command "$TS_CMD_MOUNT" +ts_check_test_command "$TS_CMD_UMOUNT" + +ts_skip_nonroot +ts_check_losetup + +ORIGPWD=$(pwd) +IMAGE_NAME="${TS_TESTNAME}.img" +IMAGE_PATH="$TS_OUTDIR/$IMAGE_NAME" +IMAGE_SRC="$TS_OUTDIR/${TS_TESTNAME}-data" + +ts_log "create mountpoint dir" +[ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT + +mkdir -p $IMAGE_SRC +echo hello > $IMAGE_SRC/a +echo hello > $IMAGE_SRC/b + +ts_log "create cramfs image" +$TS_CMD_MKCRAMFS $IMAGE_SRC $IMAGE_PATH >> $TS_OUTPUT 2>> $TS_ERRLOG +[ -s "$IMAGE_PATH" ] || ts_die "Cannot create $IMAGE_PATH" + +ts_mount "cramfs" -r $IMAGE_PATH $TS_MOUNTPOINT + +# check it +ts_is_mounted $TS_MOUNTPOINT || ts_die "Cannot find $TS_MOUNTPOINT in /proc/mounts" + +ts_log "umount the image" +$TS_CMD_UMOUNT $TS_MOUNTPOINT +ts_finalize + diff --git a/tests/ts/cramfs/fsck-bad-header b/tests/ts/cramfs/fsck-bad-header new file mode 100755 index 0000000..95d8274 --- /dev/null +++ b/tests/ts/cramfs/fsck-bad-header @@ -0,0 +1,102 @@ +#!/bin/bash + +# +# Copyright (C) 2007 Karel Zak <kzak@redhat.com> +# +# This file is part of util-linux. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +TS_TOPDIR="${0%/*}/../.." +TS_DESC="fsck bad header" + +. $TS_TOPDIR/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_CMD_MKCRAMFS" +ts_check_test_command "$TS_CMD_FSCKCRAMFS" +ts_check_prog "dd" + +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_both "## 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>> $TS_ERRLOG + 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_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 + diff --git a/tests/ts/cramfs/fsck-endianness b/tests/ts/cramfs/fsck-endianness new file mode 100755 index 0000000..bcfb46c --- /dev/null +++ b/tests/ts/cramfs/fsck-endianness @@ -0,0 +1,58 @@ +#!/bin/bash + +# +# Copyright (C) 2007 Karel Zak <kzak@redhat.com> +# +# This file is part of util-linux. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +TS_TOPDIR="${0%/*}/../.." +TS_DESC="fsck endianness" + +. $TS_TOPDIR/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_CMD_MKCRAMFS" +ts_check_test_command "$TS_CMD_FSCKCRAMFS" +ts_check_test_command "$TS_HELPER_MD5" + +ts_skip_nonroot + +IMAGE_LITTLE="$TS_SELF/cramfs-little.img" #Known good little endian image +IMAGE_BIG="$TS_SELF/cramfs-big.img" #Known good big endian image + +IMAGE_CREATED="$TS_OUTDIR/${TS_TESTNAME}-cramfs.img" #Image created during the test and compared against the known images. +IMAGE_DATA="$TS_OUTDIR/${TS_TESTNAME}-data" + +test_image() { + local FROM_ENDIANNESS="$1"; shift + local TO_ENDIANNESS="$1"; shift + local FROM_IMAGE="$1"; shift + + rm -rf "$IMAGE_DATA" + ts_log "extract from $FROM_ENDIANNESS endian" + $TS_CMD_FSCKCRAMFS -v -b 4096 --extract=$IMAGE_DATA $FROM_IMAGE | head -n1 | cut -d" " -f4 >> $TS_OUTPUT 2>> $TS_ERRLOG + + ts_log "create $TO_ENDIANNESS endian" + $TS_CMD_MKCRAMFS -N "$TO_ENDIANNESS" -b 4096 "$IMAGE_DATA" \ + "$IMAGE_CREATED" >> $TS_OUTPUT 2>> $TS_ERRLOG + + "$TS_HELPER_MD5" < "$IMAGE_CREATED" >> $TS_OUTPUT + + rm "$IMAGE_CREATED" +} + +test_image "little" "big" "$IMAGE_LITTLE" +test_image "big" "little" "$IMAGE_BIG" + +ts_finalize + diff --git a/tests/ts/cramfs/mkfs b/tests/ts/cramfs/mkfs new file mode 100755 index 0000000..f99e4da --- /dev/null +++ b/tests/ts/cramfs/mkfs @@ -0,0 +1,119 @@ +#!/bin/bash + +# +# Copyright (C) 2007 Karel Zak <kzak@redhat.com> +# +# This file is part of util-linux. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +TS_TOPDIR="${0%/*}/../.." +TS_DESC="mkfs checksums" + +. $TS_TOPDIR/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_CMD_MKCRAMFS" +ts_check_test_command "$TS_CMD_MOUNT" +ts_check_test_command "$TS_CMD_UMOUNT" +ts_check_test_command "$TS_HELPER_MD5" +ts_check_test_command "$TS_HELPER_SYSINFO" + +ts_skip_nonroot +ts_check_losetup + +ORIGPWD=$(pwd) +IMAGE_NAME="${TS_TESTNAME}-loop.img" +IMAGE_PATH="$TS_OUTDIR/$IMAGE_NAME" +IMAGE_SRC="$TS_OUTDIR/${TS_TESTNAME}-data" +LABEL="testCramfs" + +BYTE_ORDER=$($TS_HELPER_SYSINFO byte-order) +PAGE_SIZE=$($TS_HELPER_SYSINFO pagesize) +case "${BYTE_ORDER}:${PAGE_SIZE}" in + LE:4096) + MD5_EXP="a6667acb1cb0685d9eb5b9cd3724766c" ;; + LE:65536) + MD5_EXP="b60133682603b0118592b55f1dba017c" ;; + BE:4096) + MD5_EXP="eaf05031dc8ec97c91ba5c773635cc89" ;; + BE:8192 | BE:65536) + MD5_EXP="5859f87b185b1187fca3b2b00c809c03" ;; + *) + echo "warning ${TS_NS}: unknown checksum for ${BYTE_ORDER}:${PAGE_SIZE}" + MD5_EXP="unknown" ;; +esac + +ts_log "create mountpoint dir" + +[ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT + +ts_log "generate data" +rm -rf "$IMAGE_SRC" +mkdir -p $IMAGE_SRC +for d in `seq 0 110`; do + DIRNAME="$IMAGE_SRC/$(printf "dir-%03d" $d)" + mkdir -p $DIRNAME + for f in `seq 0 10`; do + FILENAME="$DIRNAME/$(printf "data.%03d" $f)" + printf "data in %03d-%03d" $d $f >> $FILENAME + done +done + +ts_cd "$IMAGE_SRC" + +ts_log "list checksums from original data" +find . -type f -exec md5sum {} \; | sort >> $TS_OUTPUT +echo >> $TS_OUTPUT + +ts_log "create cramfs image" +$TS_CMD_MKCRAMFS -n $LABEL $IMAGE_SRC $IMAGE_PATH >> $TS_OUTPUT 2>> $TS_ERRLOG +[ -s "$IMAGE_PATH" ] || ts_die "Cannot create $IMAGE_PATH" + +ts_cd "$TS_OUTDIR" + +ts_log "count MD5 from the image" +MD5_OUT=$("$TS_HELPER_MD5" < "$IMAGE_NAME") >> $TS_OUTPUT 2>> $TS_ERRLOG +if [ "$MD5_EXP" != "$MD5_OUT" -a "$MD5_EXP" != "unknown" ]; then + ts_log "is $MD5_OUT, should be $MD5_EXP" +fi +echo >> $TS_OUTPUT + +ts_log "create loop device from image" +DEVICE=$($TS_CMD_LOSETUP --show -f $IMAGE_PATH) +ts_register_loop_device "$DEVICE" + +ts_log "check the image" +ts_device_has "TYPE" "cramfs" $DEVICE +[ "$?" == "0" ] || ts_die "Cannot find cramfs on $DEVICE" + +ts_log "mount the image" +ts_mount "cramfs" -r -L $LABEL $TS_MOUNTPOINT + +# check it +ts_is_mounted $DEVICE || ts_die "Cannot find $DEVICE in /proc/mounts" + +ts_cd "$TS_MOUNTPOINT" + +ts_log "list the image" +export TZ='GMT-1' +ls -laR --time-style=long-iso . | sed 's:\. : :g' >> $TS_OUTPUT +echo >> $TS_OUTPUT + +ts_log "list checksums from new data" +find . -type f -exec md5sum {} \; | sort >> $TS_OUTPUT +echo >> $TS_OUTPUT + +ts_cd "$ORIGPWD" + +ts_log "umount the image" +ts_finalize + diff --git a/tests/ts/cramfs/mkfs-endianness b/tests/ts/cramfs/mkfs-endianness new file mode 100755 index 0000000..e3913d6 --- /dev/null +++ b/tests/ts/cramfs/mkfs-endianness @@ -0,0 +1,59 @@ +#!/bin/bash + +# +# Copyright (C) 2007 Karel Zak <kzak@redhat.com> +# +# This file is part of util-linux. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +TS_TOPDIR="${0%/*}/../.." +TS_DESC="mkfs endianness" + +. $TS_TOPDIR/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_CMD_MKCRAMFS" +ts_check_test_command "$TS_CMD_HEXDUMP" + +ts_skip_nonroot + +IMAGE_DATA="$TS_OUTDIR/${TS_TESTNAME}-data" +IMAGE_CREATED="$TS_OUTDIR/${TS_TESTNAME}-cramfs.img" #Image created during the test and compared against the known images. + +test_image() { + local TO_ENDIANNESS="$1"; shift + ts_log "create $TO_ENDIANNESS endian" + + $TS_CMD_MKCRAMFS -N "$TO_ENDIANNESS" -b 4096 "$IMAGE_DATA" \ + "$IMAGE_CREATED" >> $TS_OUTPUT 2>> $TS_ERRLOG + + $TS_CMD_HEXDUMP -C $IMAGE_CREATED >> $TS_OUTPUT + + rm "$IMAGE_CREATED" +} + +#generate test data, must be owner root +rm -rf "$IMAGE_DATA" +mkdir -p $IMAGE_DATA/dirA/dirB +yes "Testing cramfs 1234567890 Endianness check 1234567890 Endianness check" \ + | dd of=$IMAGE_DATA/dirA/dirB/a bs=512 count=1 &> /dev/null +yes "Testing cramfs 1234567890 Endianness check 1234567890 Endianness check" \ + | dd of=$IMAGE_DATA/dirA/dirB/b bs=512 count=30 &> /dev/null +# sudo may use whatever group +chgrp -R 0 $IMAGE_DATA + +#perform tests for both endians +test_image "little" +test_image "big" + +ts_finalize + |