btrfs-progs: tests: add shell quotes to mkfs test scripts

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2018-03-23 16:34:30 +01:00
parent a855717a87
commit 3ccad2a644
10 changed files with 53 additions and 54 deletions

View File

@ -11,28 +11,27 @@ setup_root_helper
test_get_info()
{
run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $dev1
run_check $SUDO_HELPER $TOP/btrfs check $dev1
run_check $SUDO_HELPER mount $dev1 $TEST_MNT
run_check $TOP/btrfs filesystem df $TEST_MNT
run_check $SUDO_HELPER $TOP/btrfs filesystem usage $TEST_MNT
run_check $SUDO_HELPER $TOP/btrfs device usage $TEST_MNT
run_check $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super "$dev1"
run_check $SUDO_HELPER "$TOP/btrfs" check "$dev1"
run_check $SUDO_HELPER mount "$dev1" "$TEST_MNT"
run_check "$TOP/btrfs" filesystem df "$TEST_MNT"
run_check $SUDO_HELPER "$TOP/btrfs" filesystem usage "$TEST_MNT"
run_check $SUDO_HELPER "$TOP/btrfs" device usage "$TEST_MNT"
run_check $SUDO_HELPER umount "$TEST_MNT"
}
test_do_mkfs()
{
run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \
$@
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$@"
}
test_mkfs_single()
{
test_do_mkfs $@ $dev1
test_do_mkfs "$@" "$dev1"
test_get_info
}
test_mkfs_multi()
{
test_do_mkfs $@ ${loopdevs[@]}
test_do_mkfs "$@" ${loopdevs[@]}
test_get_info
}

View File

@ -13,12 +13,12 @@ test_mkfs_with_size() {
local tmp
size="$1"
run_check truncate -s$size $TEST_DEV
imgsize=$(run_check_stdout stat --format=%s $TEST_DEV)
run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \
--rootdir $INTERNAL_BIN/Documentation \
$TEST_DEV
tmp=$(run_check_stdout stat --format=%s $TEST_DEV)
run_check truncate -s"$size" "$TEST_DEV"
imgsize=$(run_check_stdout stat --format=%s "$TEST_DEV")
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f \
--rootdir "$INTERNAL_BIN/Documentation" \
"$TEST_DEV"
tmp=$(run_check_stdout stat --format=%s "$TEST_DEV")
if ! [ "$imgsize" = "$tmp" ]; then
_fail "image size changed from $imgsize to $tmp"
fi

View File

@ -11,31 +11,31 @@ prepare_test_dev
# prep device
dmname=\
btrfs-test-with-very-long-name-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
dmdev=/dev/mapper/$dmname
dmdev="/dev/mapper/$dmname"
run_check truncate -s0 img
chmod a+w img
run_check truncate -s2g img
loopdev=`run_check_stdout $SUDO_HELPER losetup --find --show img`
run_check $SUDO_HELPER dmsetup create $dmname --table "0 1048576 linear $loopdev 0"
run_check $SUDO_HELPER dmsetup create "$dmname" --table "0 1048576 linear $loopdev 0"
dmbase=`readlink -f $dmdev`
dmbase=`readlink -f "$dmdev"`
base=`basename "$dmbase"`
rot=/sys/class/block/$base/queue/rotational
rot="/sys/class/block/$base/queue/rotational"
# switch rotational
run_check cat $rot
echo 0 | run_check $SUDO_HELPER tee $rot
run_check cat $rot
echo 0 | run_check $SUDO_HELPER tee "$rot"
run_check cat "$rot"
# test
run_check_stdout $SUDO_HELPER $TOP/mkfs.btrfs -f $@ $dmdev |
run_check_stdout $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$@" "$dmdev" |
grep -q 'SSD detected:.*yes' || _fail 'SSD not detected'
run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $dmdev
run_check $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super "$dmdev"
# cleanup
run_check $SUDO_HELPER dmsetup remove $dmname
run_mayfail $SUDO_HELPER losetup -d $loopdev
run_check $SUDO_HELPER dmsetup remove "$dmname"
run_mayfail $SUDO_HELPER losetup -d "$loopdev"
run_check truncate -s0 img
rm img

View File

@ -18,15 +18,15 @@ cp partition-1g-1g img
run_check truncate -s2g img
loopdev=$(run_check_stdout $SUDO_HELPER losetup --partscan --find --show img)
base=$(basename $loopdev)
base=$(basename "$loopdev")
# expect partitions named like loop0p1 etc
for looppart in $(ls /dev/$base?*); do
run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $looppart
run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $looppart
for looppart in $(ls /dev/"$base"?*); do
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$looppart"
run_check $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super "$looppart"
done
# cleanup
run_check $SUDO_HELPER losetup -d $loopdev
run_check $SUDO_HELPER losetup -d "$loopdev"
run_check truncate -s0 img
rm img

View File

@ -11,9 +11,9 @@ prepare_test_dev
test_mkfs_single()
{
run_check $SUDO_HELPER $TOP/mkfs.btrfs -f "$@" $TEST_DEV
run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $TEST_DEV
run_check $SUDO_HELPER $TOP/btrfs check $TEST_DEV
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$@" "$TEST_DEV"
run_check $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-super "$TEST_DEV"
run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV"
}
# default
@ -22,14 +22,14 @@ test_mkfs_single
# nodesize >= sectorsize
for nodesize in 4096 8192 16384 32768 65536; do
for sectorsize in 4096 8192 16384 32768 65536; do
[ $nodesize -lt $sectorsize ] && continue
test_mkfs_single -n $nodesize -s $sectorsize -d single -m single
test_mkfs_single -n $nodesize -s $sectorsize -d single -m dup
[ "$nodesize" -lt "$sectorsize" ] && continue
test_mkfs_single -n "$nodesize" -s "$sectorsize" -d single -m single
test_mkfs_single -n "$nodesize" -s "$sectorsize" -d single -m dup
done
done
# nodesize, mixed mode
for nodesize in 4k 8k 16k 32k 64k; do
test_mkfs_single -n $nodesize -s $nodesize -d single -m single --mixed
test_mkfs_single -n $nodesize -s $nodesize -d dup -m dup --mixed
test_mkfs_single -n "$nodesize" -s "$nodesize" -d single -m single --mixed
test_mkfs_single -n "$nodesize" -s "$nodesize" -d dup -m dup --mixed
done

View File

@ -19,13 +19,13 @@ do_test()
{
sectorsize=$1
nodesize=$2
run_mayfail $TOP/mkfs.btrfs -f -O $features -n $nodesize -s $sectorsize \
$TEST_DEV
run_mayfail "$TOP/mkfs.btrfs" -f -O "$features" -n "$nodesize" -s "$sectorsize" \
"$TEST_DEV"
ret=$?
if [ $ret == 0 ]; then
run_check $TOP/btrfs check $TEST_DEV
if [ "$ret" == 0 ]; then
run_check "$TOP/btrfs" check "$TEST_DEV"
fi
return $ret
return "$ret"
}
# Invalid: Unaligned sectorsize and nodesize

View File

@ -14,12 +14,12 @@ do_test()
# the minimal device size for the given option combination
prepare_test_dev 1M
output=$(run_mustfail_stdout "mkfs.btrfs for small image" \
"$TOP/mkfs.btrfs" -f $@ "$TEST_DEV")
"$TOP/mkfs.btrfs" -f "$@" "$TEST_DEV")
good_size=$(echo "$output" | grep -oP "(?<=is )\d+")
prepare_test_dev "$good_size"
echo "Minimal device size is $good_size" >> "$RESULTS"
run_check $TOP/mkfs.btrfs -f $@ "$TEST_DEV"
run_check $TOP/mkfs.btrfs -f "$@" "$TEST_DEV"
run_check_mount_test_dev
run_check_umount_test_dev
}

