diff options
Diffstat (limited to 'tests/misc-tests')
-rwxr-xr-x | tests/misc-tests/006-image-on-missing-device/test.sh | 40 | ||||
-rwxr-xr-x | tests/misc-tests/011-delete-missing-device/test.sh | 41 | ||||
-rwxr-xr-x | tests/misc-tests/022-filesystem-du-on-empty-subvol/test.sh | 26 | ||||
-rwxr-xr-x | tests/misc-tests/023-device-usage-with-missing-device/test.sh | 40 | ||||
-rwxr-xr-x | tests/misc-tests/024-inspect-internal-rootid/test.sh | 57 | ||||
-rw-r--r-- | tests/misc-tests/025-zstd-compression/compress.raw.xz | bin | 0 -> 18220 bytes | |||
-rwxr-xr-x | tests/misc-tests/025-zstd-compression/test.sh | 56 | ||||
-rwxr-xr-x | tests/misc-tests/026-image-non-printable-chars/test.sh | 30 | ||||
-rwxr-xr-x | tests/misc-tests/027-subvol-list-deleted-toplevel/test.sh | 18 |
9 files changed, 241 insertions, 67 deletions
diff --git a/tests/misc-tests/006-image-on-missing-device/test.sh b/tests/misc-tests/006-image-on-missing-device/test.sh index 5b6fe065..2766fb17 100755 --- a/tests/misc-tests/006-image-on-missing-device/test.sh +++ b/tests/misc-tests/006-image-on-missing-device/test.sh @@ -10,38 +10,8 @@ check_prereq btrfs-image check_prereq mkfs.btrfs check_prereq btrfs -ndevs=2 -declare -a devs -dev1= -dev2= - setup_root_helper - -# TODO: move the helpers to common - -prepare_devices() -{ - for i in `seq $ndevs`; do - touch img$i - chmod a+rw img$i - truncate -s0 img$i - truncate -s2g img$i - devs[$i]=`run_check_stdout $SUDO_HELPER losetup --find --show img$i` - done -} - -cleanup_devices() -{ - for dev in ${devs[@]}; do - run_mayfail $SUDO_HELPER losetup -d $dev - done - for i in `seq $ndevs`; do - truncate -s0 img$i - done - run_check $SUDO_HELPER losetup --all -} - test_image_dump() { run_check $SUDO_HELPER $TOP/btrfs check $dev1 @@ -65,13 +35,15 @@ test_run() # btrfs-image must not loop run_mayfail wipefs -a $dev2 run_check $SUDO_HELPER losetup -d $dev2 + unset loopdevs[2] run_check $SUDO_HELPER $TOP/btrfs filesystem show $dev1 test_image_dump } -prepare_devices -dev1=${devs[1]} -dev2=${devs[2]} +setup_loopdevs 2 +prepare_loopdevs +dev1=${loopdevs[1]} +dev2=${loopdevs[2]} test_run -cleanup_devices +cleanup_loopdevs diff --git a/tests/misc-tests/011-delete-missing-device/test.sh b/tests/misc-tests/011-delete-missing-device/test.sh index 5b5f9786..8a1b14b1 100755 --- a/tests/misc-tests/011-delete-missing-device/test.sh +++ b/tests/misc-tests/011-delete-missing-device/test.sh @@ -6,38 +6,11 @@ source $TOP/tests/common check_prereq mkfs.btrfs check_prereq btrfs -ndevs=4 -declare -a devs -dev1= -devtodel= - setup_root_helper -prepare_devices() -{ - for i in `seq $ndevs`; do - touch img$i - chmod a+rw img$i - truncate -s0 img$i - truncate -s2g img$i - devs[$i]=`run_check_stdout $SUDO_HELPER losetup --find --show img$i` - done -} - -cleanup_devices() -{ - for dev in ${devs[@]}; do - run_mayfail $SUDO_HELPER losetup -d $dev - done - for i in `seq $ndevs`; do - truncate -s0 img$i - done - run_check $SUDO_HELPER losetup --all -} - test_do_mkfs() { - run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $@ ${devs[@]} + run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $@ ${loopdevs[@]} run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $dev1 run_check $SUDO_HELPER $TOP/btrfs check $dev1 run_check $SUDO_HELPER $TOP/btrfs filesystem show @@ -47,6 +20,7 @@ test_wipefs() { run_check $SUDO_HELPER wipefs -a $devtodel run_check $SUDO_HELPER losetup -d $devtodel + unset loopdevs[3] run_check $SUDO_HELPER losetup --all run_check $TOP/btrfs filesystem show } @@ -70,13 +44,14 @@ test_delete_missing() run_check_umount_test_dev } -prepare_devices -dev1=${devs[1]} -devtodel=${devs[3]} +setup_loopdevs 4 +prepare_loopdevs +dev1=${loopdevs[1]} +devtodel=${loopdevs[3]} TEST_DEV=$dev1 -test_do_mkfs +test_do_mkfs -m raid1 -d raid1 test_wipefs test_delete_missing -cleanup_devices +cleanup_loopdevs diff --git a/tests/misc-tests/022-filesystem-du-on-empty-subvol/test.sh b/tests/misc-tests/022-filesystem-du-on-empty-subvol/test.sh new file mode 100755 index 00000000..72cf076f --- /dev/null +++ b/tests/misc-tests/022-filesystem-du-on-empty-subvol/test.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# +# btrfs fi du should handle empty subvolumes (with ino == 2) + +source "$TOP/tests/common" + +check_prereq mkfs.btrfs +check_prereq btrfs +setup_root_helper +prepare_test_dev + +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev + +cd "$TEST_MNT" + +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create test1 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create test1/test2 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot test1 test1-snap +run_check $SUDO_HELPER "$TOP/btrfs" filesystem du -s test1 +run_check_stdout $SUDO_HELPER "$TOP/btrfs" filesystem du -s test1-snap | \ + grep -q "ERROR:.*ioctl" && _fail "empty subvolume not handled" + +cd .. + +run_check_umount_test_dev diff --git a/tests/misc-tests/023-device-usage-with-missing-device/test.sh b/tests/misc-tests/023-device-usage-with-missing-device/test.sh new file mode 100755 index 00000000..3c8ba85c --- /dev/null +++ b/tests/misc-tests/023-device-usage-with-missing-device/test.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# check if 'device slack' is reported as zero when a device is missing + +source "$TOP/tests/common" + +check_prereq btrfs-image +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper + +test_run() +{ + # empty filesystem, with enough redundancy so degraded mount works + run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -d raid1 -m raid1 $dev1 $dev2 + + TEST_DEV="$dev1" + run_check_mount_test_dev + run_check $SUDO_HELPER "$TOP/btrfs" filesystem usage "$TEST_MNT" + run_check_stdout $SUDO_HELPER "$TOP/btrfs" device usage "$TEST_MNT" | \ + grep -q "slack.*16\\.00EiB" && _fail + run_check_umount_test_dev + + run_mayfail wipefs -a $dev2 + run_check $SUDO_HELPER losetup -d $dev2 + unset loopdevs[2] + + run_check_mount_test_dev -o degraded,ro + run_check $SUDO_HELPER "$TOP/btrfs" filesystem usage "$TEST_MNT" + run_check_stdout $SUDO_HELPER "$TOP/btrfs" device usage "$TEST_MNT" | \ + grep -q "slack.*16\\.00EiB" && _fail + run_check_umount_test_dev +} + +setup_loopdevs 2 +prepare_loopdevs +dev1=${loopdevs[1]} +dev2=${loopdevs[2]} +test_run +cleanup_loopdevs diff --git a/tests/misc-tests/024-inspect-internal-rootid/test.sh b/tests/misc-tests/024-inspect-internal-rootid/test.sh new file mode 100755 index 00000000..40e382bb --- /dev/null +++ b/tests/misc-tests/024-inspect-internal-rootid/test.sh @@ -0,0 +1,57 @@ +#!/bin/bash +# +# test commands of inspect-internal rootid + +source "$TOP/tests/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +prepare_test_dev + +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev +run_check $SUDO_HELPER chmod a+rw "$TEST_MNT" +cd "$TEST_MNT" + +run_check "$TOP/btrfs" subvolume create sub +run_check "$TOP/btrfs" subvolume create sub/subsub +run_check mkdir dir +run_check touch file1 +run_check touch dir/file2 +run_check touch sub/file3 + +id1=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid .) \ + || { echo $id1; exit 1; } +id2=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid sub) \ + || { echo $id2; exit 1; } +id3=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid sub/subsub) \ + || { echo $id3; exit 1; } +id4=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid dir) \ + || { echo $id4; exit 1; } +id5=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid file1) \ + || { echo $id5; exit 1; } +id6=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid dir/file2) \ + || { echo $id6; exit 1; } +id7=$(run_check_stdout "$TOP/btrfs" inspect-internal rootid sub/file3) \ + || { echo $id7; exit 1; } + +if ! ([ $id1 -ne $id2 ] && [ $id1 -ne $id3 ] && [ $id2 -ne $id3 ]); then + _fail "inspect-internal rootid: each subvolume must have different id" +fi + +if ! ([ $id1 -eq $id4 ] && [ $id1 -eq $id5 ] && [ $id1 -eq $id6 ]); then + _fail "inspect-internal rootid: rootid mismatch found" +fi + +if ! ([ $id2 -eq $id7 ]); then + _fail "inspect-internal rootid: rootid mismatch found" +fi + +run_mustfail "should fail for non existent file" \ + "$TOP/btrfs" inspect-internal rootid no_such_file +run_mustfail "should fail for non-btrfs filesystem" \ + "$TOP/btrfs" inspect-internal rootid /dev/null + +cd .. +run_check_umount_test_dev diff --git a/tests/misc-tests/025-zstd-compression/compress.raw.xz b/tests/misc-tests/025-zstd-compression/compress.raw.xz Binary files differnew file mode 100644 index 00000000..67aaf17f --- /dev/null +++ b/tests/misc-tests/025-zstd-compression/compress.raw.xz diff --git a/tests/misc-tests/025-zstd-compression/test.sh b/tests/misc-tests/025-zstd-compression/test.sh new file mode 100755 index 00000000..e95dcb36 --- /dev/null +++ b/tests/misc-tests/025-zstd-compression/test.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# Test zstd compression support on a prebuilt btrfs image + +source "$TOP/tests/common" + +check_prereq btrfs +check_global_prereq md5sum + +# Extract the test image +image=$(extract_image compress.raw.xz) + +check_dump_tree() { + local image=$1 + local string=$2 + + run_check_stdout "$TOP/btrfs" inspect-internal dump-tree "$image" \ + | grep -q "$string" \ + || _fail "btrfs inspect-internal dump-tree didn't print $string" +} + +# Check that there are blocks of each compression type +check_dump_tree "$image" "extent compression 1 (zlib)" +check_dump_tree "$image" "extent compression 2 (lzo)" +check_dump_tree "$image" "extent compression 3 (zstd)" + +# Check that the filesystem has incompat COMPRESS_ZSTD +run_check_stdout "$TOP/btrfs" inspect-internal dump-super -f "$image" \ + | grep -q COMPRESS_ZSTD \ + || _fail "btrfs inspect-internal dump-super no incompat COMPRESS_ZSTD" + +# Create a temporary directory and restore the filesystem +restore_tmp=$(mktemp --tmpdir -d btrfs-progs-022-zstd-compression.XXXXXXXXXX) +run_check "$TOP/btrfs" restore "$image" "$restore_tmp" + +# Expect 3 files +num_files=$(ls -1 "$restore_tmp" | wc -l) +[ "$num_files" == 3 ] || _fail "number of files does not match" + +check_md5() { + local file="$1" + local expect_md5="$2" + + md5=$(run_check_stdout md5sum "$file" | cut -d ' ' -f 1) + [ "$md5" == "$expect_md5" ] \ + || _fail "$file digest $md5 does not match $expect_md5" +} + +# Each should be 200K of zeros +expect_md5=$(dd if=/dev/zero bs=1K count=200 status=none | md5sum | cut -d ' ' -f 1) +check_md5 "$restore_tmp/zlib" "$expect_md5" +check_md5 "$restore_tmp/lzo" "$expect_md5" +check_md5 "$restore_tmp/zstd" "$expect_md5" + +# Clean up +rm -r -- "$restore_tmp" +rm -- "$image" diff --git a/tests/misc-tests/026-image-non-printable-chars/test.sh b/tests/misc-tests/026-image-non-printable-chars/test.sh new file mode 100755 index 00000000..8018586f --- /dev/null +++ b/tests/misc-tests/026-image-non-printable-chars/test.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# check that sanitized names with matching crc do not contain unprintable +# characters, namely 0x7f + +source "$TOP/tests/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +prepare_test_dev + +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev +run_check $SUDO_HELPER chmod a+rw "$TEST_MNT" + +# known to produce char 0x7f == 127 +touch "$TEST_MNT/|5gp!" + +run_check_umount_test_dev + +run_check $SUDO_HELPER "$TOP/btrfs-image" -ss "$TEST_DEV" img +run_check $SUDO_HELPER "$TOP/btrfs-image" -r img img.restored +run_check_stdout $SUDO_HELPER "$TOP/btrfs" inspect-internal dump-tree img.restored > img.dump + +ch7f=$(echo -en '\x7f') +if grep -q "$ch7f" img.dump; then + _fail "found char 0x7f in the sanitized names" +fi + +rm -f -- img img.restored img.dump diff --git a/tests/misc-tests/027-subvol-list-deleted-toplevel/test.sh b/tests/misc-tests/027-subvol-list-deleted-toplevel/test.sh new file mode 100755 index 00000000..ee41d71f --- /dev/null +++ b/tests/misc-tests/027-subvol-list-deleted-toplevel/test.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# check that the toplevel subvolume is not listed as regular or deleted + +source "$TOP/tests/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +prepare_test_dev + +run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV" +run_check_mount_test_dev +run_check_stdout $SUDO_HELPER "$TOP/btrfs" subvolume list "$TEST_MNT" | + grep -i -q "id 5" && _fail "found toplevel among regular" +run_check_stdout $SUDO_HELPER "$TOP/btrfs" subvolume list -d "$TEST_MNT" | + grep -i -q "id 5.*DELETED" && _fail "found toplevel among deleted" + +run_check_umount_test_dev |