summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/README.md15
-rwxr-xr-xtests/build-tests.sh22
-rwxr-xr-xtests/cli-tests/007-check-force/test.sh32
-rw-r--r--tests/common77
-rw-r--r--tests/common.convert49
-rw-r--r--tests/common.local11
-rwxr-xr-xtests/convert-tests.sh11
-rwxr-xr-xtests/convert-tests/001-ext2-basic/test.sh1
-rwxr-xr-xtests/convert-tests/002-ext3-basic/test.sh1
-rwxr-xr-xtests/convert-tests/003-ext4-basic/test.sh1
-rwxr-xr-xtests/convert-tests/005-delete-all-rollback/test.sh3
-rwxr-xr-xtests/convert-tests/006-large-hole-extent/test.sh1
-rwxr-xr-xtests/convert-tests/007-unsupported-block-sizes/test.sh1
-rwxr-xr-xtests/convert-tests/008-readonly-image/test.sh7
-rwxr-xr-xtests/convert-tests/009-common-inode-flags/test.sh5
-rwxr-xr-xtests/convert-tests/010-reiserfs-basic/test.sh21
-rwxr-xr-xtests/convert-tests/011-reiserfs-delete-all-rollback/test.sh72
-rwxr-xr-xtests/convert-tests/012-reiserfs-large-hole-extent/test.sh28
-rwxr-xr-xtests/convert-tests/013-reiserfs-common-inode-flags/test.sh42
-rwxr-xr-xtests/convert-tests/014-reiserfs-tail-handling/test.sh79
-rw-r--r--tests/fsck-tests/026-bad-dir-item-name/default_case.img.xzbin0 -> 1924 bytes
-rwxr-xr-xtests/fsck-tests/026-bad-dir-item-name/test.sh13
-rw-r--r--tests/fuzz-tests/images/bko-155551-unaligned-tree-block.raw.txt49
-rw-r--r--tests/fuzz-tests/images/bko-155551-unaligned-tree-block.raw.xzbin0 -> 3692 bytes
-rwxr-xr-xtests/misc-tests/006-image-on-missing-device/test.sh40
-rwxr-xr-xtests/misc-tests/011-delete-missing-device/test.sh41
-rwxr-xr-xtests/misc-tests/022-filesystem-du-on-empty-subvol/test.sh26
-rwxr-xr-xtests/misc-tests/023-device-usage-with-missing-device/test.sh40
-rwxr-xr-xtests/misc-tests/024-inspect-internal-rootid/test.sh57
-rw-r--r--tests/misc-tests/025-zstd-compression/compress.raw.xzbin0 -> 18220 bytes
-rwxr-xr-xtests/misc-tests/025-zstd-compression/test.sh56
-rwxr-xr-xtests/misc-tests/026-image-non-printable-chars/test.sh30
-rwxr-xr-xtests/misc-tests/027-subvol-list-deleted-toplevel/test.sh18
-rwxr-xr-xtests/mkfs-tests/001-basic-profiles/test.sh35
-rwxr-xr-xtests/mkfs-tests/005-long-device-name-for-ssd/test.sh1
-rwxr-xr-xtests/mkfs-tests/006-partitioned-loopdev/test.sh1
-rwxr-xr-xtests/mkfs-tests/009-special-files-for-rootdir/test.sh36
-rwxr-xr-xtests/scan-results.sh2
-rw-r--r--tests/sha-private.h4
-rw-r--r--tests/sha224-256.c20
40 files changed, 806 insertions, 142 deletions
diff --git a/tests/README.md b/tests/README.md
index a8d3a2ba..04d2ce2a 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -30,7 +30,7 @@ category, eg. `fsck-tests-results.txt`.
## Selective testing
-The test are prefixed by a number for ordering and uniqueness. To run a
+The tests are prefixed by a number for ordering and uniqueness. To run a
particular test use:
```shell
@@ -76,8 +76,7 @@ will run the first test in fsck-tests subdirectory.
* anything that does not fit to the above, the test driver script will only
execute `./test.sh` in the test directory
-*tests/common:*
-*tests/common.convert:*
+*tests/common, tests/common.convert:*
* script with shell helpers, separated by functionality
@@ -146,6 +145,13 @@ the loop devices as they are managed on a per-test basis.
There's a script `test-console.sh` that will run shell commands in a loop and
logs the output with the testing environment set up.
+### Runtime dependencies
+
+The tests use some common system utilities like `find`, `rm`, `dd`. Additionally,
+specific tests need the following packages installed: `acl`, `attr`,
+`e2fsprogs`, `reiserfsprogs`
+
+
## New test
1. Pick the category for the new test or fallback to `misc-tests` if not sure. For
@@ -162,7 +168,7 @@ begining of `test.sh`. You don't need to add the file to git yet.
4. Write the test commands, comment anything that's not obvious.
-5. Test your test. Use the `TEST` variable to jump right to your test:
+5. **Test your test.** Use the `TEST` variable to jump right to your test:
```shell
$ make TEST=012\* tests-misc # from top directory
$ TEST=012\* ./misc-tests.sh # from tests/
@@ -172,6 +178,7 @@ $ TEST=012\* ./misc-tests.sh # from tests/
fixed the bug (or both). Subject line of the shall mention the name of the
new directory for ease of search, eg. `btrfs-progs: tests: add 012-subvolume-sync-must-wait`
+
### Crafted/fuzzed images
Images that are create by fuzzing or specially crafted to trigger some error
diff --git a/tests/build-tests.sh b/tests/build-tests.sh
index 4dc8744e..15db42af 100755
--- a/tests/build-tests.sh
+++ b/tests/build-tests.sh
@@ -87,5 +87,27 @@ build_make_targets
conf='--disable-convert'
build_make_targets
+conf='--with-convert=ext2'
+build_make_targets
+
+conf='--with-convert=ext2,reiserfs'
+build_make_targets
+
+conf='--enable-zstd'
+build_make_targets
+
+# debugging builds, just the default targets
+target='D=1'
+buildme
+
+target='D=asan'
+buildme
+
+target='D=tsan'
+buildme
+
+target='D=ubsan'
+buildme
+
echo "---------------------------------------------------"
echo "$verdict"
diff --git a/tests/cli-tests/007-check-force/test.sh b/tests/cli-tests/007-check-force/test.sh
new file mode 100755
index 00000000..12b30205
--- /dev/null
+++ b/tests/cli-tests/007-check-force/test.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+#
+# test 'btrfs check --force' on a mounted filesystem
+
+source "$TOP/tests/common"
+
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+setup_root_helper
+
+# we need to use a real block device, because the check opens the device in
+# exclusive mode, that unfortunatelly behaves differently for direct file
+# access and for the real /dev/loop0 device
+setup_loopdevs 1
+prepare_loopdevs
+TEST_DEV=${loopdevs[1]}
+
+run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
+run_check_mount_test_dev
+run_mustfail "checking mounted filesystem without --force" \
+ $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV"
+run_check $SUDO_HELPER "$TOP/btrfs" check --force "$TEST_DEV"
+run_mustfail "checking mounted filesystem with --force --repair" \
+ $SUDO_HELPER "$TOP/btrfs" check --force --repair "$TEST_DEV"
+run_check_umount_test_dev
+run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV"
+run_check $SUDO_HELPER "$TOP/btrfs" check --force "$TEST_DEV"
+run_mustfail "--force --repair on unmounted filesystem" \
+ $SUDO_HELPER "$TOP/btrfs" check --force --repair "$TEST_DEV"
+
+cleanup_loopdevs
diff --git a/tests/common b/tests/common
index bed60094..eb525a4d 100644
--- a/tests/common
+++ b/tests/common
@@ -21,6 +21,27 @@ _assert_path()
exit 1
}
+# $1: this string gets matched to files, absolute or relative path, or a
+# systemwide command available via $PATH
+_is_file_or_command()
+{
+ local msg
+
+ msg="$1"
+ if [ -z "$msg" ]; then
+ return 1
+ fi
+
+ if [ -f "$msg" -o -d "$msg" -o -b "$msg" ]; then
+ return 0
+ fi
+ msg=$(type -p -- "$msg")
+ if [ -f "$msg" ]; then
+ return 0
+ fi
+ return 1
+}
+
_fail()
{
echo "$*" | tee -a "$RESULTS"
@@ -133,9 +154,12 @@ run_check_stdout()
echo "############### $@" >> "$RESULTS" 2>&1
if [[ $TEST_LOG =~ tty ]]; then echo "CMD(stdout): $@" > /dev/tty; fi
if [ "$1" = 'root_helper' ]; then
- "$@" 2>&1 | tee -a "$RESULTS" || _fail "failed: $@"
+ "$@" 2>&1 | tee -a "$RESULTS"
else
- $INSTRUMENT "$@" 2>&1 | tee -a "$RESULTS" || _fail "failed: $@"
+ $INSTRUMENT "$@" 2>&1 | tee -a "$RESULTS"
+ fi
+ if [ ${PIPESTATUS[0]} -ne 0 ]; then
+ _fail "failed: $@"
fi
}
@@ -185,6 +209,11 @@ run_mustfail()
msg="$1"
shift
+ if _is_file_or_command "$msg"; then
+ echo "ASSERTION FAIL: 1st argument of run_mustfail must be a message"
+ exit 1
+ fi
+
ins=$(_get_spec_ins "$@")
spec=$(($ins-1))
cmd=$(eval echo "\${$spec}")
@@ -480,7 +509,7 @@ generate_dataset() {
;;
slow_symlink)
- long_filename=`date +%s | sha256sum | cut -f1 -d'-'`
+ long_filename=`date +%s | sha256sum | cut -f1 -d ' '`
run_check $SUDO_HELPER touch "$dirpath/$long_filename"
for num in $(seq 1 "$DATASET_SIZE"); do
run_check $SUDO_HELPER ln -s "$dirpath/$long_filename" "$dirpath/slow_slink.$num"
@@ -493,6 +522,48 @@ generate_dataset() {
esac
}
+# prepare environment for loop devices, set up the following variables
+# - nloopdevs -- number of desired devices
+# - loopdevs -- array containing paths to all devices (after prepare is called)
+# - loopdev_prefix -- file backed images starting with this string, 'img' by default
+#
+# $1: number of loop devices to be set up
+setup_loopdevs()
+{
+ if [ -z "$1" ]; then
+ _fail "setup_loopdevs needs a number"
+ fi
+ nloopdevs="$1"
+ loopdev_prefix=img
+ declare -a loopdevs
+
+}
+
+# create all loop devices from a given loopdev environment
+prepare_loopdevs()
+{
+ for i in `seq $nloopdevs`; do
+ touch $loopdev_prefix$i
+ chmod a+rw $loopdev_prefix$i
+ truncate -s0 $loopdev_prefix$i
+ truncate -s2g $loopdev_prefix$i
+ loopdevs[$i]=`run_check_stdout $SUDO_HELPER losetup --find --show $loopdev_prefix$i`
+ done
+}
+
+# detach loop devices and reset their size to 0, delete the files afterwards
+cleanup_loopdevs()
+{
+ for dev in ${loopdevs[@]}; do
+ run_check $SUDO_HELPER losetup -d $dev
+ done
+ for i in `seq $nloopdevs`; do
+ truncate -s0 $loopdev_prefix$i
+ rm -- "$loopdev_prefix$i"
+ done
+ run_check $SUDO_HELPER losetup --all
+}
+
init_env()
{
TEST_MNT="${TEST_MNT:-$TOP/tests/mnt}"
diff --git a/tests/common.convert b/tests/common.convert
index 2c19a4be..1be804cf 100644
--- a/tests/common.convert
+++ b/tests/common.convert
@@ -50,7 +50,7 @@ convert_test_preamble() {
msg="$2"
shift 3
echo " [TEST/conv] $msg, btrfs" "${features:-defaults}"
- echo "creating ext image with: $@" >> "$RESULTS"
+ echo "creating test image with: $@" >> "$RESULTS"
}
# prepare TEST_DEV before conversion, create filesystem and mount it, image
@@ -59,6 +59,8 @@ convert_test_preamble() {
# $2+: free form, command to create the filesystem, with appended -F
convert_test_prep_fs() {
local fstype
+ local force
+ local mountopts
fstype="$1"
shift
@@ -67,10 +69,21 @@ convert_test_prep_fs() {
run_check truncate -s 0 "$TEST_DEV"
# 256MB is the smallest acceptable btrfs image.
run_check truncate -s 512M "$TEST_DEV"
- run_check "$@" -F "$TEST_DEV"
+ force=
+ mountopts=
+ case "$fstype" in
+ ext[234])
+ force=-F ;;
+ reiserfs)
+ force=-ff
+ mountopts="-o acl,user_xattr,attrs" ;;
+ *)
+ _fail "unknown filesystem to convert: $fstype"
+ esac
+ run_check "$@" $force "$TEST_DEV"
# create a file to check btrfs-convert can convert regular file correct
- run_check_mount_convert_dev "$fstype"
+ run_check_mount_convert_dev "$fstype" $mountopts
# create a file inside the fs before convert, to make sure there is
# data covering btrfs backup superblock range (64M)
@@ -205,9 +218,21 @@ convert_test_post_checks_all() {
}
# do rollback and fsck
+# $1: filesystem name or alias (ext2 includes ext3 and ext4),
convert_test_post_rollback() {
+ local types
+
run_check "$TOP/btrfs-convert" --rollback "$TEST_DEV"
- run_check fsck -n -t ext2,ext3,ext4 "$TEST_DEV"
+ if [ -z "$1" ]; then
+ _fail "missing filesystem type to check"
+ fi
+ case "$1" in
+ ext[234]) types=ext2,ext3,ext4 ;;
+ reiserfs) types=reiserfs ;;
+ *) _fail "unknown filesystem type to check: $1" ;;
+ esac
+
+ run_check fsck -n -t "$types" "$TEST_DEV"
}
# simple wrapper for a convert test
@@ -248,5 +273,19 @@ convert_test() {
rm -- "$EXT_PERMTMP"
rm -- "$EXT_ACLTMP"
- convert_test_post_rollback
+ convert_test_post_rollback "$fstype"
+}
+
+load_module_reiserfs()
+{
+ $SUDO_HELPER modprobe reiserfs
+}
+
+check_kernel_support_reiserfs()
+{
+ if ! grep -iq 'reiserfs' /proc/filesystems; then
+ echo "WARNING: reiserfs filesystem not listed in /proc/filesystems, some tests might be skipped"
+ return 1
+ fi
+ return 0
}
diff --git a/tests/common.local b/tests/common.local
index 4f56bb08..d2b8d073 100644
--- a/tests/common.local
+++ b/tests/common.local
@@ -3,14 +3,13 @@
# additional arguments to various commands
# already defined, eg. via make argument
-if [ -n "$TEST_ENABLE_OVERRIDE" ]; then
- return
-fi
+if [ -z "$TEST_ENABLE_OVERRIDE" ]; then
+ # set to 'true'
+ TEST_ENABLE_OVERRIDE=false
-# set to 'true'
-TEST_ENABLE_OVERRIDE=false
+ TEST_ARGS_CHECK=--mode=lowmem
+fi
-TEST_ARGS_CHECK=--mode=lowmem
# gets arguments of a current command and can decide if the argument insertion
# should happen, eg. if some option combination does not make sense or would
diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh
index c5663367..2a92a58b 100755
--- a/tests/convert-tests.sh
+++ b/tests/convert-tests.sh
@@ -22,6 +22,11 @@ export TEST_DEV
rm -f "$RESULTS"
check_kernel_support
+check_kernel_support_reiserfs
+# anything expected by common.convert
+check_global_prereq getfacl
+check_global_prereq setfacl
+check_global_prereq md5sum
run_one_test() {
local testdir
@@ -36,10 +41,12 @@ run_one_test() {
# Only support custom test scripts
./test.sh
if [ $? -ne 0 ]; then
- _fail "test failed for case $testname"
if [[ $TEST_LOG =~ dump ]]; then
- cat "$RESULTS"
+ # the logs can be large and may exceed the
+ # limits, use 4MB for now
+ tail -c 3900000 "$RESULTS"
fi
+ _fail "test failed for case $testname"
fi
else
_fail "custom test script not found"
diff --git a/tests/convert-tests/001-ext2-basic/test.sh b/tests/convert-tests/001-ext2-basic/test.sh
index 7d8e87d8..d94bf0b6 100755
--- a/tests/convert-tests/001-ext2-basic/test.sh
+++ b/tests/convert-tests/001-ext2-basic/test.sh
@@ -6,6 +6,7 @@ source "$TOP/tests/common.convert"
setup_root_helper
prepare_test_dev 512M
check_prereq btrfs-convert
+check_global_prereq mke2fs
for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do
convert_test ext2 "$feature" "ext2 4k nodesize" 4096 mke2fs -b 4096
diff --git a/tests/convert-tests/002-ext3-basic/test.sh b/tests/convert-tests/002-ext3-basic/test.sh
index 5a33c2ca..f00e0e82 100755
--- a/tests/convert-tests/002-ext3-basic/test.sh
+++ b/tests/convert-tests/002-ext3-basic/test.sh
@@ -6,6 +6,7 @@ source "$TOP/tests/common.convert"
setup_root_helper
prepare_test_dev 512M
check_prereq btrfs-convert
+check_global_prereq mke2fs
for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do
convert_test ext3 "$feature" "ext3 4k nodesize" 4096 mke2fs -j -b 4096
diff --git a/tests/convert-tests/003-ext4-basic/test.sh b/tests/convert-tests/003-ext4-basic/test.sh
index df8bec28..d33f1d9a 100755
--- a/tests/convert-tests/003-ext4-basic/test.sh
+++ b/tests/convert-tests/003-ext4-basic/test.sh
@@ -6,6 +6,7 @@ source "$TOP/tests/common.convert"
setup_root_helper
prepare_test_dev 512M
check_prereq btrfs-convert
+check_global_prereq mke2fs
for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do
convert_test ext4 "$feature" "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096
diff --git a/tests/convert-tests/005-delete-all-rollback/test.sh b/tests/convert-tests/005-delete-all-rollback/test.sh
index 337413bb..19aa76d4 100755
--- a/tests/convert-tests/005-delete-all-rollback/test.sh
+++ b/tests/convert-tests/005-delete-all-rollback/test.sh
@@ -8,6 +8,7 @@ source "$TOP/tests/common.convert"
setup_root_helper
prepare_test_dev 512M
check_prereq btrfs-convert
+check_global_prereq mke2fs
# simple wrapper for a convert test
# $1: btrfs features, argument to -O
@@ -45,7 +46,7 @@ do_test() {
cd "$here"
run_check "$TOP/btrfs" filesystem sync "$TEST_MNT"
run_check_umount_test_dev
- convert_test_post_rollback
+ convert_test_post_rollback ext4
run_check_mount_convert_dev ext4
convert_test_post_check_checksums "$CHECKSUMTMP"
diff --git a/tests/convert-tests/006-large-hole-extent/test.sh b/tests/convert-tests/006-large-hole-extent/test.sh
index f63a1186..0edb6280 100755
--- a/tests/convert-tests/006-large-hole-extent/test.sh
+++ b/tests/convert-tests/006-large-hole-extent/test.sh
@@ -11,6 +11,7 @@ source "$TOP/tests/common.convert"
setup_root_helper
prepare_test_dev 512M
check_prereq btrfs-convert
+check_global_prereq mke2fs
default_mke2fs="mke2fs -t ext4 -b 4096"
convert_test_preamble '' 'large hole extent test' 16k "$default_mke2fs"
diff --git a/tests/convert-tests/007-unsupported-block-sizes/test.sh b/tests/convert-tests/007-unsupported-block-sizes/test.sh
index af8ec357..f1b29726 100755
--- a/tests/convert-tests/007-unsupported-block-sizes/test.sh
+++ b/tests/convert-tests/007-unsupported-block-sizes/test.sh
@@ -7,6 +7,7 @@ source "$TOP/tests/common.convert"
setup_root_helper
prepare_test_dev 512M
check_prereq btrfs-convert
+check_global_prereq mke2fs
for bs in 1024 2048; do
default_mke2fs="mke2fs -t ext4 -b $bs"
diff --git a/tests/convert-tests/008-readonly-image/test.sh b/tests/convert-tests/008-readonly-image/test.sh
index 4d5e629f..8551fb9b 100755
--- a/tests/convert-tests/008-readonly-image/test.sh
+++ b/tests/convert-tests/008-readonly-image/test.sh
@@ -7,6 +7,7 @@ source "$TOP/tests/common.convert"
setup_root_helper
prepare_test_dev 512M
check_prereq btrfs-convert
+check_global_prereq mke2fs
default_mke2fs="mke2fs -t ext4 -b 4096"
convert_test_preamble '' 'readonly image test' 16k "$default_mke2fs"
@@ -16,11 +17,11 @@ convert_test_do_convert
run_check_mount_test_dev
# It's expected to fail
-$SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/ext2_save/image" bs=1M count=1 \
+$SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/ext2_saved/image" bs=1M count=1 \
&> /dev/null
if [ $? -ne 1 ]; then
- echo "after convert ext2_save/image is not read-only"
+ echo "after convert ext2_saved/image is not read-only"
exit 1
fi
run_check_umount_test_dev
-convert_test_post_rollback
+convert_test_post_rollback ext4
diff --git a/tests/convert-tests/009-common-inode-flags/test.sh b/tests/convert-tests/009-common-inode-flags/test.sh
index f42fb681..cd7b5111 100755
--- a/tests/convert-tests/009-common-inode-flags/test.sh
+++ b/tests/convert-tests/009-common-inode-flags/test.sh
@@ -7,6 +7,9 @@ source "$TOP/tests/common.convert"
setup_root_helper
prepare_test_dev 512M
check_prereq btrfs-convert
+check_global_prereq mke2fs
+check_global_prereq lsattr
+check_global_prereq chattr
fail=0
default_mke2fs="mke2fs -t ext4 -b 4096"
@@ -31,4 +34,4 @@ if [ $? -ne 0 ]; then
fi
run_check_umount_test_dev
-convert_test_post_rollback
+convert_test_post_rollback ext4
diff --git a/tests/convert-tests/010-reiserfs-basic/test.sh b/tests/convert-tests/010-reiserfs-basic/test.sh
new file mode 100755
index 00000000..261f8704
--- /dev/null
+++ b/tests/convert-tests/010-reiserfs-basic/test.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+source "$TOP/tests/common"
+source "$TOP/tests/common.convert"
+
+if ! check_kernel_support_reiserfs >/dev/null; then
+ _not_run "no reiserfs support"
+fi
+
+setup_root_helper
+prepare_test_dev 512M
+check_prereq btrfs-convert
+check_global_prereq mkreiserfs
+
+for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do
+ convert_test reiserfs "$feature" "reiserfs 4k nodesize" 4096 mkreiserfs -b 4096
+ convert_test reiserfs "$feature" "reiserfs 8k nodesize" 8192 mkreiserfs -b 4096
+ convert_test reiserfs "$feature" "reiserfs 16k nodesize" 16384 mkreiserfs -b 4096
+ convert_test reiserfs "$feature" "reiserfs 32k nodesize" 32768 mkreiserfs -b 4096
+ convert_test reiserfs "$feature" "reiserfs 64k nodesize" 65536 mkreiserfs -b 4096
+done
diff --git a/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh b/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh
new file mode 100755
index 00000000..c6c3119e
--- /dev/null
+++ b/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+# create a base image, convert to btrfs, remove all files, rollback the reiserfs image
+
+source "$TOP/tests/common"
+source "$TOP/tests/common.convert"
+
+if ! check_kernel_support_reiserfs >/dev/null; then
+ _not_run "no reiserfs support"
+fi
+
+setup_root_helper
+prepare_test_dev 512M
+check_prereq btrfs-convert
+check_global_prereq mkreiserfs
+
+# simple wrapper for a convert test
+# $1: btrfs features, argument to -O
+# $2: message
+# $3: nodesize value
+# $4 + rest: command to create the reiserfs image
+do_test() {
+ local features
+ local msg
+ local nodesize
+ local CHECKSUMTMP
+ local here
+
+ features="$1"
+ msg="$2"
+ nodesize="$3"
+ shift 3
+ convert_test_preamble "$features" "$msg" "$nodesize" "$@"
+ convert_test_prep_fs reiserfs "$@"
+ populate_fs
+ CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX)
+ convert_test_gen_checksums "$CHECKSUMTMP"
+
+ run_check_umount_test_dev
+
+ convert_test_do_convert "$features" "$nodesize"
+
+ run_check_mount_test_dev
+ convert_test_post_check_checksums "$CHECKSUMTMP"
+
+ here=$(pwd)
+ cd "$TEST_MNT" || _fail "cannot cd to TEST_MNT"
+ # reiserfs_saved/image must not be deleted
+ run_mayfail $SUDO_HELPER find "$TEST_MNT"/ -mindepth 1 -path '*reiserfs_saved' -prune -o -exec rm -vrf "{}" \;
+ cd "$here"
+ run_check "$TOP/btrfs" filesystem sync "$TEST_MNT"
+ run_check_umount_test_dev
+ convert_test_post_rollback reiserfs
+
+ run_check_mount_convert_dev reiserfs
+ convert_test_post_check_checksums "$CHECKSUMTMP"
+ run_check_umount_test_dev
+
+ # mount again and verify checksums
+ run_check_mount_convert_dev reiserfs
+ convert_test_post_check_checksums "$CHECKSUMTMP"
+ run_check_umount_test_dev
+
+ rm "$CHECKSUMTMP"
+}
+
+for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do
+ do_test "$feature" "reiserfs 4k nodesize" 4096 mkreiserfs -b 4096
+ do_test "$feature" "reiserfs 8k nodesize" 8192 mkreiserfs -b 4096
+ do_test "$feature" "reiserfs 16k nodesize" 16384 mkreiserfs -b 4096
+ do_test "$feature" "reiserfs 32k nodesize" 32768 mkreiserfs -b 4096
+ do_test "$feature" "reiserfs 64k nodesize" 65536 mkreiserfs -b 4096
+done
diff --git a/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh b/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh
new file mode 100755
index 00000000..7a8d4972
--- /dev/null
+++ b/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+# Create a base image with large hole extent, then convert to btrfs,
+# check the converted image.
+# Check if btrfs-convert can handle such large hole.
+# Fast pinpoint regression test. No options combination nor checksum
+# verification
+
+source "$TOP/tests/common"
+source "$TOP/tests/common.convert"
+
+if ! check_kernel_support_reiserfs >/dev/null; then
+ _not_run "no reiserfs support"
+fi
+
+setup_root_helper
+prepare_test_dev 512M
+check_prereq btrfs-convert
+check_global_prereq mkreiserfs
+
+default_mkfs="mkreiserfs -b 4096"
+convert_test_preamble '' 'large hole extent test' 16k "$default_mkfs"
+convert_test_prep_fs reiserfs $default_mkfs
+
+run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT/file" bs=1M \
+ count=1 seek=1024 > /dev/null 2>&1
+
+run_check_umount_test_dev
+convert_test_do_convert
diff --git a/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh b/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh
new file mode 100755
index 00000000..e242a3b0
--- /dev/null
+++ b/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+# Check if btrfs-convert can copy common inode flags like SYNC/IMMUTABLE
+
+source "$TOP/tests/common"
+source "$TOP/tests/common.convert"
+
+if ! check_kernel_support_reiserfs >/dev/null; then
+ _not_run "no reiserfs support"
+fi
+
+setup_root_helper
+prepare_test_dev 512M
+check_prereq btrfs-convert
+check_global_prereq mkreiserfs
+check_global_prereq chattr
+check_global_prereq lsattr
+
+fail=0
+default_mkfs="mkreiserfs -b 4096"
+convert_test_preamble '' 'common inode flags test' 16k "$default_mkfs"
+convert_test_prep_fs reiserfs $default_mkfs
+
+# create file with specific flags
+run_check $SUDO_HELPER touch "$TEST_MNT/flag_test"
+run_check $SUDO_HELPER chattr +aAdSi "$TEST_MNT/flag_test"
+run_check lsattr "$TEST_MNT/flag_test"
+
+run_check_umount_test_dev
+convert_test_do_convert
+run_check_mount_test_dev
+
+# Log the status
+run_check lsattr "$TEST_MNT/flag_test"
+# Above flags should be copied to btrfs flags, and lsattr should get them
+run_check_stdout lsattr "$TEST_MNT/flag_test" | cut -f1 -d\ | grep "[aAdiS]" -q
+if [ $? -ne 0 ]; then
+ rm tmp_output
+ _fail "no common inode flags are copied after convert"
+fi
+
+run_check_umount_test_dev
+convert_test_post_rollback reiserfs
diff --git a/tests/convert-tests/014-reiserfs-tail-handling/test.sh b/tests/convert-tests/014-reiserfs-tail-handling/test.sh
new file mode 100755
index 00000000..f6131d96
--- /dev/null
+++ b/tests/convert-tests/014-reiserfs-tail-handling/test.sh
@@ -0,0 +1,79 @@
+#!/bin/bash
+# Check the various combinations of real blocks, holes, and tails
+# Since it's possible to have a valid extent layout that check will
+# happily accept AND have garbage in the output, compare the results
+# as well.
+# We use separate inputs for tails and real blocks so we can determine
+# if there was a failure in copying either.
+
+source "$TOP/tests/common"
+source "$TOP/tests/common.convert"
+
+if ! check_kernel_support_reiserfs >/dev/null; then
+ _not_run "no reiserfs support"
+fi
+
+setup_root_helper
+prepare_test_dev 512M
+check_prereq btrfs-convert
+check_global_prereq md5sum
+check_global_prereq mkreiserfs
+check_global_prereq perl
+
+perl -e "print 'a'x8192;" > input
+perl -e "print 'b'x8192;" > input2
+
+default_mkfs="mkreiserfs -b 4096"
+convert_test_preamble '' 'tail conversion test' 16k "$default_mkfs"
+convert_test_prep_fs reiserfs $default_mkfs
+
+# Hole alone
+run_check $SUDO_HELPER truncate -s 81920 "$TEST_MNT/hole"
+
+# Tail alone
+run_check $SUDO_HELPER dd if=input of="$TEST_MNT/1k" bs=1k count=1 \
+ > /dev/null 2>&1
+
+# Single indirect block
+run_check $SUDO_HELPER dd if=input of="$TEST_MNT/4k" bs=1k count=4 \
+ > /dev/null 2>&1
+
+# Indirect block + tail
+run_check $SUDO_HELPER dd if=input of="$TEST_MNT/5k" bs=1k count=4 \
+ > /dev/null 2>&1
+run_check $SUDO_HELPER dd if=input2 of="$TEST_MNT/5k" bs=1k count=1 \
+ seek=4 > /dev/null 2>&1
+
+# Hole followed by tail
+run_check $SUDO_HELPER dd if=input of="$TEST_MNT/hole-1k" bs=1k count=1 \
+ seek=4 > /dev/null 2>&1
+
+# Indirect block followed by hole
+run_check $SUDO_HELPER dd if=input of="$TEST_MNT/4k-hole" bs=1k count=4 \
+ > /dev/null 2>&1
+run_check $SUDO_HELPER truncate -s 81920 "$TEST_MNT/4k-hole"
+
+# Indirect block followed by hole followed by tail
+run_check $SUDO_HELPER dd if=input of="$TEST_MNT/4k-hole-1k" bs=1k count=4 \
+ > /dev/null 2>&1
+run_check $SUDO_HELPER truncate -s 8192 "$TEST_MNT/4k-hole-1k"
+run_check $SUDO_HELPER dd if=input2 of="$TEST_MNT/4k-hole-1k" bs=1k count=1 \
+ seek=8 > /dev/null 2>&1
+
+rm -f input input2
+
+declare -A SUMS
+for file in "$TEST_MNT"/*; do
+ SUM=$(md5sum "$file")
+ SUMS["$file"]=$SUM
+done
+
+run_check_umount_test_dev
+convert_test_do_convert
+
+run_check_mount_test_dev
+for file in "${!SUMS[@]}"; do
+ SUM=$(md5sum "$file")
+ run_check test "$SUM" = "${SUMS[$file]}"
+done
+run_check_umount_test_dev
diff --git a/tests/fsck-tests/026-bad-dir-item-name/default_case.img.xz b/tests/fsck-tests/026-bad-dir-item-name/default_case.img.xz
new file mode 100644
index 00000000..27e8553f
--- /dev/null
+++ b/tests/fsck-tests/026-bad-dir-item-name/default_case.img.xz
Binary files differ
diff --git a/tests/fsck-tests/026-bad-dir-item-name/test.sh b/tests/fsck-tests/026-bad-dir-item-name/test.sh
new file mode 100755
index 00000000..a1077a8d
--- /dev/null
+++ b/tests/fsck-tests/026-bad-dir-item-name/test.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+#
+# confirm whether check detects name and hash mismatch in dir_item
+
+source "$TOP/tests/common"
+
+check_prereq btrfs
+
+image=$(extract_image "./default_case.img.xz")
+
+run_mustfail "dir_item hash mismatch not found" "$TOP/btrfs" check "$image"
+
+rm -f "$image"
diff --git a/tests/fuzz-tests/images/bko-155551-unaligned-tree-block.raw.txt b/tests/fuzz-tests/images/bko-155551-unaligned-tree-block.raw.txt
new file mode 100644
index 00000000..498896c1
--- /dev/null
+++ b/tests/fuzz-tests/images/bko-155551-unaligned-tree-block.raw.txt
@@ -0,0 +1,49 @@
+URL: https://bugzilla.kernel.org/show_bug.cgi?id=155551
+Lukas Lueg 2016-08-29 20:44:04 UTC
+
+More news from the fuzzer. The attached image causes btrfsck to enter what
+seems to be an endless loop; using btrfs-progs v4.7-42-g56e9586.
+
+Couldn't map the block 18446744073709551607
+No mapping for 18446744073709551607-4087
+Couldn't map the block 18446744073709551607
+bytenr mismatch, want=18446744073709551607, have=0
+checking extents
+parent transid verify failed on 4194304 wanted 169 found 4
+Ignoring transid failure
+parent transid verify failed on 4194304 wanted 169 found 4
+Ignoring transid failure
+parent transid verify failed on 4194304 wanted 169 found 4
+Ignoring transid failure
+parent transid verify failed on 4194304 wanted 169 found 4
+Ignoring transid failure
+parent transid verify failed on 4194304 wanted 169 found 4
+Ignoring transid failure
+parent transid verify failed on 4194304 wanted 169 found 4
+Ignoring transid failure
+parent transid verify failed on 4194304 wanted 169 found 4
+Ignoring transid failure
+parent transid verify failed on 4194304 wanted 169 found 4
+Ignoring transid failure
+parent transid verify failed on 4194304 wanted 169 found 4
+Ignoring transid failure
+Couldn't map the block 419430592
+No mapping for 419430592-419434688
+Couldn't map the block 419430592
+bytenr mismatch, want=419430592, have=0
+Couldn't map the block 36283884701696
+No mapping for 36283884701696-36283884705792
+Couldn't map the block 36283884701696
+bytenr mismatch, want=36283884701696, have=0
+Couldn't map the block 18446744073709551607
+No mapping for 18446744073709551607-4087
+Couldn't map the block 18446744073709551607
+bytenr mismatch, want=18446744073709551607, have=0
+Couldn't map the block 18446744073709551607
+No mapping for 18446744073709551607-4087
+Couldn't map the block 18446744073709551607
+bytenr mismatch, want=18446744073709551607, have=0
+Couldn't map the block 18446744073709551607
+No mapping for 18446744073709551607-4087
+Couldn't map the block 18446744073709551607
+bytenr mismatch, want=18446744073709551607, have=0
diff --git a/tests/fuzz-tests/images/bko-155551-unaligned-tree-block.raw.xz b/tests/fuzz-tests/images/bko-155551-unaligned-tree-block.raw.xz
new file mode 100644
index 00000000..f60271e2
--- /dev/null
+++ b/tests/fuzz-tests/images/bko-155551-unaligned-tree-block.raw.xz
Binary files differ
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
new file mode 100644
index 00000000..67aaf17f
--- /dev/null
+++ b/tests/misc-tests/025-zstd-compression/compress.raw.xz
Binary files differ
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
diff --git a/tests/mkfs-tests/001-basic-profiles/test.sh b/tests/mkfs-tests/001-basic-profiles/test.sh
index 0dc9a2bd..854ee007 100755
--- a/tests/mkfs-tests/001-basic-profiles/test.sh
+++ b/tests/mkfs-tests/001-basic-profiles/test.sh
@@ -7,34 +7,8 @@ source $TOP/tests/common
check_prereq mkfs.btrfs
check_prereq btrfs
-ndevs=4
-declare -a devs
-dev1=
-
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_check $SUDO_HELPER losetup -d $dev
- done
- for i in `seq $ndevs`; do
- truncate -s0 img$i
- done
- run_check $SUDO_HELPER losetup --all
-}
-
test_get_info()
{
run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $dev1
@@ -58,12 +32,13 @@ test_mkfs_single()
}
test_mkfs_multi()
{
- test_do_mkfs $@ ${devs[@]}
+ test_do_mkfs $@ ${loopdevs[@]}
test_get_info
}
-prepare_devices
-dev1=${devs[1]}
+setup_loopdevs 4
+prepare_loopdevs
+dev1=${loopdevs[1]}
test_mkfs_single
test_mkfs_single -d single -m single
@@ -89,4 +64,4 @@ test_mkfs_multi -d raid6 -m raid6 --mixed
test_mkfs_multi -d dup -m dup
test_mkfs_multi -d dup -m dup --mixed
-cleanup_devices
+cleanup_loopdevs
diff --git a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh
index 63fb1785..5bdf50e0 100755
--- a/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh
+++ b/tests/mkfs-tests/005-long-device-name-for-ssd/test.sh
@@ -38,3 +38,4 @@ run_check $SUDO_HELPER $TOP/btrfs inspect-internal dump-super $dmdev
run_check $SUDO_HELPER dmsetup remove $dmname
run_mayfail $SUDO_HELPER losetup -d $loopdev
run_check truncate -s0 img
+rm img
diff --git a/tests/mkfs-tests/006-partitioned-loopdev/test.sh b/tests/mkfs-tests/006-partitioned-loopdev/test.sh
index 12f37842..0c77e5cd 100755
--- a/tests/mkfs-tests/006-partitioned-loopdev/test.sh
+++ b/tests/mkfs-tests/006-partitioned-loopdev/test.sh
@@ -29,3 +29,4 @@ done
# cleanup
run_check $SUDO_HELPER losetup -d $loopdev
run_check truncate -s0 img
+rm img
diff --git a/tests/mkfs-tests/009-special-files-for-rootdir/test.sh b/tests/mkfs-tests/009-special-files-for-rootdir/test.sh
new file mode 100755
index 00000000..d327a0d9
--- /dev/null
+++ b/tests/mkfs-tests/009-special-files-for-rootdir/test.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+# Check if --rootdir can handle special files (socket/fifo/char/block) correctly
+#
+# --rootdir had a problem of filling dir items/indexes with wrong type
+# and caused btrfs check to report such error
+#
+# Note: sock type is skipped in this test
+
+source "$TOP/tests/common"
+
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+setup_root_helper # For mknod
+prepare_test_dev
+
+# mknod can create FIFO/CHAR/BLOCK file but not SOCK.
+# No neat tool to create socket file, unless using python or similar.
+# So no SOCK is tested here
+check_global_prereq mknod
+check_global_prereq dd
+
+tmp=$(mktemp -d --tmpdir btrfs-progs-mkfs.rootdirXXXXXXX)
+
+run_check mkdir "$tmp/dir"
+run_check mkdir -p "$tmp/dir/in/dir"
+run_check mknod "$tmp/fifo" p
+run_check $SUDO_HELPER mknod "$tmp/char" c 1 1
+run_check $SUDO_HELPER mknod "$tmp/block" b 1 1
+run_check dd if=/dev/zero bs=1M count=1 of="$tmp/regular"
+
+run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -r "$tmp" "$TEST_DEV"
+
+rm -rf -- "$tmp"
+
+run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV"
diff --git a/tests/scan-results.sh b/tests/scan-results.sh
index f3ebcbc4..f935b1cd 100755
--- a/tests/scan-results.sh
+++ b/tests/scan-results.sh
@@ -11,7 +11,9 @@ for i in *.txt; do
*Assertion*failed*) echo "ASSERTION FAILED: $last" ;;
*runtime\ error*) echo "RUNTIME ERROR (sanitizer): $last" ;;
*AddressSanitizer*heap-use-after-free*) echo "RUNTIME ERROR (use after free): $last" ;;
+ *LeakSanitizer:*leak*) echo "SANITIZER REPORT: memory leak: $last" ;;
*Warning:\ assertion*failed*) echo "ASSERTION WARNING: $last" ;;
+ *command\ not\ found*) echo "COMMAND NOT FOUND: $last" ;;
*) : ;;
esac
done < "$i"
diff --git a/tests/sha-private.h b/tests/sha-private.h
index 6e9c4520..d94d4374 100644
--- a/tests/sha-private.h
+++ b/tests/sha-private.h
@@ -1,5 +1,9 @@
/************************ sha-private.h ************************/
/***************** See RFC 6234 for details. *******************/
+/* Copyright (c) 2011 IETF Trust and the persons identified as */
+/* authors of the code. All rights reserved. */
+/* See sha.h for terms of use and redistribution. */
+
#ifndef _SHA_PRIVATE__H
#define _SHA_PRIVATE__H
/*
diff --git a/tests/sha224-256.c b/tests/sha224-256.c
index 2d963e65..82124a03 100644
--- a/tests/sha224-256.c
+++ b/tests/sha224-256.c
@@ -1,23 +1,3 @@
-/*
-RFC 6234 SHAs, HMAC-SHAs, and HKDF May 2011
-
-
-Copyright Notice
-
- Copyright (c) 2011 IETF Trust and the persons identified as the
- document authors. All rights reserved.
-
- This document is subject to BCP 78 and the IETF Trust's Legal
- Provisions Relating to IETF Documents
- (http://trustee.ietf.org/license-info) in effect on the date of
- publication of this document. Please review these documents
- carefully, as they describe your rights and restrictions with respect
- to this document. Code Components extracted from this document must
- include Simplified BSD License text as described in Section 4.e of
- the Trust Legal Provisions and are provided without warranty as
- described in the Simplified BSD License.
-*/
-
/************************* sha224-256.c ************************/
/***************** See RFC 6234 for details. *******************/
/* Copyright (c) 2011 IETF Trust and the persons identified as */