View File

@ -11,7 +11,7 @@ fs_size=$((512 * 1024 * 1024))
bs=$((1024 * 1024))
tmp=$(mktemp -d --tmpdir btrfs-progs-mkfs.rootdirXXXXXXX)
prepare_test_dev $fs_size
prepare_test_dev "$fs_size"
# No shrink case
@ -20,7 +20,7 @@ run_check_mount_test_dev
# We should be able to write at least half of the fs size data since the fs is
# not shrunk
run_check $SUDO_HELPER dd if=/dev/zero bs=$bs count=$(($fs_size / $bs / 2)) \
run_check $SUDO_HELPER dd if=/dev/zero bs="$bs" count=$(($fs_size / $bs / 2)) \
of="$TEST_MNT/file"
run_check_umount_test_dev
@ -31,7 +31,7 @@ run_check "$TOP/mkfs.btrfs" -f --rootdir "$tmp" --shrink "$TEST_DEV"
run_check_mount_test_dev
run_mustfail "mkfs.btrfs for shrink rootdir" \
$SUDO_HELPER dd if=/dev/zero bs=$bs count=$(($fs_size / $bs / 2)) \
$SUDO_HELPER dd if=/dev/zero bs="$bs" count=$(($fs_size / $bs / 2)) \
of="$TEST_MNT/file"
run_check_umount_test_dev

View File

@ -22,14 +22,14 @@ do_one_test ()
dump-tree -t device "$TEST_DEV" | \
grep -oP '(?<=DEV_EXTENT )[[:digit:]]*' | head -n1)
if [ -z $first_dev_extent ]; then
if [ -z "$first_dev_extent" ]; then
_fail "failed to get first device extent"
fi
echo "first dev extent starts at $first_dev_extent" >> "$RESULTS"
echo "reserved range is [0, $(( 1024 * 1024)))" >> "$RESULTS"
# First device extent should not start below 1M
if [ $first_dev_extent -lt $(( 1024 * 1024 )) ]; then
if [ "$first_dev_extent" -lt $(( 1024 * 1024 )) ]; then
_fail "first device extent occupies reserved 0~1M range"
fi
}

View File

@ -21,7 +21,7 @@ create_file()
test_mkfs_rootdir()
{
nodesize=$1
run_check "$TOP/mkfs.btrfs" --nodesize $nodesize -f --rootdir "$tmp" \
run_check "$TOP/mkfs.btrfs" --nodesize "$nodesize" -f --rootdir "$tmp" \
"$TEST_DEV"
run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV"
}
@ -39,8 +39,8 @@ for i in 512 1024 2048 4096 8192 16384 32768; do
done
for nodesize in 4096 8192 16384 32768 65536; do
if [ $nodesize -ge $pagesize ]; then
test_mkfs_rootdir $nodesize
if [ "$nodesize" -ge "$pagesize" ]; then
test_mkfs_rootdir "$nodesize"
fi
done
rm -rf -- "$tmp"