| #!/bin/sh |
| set -e |
| |
| mnt=/mnt/mount |
| tmp=$(mktemp -d) |
| trap "sh -c 'sudo umount ${mnt} 2>/dev/null; rm -rf ${tmp}'" EXIT INT |
| |
| build=${PWD}/build |
| |
| test_ext2() { |
| type=$1 |
| img=${tmp}/${type}.img |
| |
| printf "\n===> Prepping \`${img}'\n" |
| dd if=/dev/zero bs=1M count=64 >${img} 2>/dev/null |
| mkfs.${type} -E root_owner ${img} >/dev/null 2>&1 |
| |
| sudo mount -o loop ${img} ${mnt} -o rw |
| mkdir -p ${mnt}/dir/subdir |
| |
| echo " ==> Adding \`test' files and links" |
| echo 'Moin!' >${mnt}/test |
| echo 'Moin! from `dir'\' >${mnt}/dir/test |
| echo 'Moin! from `subdir'\' >${mnt}/dir/subdir/test |
| ln -s test ${mnt}/l5 |
| ln -s ../l5 ${mnt}/dir/l4 |
| ln -s ../l4 ${mnt}/dir/subdir/l3 |
| ln -s ../dir/subdir/l3 ${mnt}/dir/l2 |
| ln -s ../dir/subdir/../l2 ${mnt}/dir/l1 |
| ln -s l1 ${mnt}/dir/ltest |
| ln -s ../../dir/../dir/../dir/../dir/subdir/../../dir/subdir/../subdir/../subdir/../../dir/test ${mnt}/dir/subdir/ltest |
| |
| echo " ==> Adding random small files" |
| i=0; step=123; files=12345 |
| for j in $(seq $((files/step))); do |
| dd if=/dev/urandom bs=123 count=1 2>/dev/null | \ |
| tee $(printf "${mnt}/dir/random%05d " $(seq $((i+1)) $((i+step)))) >/dev/null |
| i=$((i+step)) |
| done |
| |
| echo " => Removing some files to produce gaps" |
| i=0 |
| for j in $(seq $((files/step))); do |
| rm $(printf "${mnt}/dir/random%05d " $(seq $((i+2)) 2 $((i+step)))) |
| i=$((i+step)) |
| done |
| |
| echo " ==> Adding a big file (should be fragmented)" |
| dd if=/dev/urandom bs=1M count=30 >${mnt}/random 2>/dev/null |
| |
| echo " ==> Removing some more small files" |
| i=0 |
| for j in $(seq $((files/step))); do |
| rm $(printf "${mnt}/dir/random%05d " $(seq $((i+3)) 4 $((i+step)))) |
| rm $(printf "${mnt}/dir/random%05d " $(seq $((i+5)) 8 $((i+step)))) |
| rm $(printf "${mnt}/dir/random%05d " $(seq $((i+9)) 16 $((i+step)))) |
| i=$((i+step)) |
| done |
| |
| echo " ==> Adding a big, fragmented, sparse file" |
| for i in $(seq 1 2 8765); do |
| dd if=/dev/urandom bs=4K count=1 conv=notrunc \ |
| seek=${i} of=${mnt}/dir/subdir/sparse 2>/dev/null |
| done |
| if [ "${type}" = "ext4" ]; then |
| echo " => Increasing sparse file >1GiB" |
| dd if=/dev/urandom bs=4K count=1 conv=notrunc \ |
| seek=345678 of=${mnt}/dir/subdir/sparse 2>/dev/null |
| fi |
| |
| sudo umount ${mnt} |
| |
| test_img ${img} |
| } |
| |
| test_isofs() { |
| img=${tmp}/test.iso |
| template=${tmp}/ext2.img |
| |
| printf "\n===> Prepping \`${img}'\n" |
| |
| sudo mount -o loop ${template} ${mnt} -o ro |
| |
| mkisofs -o ${img} ${mnt} |
| |
| sudo umount ${mnt} |
| |
| test_img ${img} |
| } |
| |
| test_img() { |
| img=$1 |
| |
| sudo mount -o loop ${img} ${mnt} -o ro |
| cd ${mnt} |
| |
| printf "\n ==> Running simple test for \`test' files\n" |
| ${build}/fstest -d ${img} |
| |
| printf "\n ==> Comparing all file contents" |
| find . \( -name lost+found -prune \) -o ! -type d -printf . \ |
| \( -exec sh -c "${build}/fscat -d ${img} {} | cmp - {}" \; \ |
| -o \( -exec false {} + -quit \) \) |
| printf " done\n" |
| |
| printf "\n ==> Comparing all file contents (at once)... " |
| sum=$(find . \( -name lost+found -prune \) -o ! -type d \ |
| -exec ${build}/fscat -d ${img} {} + | cksum) |
| sum2=$(find . \( -name lost+found -prune \) -o ! -type d -exec cat {} + | cksum) |
| if [ "${sum}" = "${sum2}" ]; then |
| printf "done\n" |
| else |
| printf "FAILED!\n" |
| exit 1 |
| fi |
| |
| cd - >/dev/null |
| sudo umount ${mnt} |
| } |
| |
| test_ext2 ext2 |
| test_ext2 ext4 |
| test_isofs |