summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/README.md47
-rwxr-xr-xtests/cli-tests.sh3
-rwxr-xr-xtests/cli-tests/003-fi-resize-args/test.sh46
-rw-r--r--tests/common10
-rw-r--r--tests/common.convert182
-rwxr-xr-xtests/convert-tests.sh177
-rwxr-xr-xtests/convert-tests/001-ext2-basic/test.sh16
-rwxr-xr-xtests/convert-tests/002-ext3-basic/test.sh16
-rwxr-xr-xtests/convert-tests/003-ext4-basic/test.sh16
-rw-r--r--tests/convert-tests/004-ext2-backup-superblock-ranges/drdhdhdrd.e2image.raw.xzbin0 -> 84564 bytes
-rw-r--r--tests/convert-tests/004-ext2-backup-superblock-ranges/drdhdhrh.e2image.raw.xzbin0 -> 84568 bytes
-rw-r--r--tests/convert-tests/004-ext2-backup-superblock-ranges/hrhdhdrd.e2image.raw.xzbin0 -> 84556 bytes
-rw-r--r--tests/convert-tests/004-ext2-backup-superblock-ranges/hrhdhrh.e2image.raw.xzbin0 -> 84568 bytes
-rwxr-xr-xtests/convert-tests/004-ext2-backup-superblock-ranges/test.sh43
-rwxr-xr-xtests/convert-tests/005-delete-all-rollback/test.sh61
-rwxr-xr-xtests/fsck-tests.sh10
-rw-r--r--tests/fsck-tests/020-extent-ref-cases/keyed_block_ref.imgbin0 -> 10240 bytes
-rw-r--r--tests/fsck-tests/020-extent-ref-cases/keyed_data_ref.imgbin0 -> 4096 bytes
-rw-r--r--tests/fsck-tests/020-extent-ref-cases/no_inline_ref.imgbin0 -> 4096 bytes
-rw-r--r--tests/fsck-tests/020-extent-ref-cases/no_skinny_ref.imgbin0 -> 3072 bytes
-rw-r--r--tests/fsck-tests/020-extent-ref-cases/shared_block_ref.imgbin0 -> 23552 bytes
-rw-r--r--tests/fsck-tests/020-extent-ref-cases/shared_data_ref.imgbin0 -> 5120 bytes
-rwxr-xr-xtests/fsck-tests/020-extent-ref-cases/test.sh23
-rwxr-xr-xtests/fuzz-tests.sh3
-rw-r--r--tests/fuzz-tests/images/superblock-stripsize-bogus.raw.txt32
-rw-r--r--tests/fuzz-tests/images/superblock-stripsize-bogus.raw.xzbin0 -> 41512 bytes
-rw-r--r--tests/fuzz-tests/images/superblock-total-bytes-0.raw.txt50
-rw-r--r--tests/fuzz-tests/images/superblock-total-bytes-0.raw.xzbin0 -> 41424 bytes
-rw-r--r--tests/fuzz-tests/images/sys-chunk-stripe-len-bogus.raw.txt54
-rw-r--r--tests/fuzz-tests/images/sys-chunk-stripe-len-bogus.raw.xzbin0 -> 41440 bytes
-rw-r--r--tests/fuzz-tests/images/sys-chunk-type-bogus.raw.txt55
-rw-r--r--tests/fuzz-tests/images/sys-chunk-type-bogus.raw.xzbin0 -> 41524 bytes
-rwxr-xr-xtests/misc-tests.sh6
-rwxr-xr-xtests/misc-tests/007-subvolume-sync/test.sh4
-rwxr-xr-xtests/misc-tests/009-subvolume-sync-must-wait/test.sh2
-rwxr-xr-xtests/misc-tests/013-subvolume-sync-crash/test.sh2
-rwxr-xr-xtests/mkfs-tests.sh6
-rwxr-xr-xtests/mkfs-tests/008-secorsize-nodesize-combination/test.sh2
-rwxr-xr-xtests/test-console.sh23
39 files changed, 704 insertions, 185 deletions
diff --git a/tests/README.md b/tests/README.md
index be3bda82..6bb3de49 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -1,5 +1,14 @@
# Btrfs-progs tests
+A testsuite covering functionality of btrfs-progs, ie. the checker, image, mkfs
+and similar tools. There are no special requirements on kernel features, the
+tests build on top of the core functionality like snapshots and device
+management. In some cases optional features are turned on by mkfs and the
+filesystem image could be mounted, such tests might fail if there's lack of
+support.
+
+## Quick start
+
Run the tests from the top directory:
```shell
@@ -20,7 +29,7 @@ category, eg. `fsck-tests-results.txt`.
## Selective testing
-The test are prefixed by a number for ordering and uniquenes. To run a
+The test are prefixed by a number for ordering and uniqueness. To run a
particular test use:
```shell
@@ -54,14 +63,22 @@ will run the first test in fsck-tests subdirectory.
* tests that are supposed to run various utilities on the images and not
crash
+*tests/cli-tests/:*
+
+ * tests for command line interface, option coverage, weird option combinations that should not work
+ * not necessary to do any functional testing, could be rather lightweight
+ * functional tests should go to to other test dirs
+ * the driver script will only execute `./test.sh` in the test directory
+
*tests/misc-tests/:*
* 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:*
- * script with helpers
+ * script with shell helpers, separated by functionality
*tests/test.img:*
@@ -92,7 +109,8 @@ the root helper).
### Verbosity
Setting the variable `TEST_LOG=tty` will print all commands executed by some of
-the wrappers (`run_check` etc), other commands are silent.
+the wrappers (`run_check` etc), other commands are not printed to the terminal
+(but the full output is in the log).
### Permissions
@@ -111,26 +129,33 @@ least the mounts and loop devices need to be cleaned before the next run.
This is partially done by the script `clean-tests.sh`, you may want to check
the loop devices as they are managed on a per-test basis.
+### Prototyping tests, quick tests
+
+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.
+
## New test
1. Pick the category for the new test or fallback to `misc-tests` if not sure. For
an easy start copy an existing `test.sh` script from some test that might be
-close to the purpose of your new test.
+close to the purpose of your new test. The environment setup includes the
+common scripts and/or prepares the test devices. Other scripts contain examples
+how to do mkfs, mount, unmount, check, etc.
-* Use the highest unused number in the sequence, write a short descriptive title
-and join by dashes `-`.
+2. Use the highest unused number in the sequence, write a short descriptive title
+and join by dashes `-`. This will become the directory name, eg. `012-subvolume-sync-must-wait`.
-* Write a short description of the bug and how it's teste to the comment at the
-begining of `test.sh`.
+3. Write a short description of the bug and how it's tested to the comment at the
+begining of `test.sh`. You don't need to add the file to git yet.
-* Write the test commands, comment anything that's not obvious.
+4. Write the test commands, comment anything that's not obvious.
-* 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/
```
-* The commit changelog should reference a commit that either introduced or
+6. The commit changelog should reference a commit that either introduced or
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`
diff --git a/tests/cli-tests.sh b/tests/cli-tests.sh
index e65e7f50..72f7865a 100755
--- a/tests/cli-tests.sh
+++ b/tests/cli-tests.sh
@@ -2,8 +2,6 @@
#
# command line interface coverage tests
-unset TOP
-unset LANG
LANG=C
SCRIPT_DIR=$(dirname $(readlink -f $0))
TOP=$(readlink -f $SCRIPT_DIR/../)
@@ -17,6 +15,7 @@ export TOP
export RESULTS
export LANG
export IMAGE
+export TEST_DEV
rm -f $RESULTS
diff --git a/tests/cli-tests/003-fi-resize-args/test.sh b/tests/cli-tests/003-fi-resize-args/test.sh
new file mode 100755
index 00000000..2f136fa2
--- /dev/null
+++ b/tests/cli-tests/003-fi-resize-args/test.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+#
+# test parsing of various resize arguments
+
+source $TOP/tests/common
+
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+setup_root_helper
+prepare_test_dev 2g
+
+run_check $TOP/mkfs.btrfs -f $IMAGE
+run_check_mount_test_dev
+
+# missing the one of the required arguments
+for sep in '' '--'; do
+ run_check_stdout $TOP/btrfs filesystem resize $sep |
+ grep -q "btrfs filesystem resize: too few arguments"
+ run_check_stdout $TOP/btrfs filesystem resize $sep $TEST_MNT |
+ grep -q "btrfs filesystem resize: too few arguments"
+ run_check_stdout $TOP/btrfs filesystem resize $sep -128M |
+ grep -q "btrfs filesystem resize: too few arguments"
+ run_check_stdout $TOP/btrfs filesystem resize $sep +128M |
+ grep -q "btrfs filesystem resize: too few arguments"
+ run_check_stdout $TOP/btrfs filesystem resize $sep 512M |
+ grep -q "btrfs filesystem resize: too few arguments"
+ run_check_stdout $TOP/btrfs filesystem resize $sep 1:-128M |
+ grep -q "btrfs filesystem resize: too few arguments"
+ run_check_stdout $TOP/btrfs filesystem resize $sep 1:512M |
+ grep -q "btrfs filesystem resize: too few arguments"
+ run_check_stdout $TOP/btrfs filesystem resize $sep 1:+128M |
+ grep -q "btrfs filesystem resize: too few arguments"
+done
+
+# valid resize
+for sep in '' '--'; do
+ run_check $SUDO_HELPER $TOP/btrfs filesystem resize $sep -128M $TEST_MNT
+ run_check $SUDO_HELPER $TOP/btrfs filesystem resize $sep +128M $TEST_MNT
+ run_check $SUDO_HELPER $TOP/btrfs filesystem resize $sep 512M $TEST_MNT
+ run_check $SUDO_HELPER $TOP/btrfs filesystem resize $sep 1:-128M $TEST_MNT
+ run_check $SUDO_HELPER $TOP/btrfs filesystem resize $sep 1:512M $TEST_MNT
+ run_check $SUDO_HELPER $TOP/btrfs filesystem resize $sep 1:+128M $TEST_MNT
+done
+
+run_check_umount_test_dev
diff --git a/tests/common b/tests/common
index 91682eff..c50b661f 100644
--- a/tests/common
+++ b/tests/common
@@ -90,7 +90,15 @@ run_mustfail()
check_prereq()
{
if ! [ -f $TOP/$1 ]; then
- _fail "Failed prerequisities: $1";
+ _fail "Failed prerequisites: $1";
+ fi
+}
+
+check_global_prereq()
+{
+ which $1 &> /dev/null
+ if [ $? -ne 0 ]; then
+ _fail "Failed system wide prerequisities: $1";
fi
}
diff --git a/tests/common.convert b/tests/common.convert
new file mode 100644
index 00000000..4e3d49c9
--- /dev/null
+++ b/tests/common.convert
@@ -0,0 +1,182 @@
+#!/bin/bash
+# helpers for btrfs-convert tests
+
+# how many files to create.
+DATASET_SIZE=50
+
+generate_dataset() {
+
+ dataset_type="$1"
+ dirpath=$TEST_MNT/$dataset_type
+ run_check $SUDO_HELPER mkdir -p $dirpath
+
+ case $dataset_type in
+ small)
+ for num in $(seq 1 $DATASET_SIZE); do
+ run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \
+ count=1 >/dev/null 2>&1
+ done
+ ;;
+
+ hardlink)
+ for num in $(seq 1 $DATASET_SIZE); do
+ run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num
+ run_check $SUDO_HELPER ln $dirpath/$dataset_type.$num $dirpath/hlink.$num
+ done
+ ;;
+
+ symlink)
+ for num in $(seq 1 $DATASET_SIZE); do
+ run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num
+ run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/slink.$num
+ done
+ ;;
+
+ brokenlink)
+ for num in $(seq 1 $DATASET_SIZE); do
+ run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/blink.$num
+ done
+ ;;
+
+ perm)
+ for modes in 777 775 755 750 700 666 664 644 640 600 444 440 400 000 \
+ 1777 1775 1755 1750 1700 1666 1664 1644 1640 1600 1444 1440 1400 1000 \
+ 2777 2775 2755 2750 2700 2666 2664 2644 2640 2600 2444 2440 2400 2000 \
+ 4777 4775 4755 4750 4700 4666 4664 4644 4640 4600 4444 4440 4400 4000; do
+ if [[ "$modes" == *9* ]] || [[ "$modes" == *8* ]]
+ then
+ continue;
+ else
+ run_check $SUDO_HELPER touch $dirpath/$dataset_type.$modes
+ run_check $SUDO_HELPER chmod $modes $dirpath/$dataset_type.$modes
+ fi
+ done
+ ;;
+
+ sparse)
+ for num in $(seq 1 $DATASET_SIZE); do
+ run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \
+ count=1 >/dev/null 2>&1
+ run_check $SUDO_HELPER truncate -s 500K $dirpath/$dataset_type.$num
+ run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \
+ oflag=append conv=notrunc count=1 >/dev/null 2>&1
+ run_check $SUDO_HELPER truncate -s 800K $dirpath/$dataset_type.$num
+ done
+ ;;
+
+ acls)
+ for num in $(seq 1 $DATASET_SIZE); do
+ run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num
+ run_check $SUDO_HELPER setfacl -m "u:root:x" $dirpath/$dataset_type.$num
+ run_check $SUDO_HELPER setfattr -n user.foo -v bar$num $dirpath/$dataset_type.$num
+ done
+ ;;
+ esac
+}
+
+populate_fs() {
+
+ for dataset_type in 'small' 'hardlink' 'symlink' 'brokenlink' 'perm' 'sparse' 'acls'; do
+ generate_dataset "$dataset_type"
+ done
+}
+
+# verbose message before the test, same arguments as convert_test
+convert_test_preamble() {
+ local features
+ local msg
+
+ features="$1"
+ msg="$2"
+ shift 3
+ echo " [TEST/conv] $msg, btrfs" "${features:-defaults}"
+ echo "creating ext image with: $@" >> $RESULTS
+}
+
+# prepare TEST_DEV before conversion, create filesystem and mount it, image
+# size is 512MB
+# $@: free form, command to create the filesystem, with appended -F
+convert_test_prep_fs() {
+ # TEST_DEV not removed as the file might have special permissions, eg.
+ # when test image is on NFS and would not be writable for root
+ 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
+
+ # create a file to check btrfs-convert can convert regular file correct
+ run_check_mount_test_dev
+
+ # create a file inside the fs before convert, to make sure there is
+ # data covering btrfs backup superblock range (64M)
+ run_check $SUDO_HELPER dd if=/dev/zero bs=1M count=64 \
+ of=$TEST_MNT/convert_space_holder
+}
+
+# generate md5 checksums of files on $TEST_MNT
+# $1: path where the checksums will be stored
+convert_test_gen_checksums() {
+ local CHECKSUMTMP
+ CHECKSUMTMP="$1"
+
+ run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \
+ count=1 >/dev/null 2>&1
+ run_check_stdout $SUDO_HELPER find $TEST_MNT -type f ! -name 'image' -exec md5sum {} \+ > "$CHECKSUMTMP"
+}
+
+# do conversion with given features and nodesize, fsck afterwards
+# $1: features, argument of -O, can be empty
+# $2: nodesize, argument of -N, can be empty
+convert_test_do_convert() {
+ run_check $TOP/btrfs-convert ${1:+-O "$1"} ${2:+-N "$2"} $TEST_DEV
+ run_check $TOP/btrfs check $TEST_DEV
+ run_check $TOP/btrfs-show-super -Ffa $TEST_DEV
+}
+
+# post conversion checks, verify md5sums
+# $1: file with checksums
+convert_test_post_check() {
+ local CHECKSUMTMP
+ CHECKSUMTMP="$1"
+
+ run_check_mount_test_dev
+ run_check_stdout $SUDO_HELPER md5sum -c "$CHECKSUMTMP" |
+ grep -q 'FAILED' && _fail "file validation failed"
+ run_check_umount_test_dev
+}
+
+# do rollback and fsck
+convert_test_post_rollback() {
+ run_check $TOP/btrfs-convert --rollback $TEST_DEV
+ run_check fsck -n -t ext2,ext3,ext4 $TEST_DEV
+}
+
+# simple wrapper for a convert test
+# $1: btrfs features, argument to -O
+# $2: description of the test "ext2 8k nodesize"
+# $3: nodesize value
+# $4 + rest: command to create the ext2 image
+convert_test() {
+ local features
+ local nodesize
+ local msg
+ local CHECKSUMTMP
+
+ features="$1"
+ msg="$2"
+ nodesize="$3"
+ shift 3
+ convert_test_preamble "$features" "$msg" "$nodesize" "$@"
+ convert_test_prep_fs "$@"
+ 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"
+ convert_test_post_check "$CHECKSUMTMP"
+ rm $CHECKSUMTMP
+
+ convert_test_post_rollback
+}
diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh
index 06d8419e..0e025f99 100755
--- a/tests/convert-tests.sh
+++ b/tests/convert-tests.sh
@@ -2,165 +2,48 @@
#
# convert ext2/3/4 images to btrfs images, and make sure the results are
# clean.
-#
-unset TOP
-unset LANG
LANG=C
SCRIPT_DIR=$(dirname $(readlink -f $0))
TOP=$(readlink -f $SCRIPT_DIR/../)
+TEST_DEV=${TEST_DEV:-}
RESULTS="$TOP/tests/convert-tests-results.txt"
-# how many files to create.
-DATASET_SIZE=50
+IMAGE="$TOP/tests/test.img"
source $TOP/tests/common
+source $TOP/tests/common.convert
-rm -f $RESULTS
-
-setup_root_helper
-prepare_test_dev 512M
-
-CHECKSUMTMP=$(mktemp --tmpdir btrfs-progs-convert.XXXXXXXXXX)
-
-generate_dataset() {
-
- dataset_type="$1"
- dirpath=$TEST_MNT/$dataset_type
- run_check $SUDO_HELPER mkdir -p $dirpath
-
- case $dataset_type in
- small)
- for num in $(seq 1 $DATASET_SIZE); do
- run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \
- count=1 >/dev/null 2>&1
- done
- ;;
-
- hardlink)
- for num in $(seq 1 $DATASET_SIZE); do
- run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num
- run_check $SUDO_HELPER ln $dirpath/$dataset_type.$num $dirpath/hlink.$num
- done
- ;;
-
- symlink)
- for num in $(seq 1 $DATASET_SIZE); do
- run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num
- run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/slink.$num
- done
- ;;
-
- brokenlink)
- for num in $(seq 1 $DATASET_SIZE); do
- run_check $SUDO_HELPER ln -s $dirpath/$dataset_type.$num $dirpath/blink.$num
- done
- ;;
-
- perm)
- for modes in 777 775 755 750 700 666 664 644 640 600 444 440 400 000 \
- 1777 1775 1755 1750 1700 1666 1664 1644 1640 1600 1444 1440 1400 1000 \
- 2777 2775 2755 2750 2700 2666 2664 2644 2640 2600 2444 2440 2400 2000 \
- 4777 4775 4755 4750 4700 4666 4664 4644 4640 4600 4444 4440 4400 4000; do
- if [[ "$modes" == *9* ]] || [[ "$modes" == *8* ]]
- then
- continue;
- else
- run_check $SUDO_HELPER touch $dirpath/$dataset_type.$modes
- run_check $SUDO_HELPER chmod $modes $dirpath/$dataset_type.$modes
- fi
- done
- ;;
-
- sparse)
- for num in $(seq 1 $DATASET_SIZE); do
- run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \
- count=1 >/dev/null 2>&1
- run_check $SUDO_HELPER truncate -s 500K $dirpath/$dataset_type.$num
- run_check $SUDO_HELPER dd if=/dev/urandom of=$dirpath/$dataset_type.$num bs=10K \
- oflag=append conv=notrunc count=1 >/dev/null 2>&1
- run_check $SUDO_HELPER truncate -s 800K $dirpath/$dataset_type.$num
- done
- ;;
+export TOP
+export RESULTS
+export LANG
+export IMAGE
+export TEST_DEV
- acls)
- for num in $(seq 1 $DATASET_SIZE); do
- run_check $SUDO_HELPER touch $dirpath/$dataset_type.$num
- run_check $SUDO_HELPER setfacl -m "u:root:x" $dirpath/$dataset_type.$num
- run_check $SUDO_HELPER setfattr -n user.foo -v bar$num $dirpath/$dataset_type.$num
- done
- ;;
- esac
-}
-
-populate_fs() {
-
- for dataset_type in 'small' 'hardlink' 'symlink' 'brokenlink' 'perm' 'sparse' 'acls'; do
- generate_dataset "$dataset_type"
- done
-}
-
-convert_test() {
- local features
- local nodesize
-
- features="$1"
- shift
+rm -f $RESULTS
- if [ -z "$features" ]; then
- echo " [TEST/conv] $1, btrfs defaults"
+run_one_test() {
+ local testdir
+ local testname
+
+ testdir="$1"
+ testname=$(basename "$testdir")
+ echo " [TEST/conv] $testname"
+ cd "$testdir"
+ echo "=== Entering $testname" >> $RESULTS
+ if [ -x test.sh ]; then
+ # Only support custom test scripts
+ ./test.sh
+ if [ $? -ne 0 ]; then
+ _fail "test failed for case $testname"
+ fi
else
- echo " [TEST/conv] $1, btrfs $features"
+ _fail "custom test script not found"
fi
- nodesize=$2
- shift 2
- echo "creating ext image with: $*" >> $RESULTS
- # TEST_DEV not removed as the file might have special permissions, eg.
- # when test image is on NFS and would not be writable for root
- 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
-
- # create a file to check btrfs-convert can convert regular file
- # correct
- run_check_mount_test_dev
- populate_fs
- run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/test bs=$nodesize \
- count=1 >/dev/null 2>&1
- run_check_stdout find $TEST_MNT -type f ! -name 'image' -exec md5sum {} \+ > $CHECKSUMTMP
- run_check_umount_test_dev
-
- run_check $TOP/btrfs-convert ${features:+-O "$features"} -N "$nodesize" $TEST_DEV
- run_check $TOP/btrfs check $TEST_DEV
- run_check $TOP/btrfs-show-super $TEST_DEV
-
- run_check_mount_test_dev
- run_check_stdout md5sum -c $CHECKSUMTMP |
- grep -q 'FAILED' && _fail "file validation failed."
- run_check_umount_test_dev
}
-if ! [ -z "$TEST" ]; then
- echo " [TEST/conv] skipped all convert tests, TEST=$TEST"
- exit 0
-fi
-
-for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do
- convert_test "$feature" "ext2 4k nodesize" 4096 mke2fs -b 4096
- convert_test "$feature" "ext3 4k nodesize" 4096 mke2fs -j -b 4096
- convert_test "$feature" "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096
- convert_test "$feature" "ext2 8k nodesize" 8192 mke2fs -b 4096
- convert_test "$feature" "ext3 8k nodesize" 8192 mke2fs -j -b 4096
- convert_test "$feature" "ext4 8k nodesize" 8192 mke2fs -t ext4 -b 4096
- convert_test "$feature" "ext2 16k nodesize" 16384 mke2fs -b 4096
- convert_test "$feature" "ext3 16k nodesize" 16384 mke2fs -j -b 4096
- convert_test "$feature" "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096
- convert_test "$feature" "ext2 32k nodesize" 32768 mke2fs -b 4096
- convert_test "$feature" "ext3 32k nodesize" 32768 mke2fs -j -b 4096
- convert_test "$feature" "ext4 32k nodesize" 32768 mke2fs -t ext4 -b 4096
- convert_test "$feature" "ext2 64k nodesize" 65536 mke2fs -b 4096
- convert_test "$feature" "ext3 64k nodesize" 65536 mke2fs -j -b 4096
- convert_test "$feature" "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096
+# Test special images
+for i in $(find $TOP/tests/convert-tests -maxdepth 1 -mindepth 1 -type d \
+ ${TEST:+-name "$TEST"} | sort)
+do
+ run_one_test "$i"
done
-
-rm $CHECKSUMTMP
diff --git a/tests/convert-tests/001-ext2-basic/test.sh b/tests/convert-tests/001-ext2-basic/test.sh
new file mode 100755
index 00000000..8f4f935d
--- /dev/null
+++ b/tests/convert-tests/001-ext2-basic/test.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+source $TOP/tests/common
+source $TOP/tests/common.convert
+
+setup_root_helper
+prepare_test_dev 512M
+check_prereq btrfs-convert
+
+for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do
+ convert_test "$feature" "ext2 4k nodesize" 4096 mke2fs -b 4096
+ convert_test "$feature" "ext2 8k nodesize" 8192 mke2fs -b 4096
+ convert_test "$feature" "ext2 16k nodesize" 16384 mke2fs -b 4096
+ convert_test "$feature" "ext2 32k nodesize" 32768 mke2fs -b 4096
+ convert_test "$feature" "ext2 64k nodesize" 65536 mke2fs -b 4096
+done
diff --git a/tests/convert-tests/002-ext3-basic/test.sh b/tests/convert-tests/002-ext3-basic/test.sh
new file mode 100755
index 00000000..aeb111eb
--- /dev/null
+++ b/tests/convert-tests/002-ext3-basic/test.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+source $TOP/tests/common
+source $TOP/tests/common.convert
+
+setup_root_helper
+prepare_test_dev 512M
+check_prereq btrfs-convert
+
+for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do
+ convert_test "$feature" "ext3 4k nodesize" 4096 mke2fs -j -b 4096
+ convert_test "$feature" "ext3 8k nodesize" 8192 mke2fs -j -b 4096
+ convert_test "$feature" "ext3 16k nodesize" 16384 mke2fs -j -b 4096
+ convert_test "$feature" "ext3 32k nodesize" 32768 mke2fs -j -b 4096
+ convert_test "$feature" "ext3 64k nodesize" 65536 mke2fs -j -b 4096
+done
diff --git a/tests/convert-tests/003-ext4-basic/test.sh b/tests/convert-tests/003-ext4-basic/test.sh
new file mode 100755
index 00000000..531c81bd
--- /dev/null
+++ b/tests/convert-tests/003-ext4-basic/test.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+source $TOP/tests/common
+source $TOP/tests/common.convert
+
+setup_root_helper
+prepare_test_dev 512M
+check_prereq btrfs-convert
+
+for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do
+ convert_test "$feature" "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096
+ convert_test "$feature" "ext4 8k nodesize" 8192 mke2fs -t ext4 -b 4096
+ convert_test "$feature" "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096
+ convert_test "$feature" "ext4 32k nodesize" 32768 mke2fs -t ext4 -b 4096
+ convert_test "$feature" "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096
+done
diff --git a/tests/convert-tests/004-ext2-backup-superblock-ranges/drdhdhdrd.e2image.raw.xz b/tests/convert-tests/004-ext2-backup-superblock-ranges/drdhdhdrd.e2image.raw.xz
new file mode 100644
index 00000000..73e2309c
--- /dev/null
+++ b/tests/convert-tests/004-ext2-backup-superblock-ranges/drdhdhdrd.e2image.raw.xz
Binary files differ
diff --git a/tests/convert-tests/004-ext2-backup-superblock-ranges/drdhdhrh.e2image.raw.xz b/tests/convert-tests/004-ext2-backup-superblock-ranges/drdhdhrh.e2image.raw.xz
new file mode 100644
index 00000000..0d5442ff
--- /dev/null
+++ b/tests/convert-tests/004-ext2-backup-superblock-ranges/drdhdhrh.e2image.raw.xz
Binary files differ
diff --git a/tests/convert-tests/004-ext2-backup-superblock-ranges/hrhdhdrd.e2image.raw.xz b/tests/convert-tests/004-ext2-backup-superblock-ranges/hrhdhdrd.e2image.raw.xz
new file mode 100644
index 00000000..a1a30429
--- /dev/null
+++ b/tests/convert-tests/004-ext2-backup-superblock-ranges/hrhdhdrd.e2image.raw.xz
Binary files differ
diff --git a/tests/convert-tests/004-ext2-backup-superblock-ranges/hrhdhrh.e2image.raw.xz b/tests/convert-tests/004-ext2-backup-superblock-ranges/hrhdhrh.e2image.raw.xz
new file mode 100644
index 00000000..ac0dbc60
--- /dev/null
+++ b/tests/convert-tests/004-ext2-backup-superblock-ranges/hrhdhrh.e2image.raw.xz
Binary files differ
diff --git a/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh b/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh
new file mode 100755
index 00000000..d85e4de4
--- /dev/null
+++ b/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+# Specially created e2image dump to test backup superblock migration for
+# new convert.
+# These images will cause the following problems if convert doesn't handle
+# backup superblock migration well:
+# 1) Assert while building free space tree
+# 2) Error copying inodes
+# 3) Discontinuous file extents after convert
+# 4) Overlap file extents
+# 5) Unable to rollback
+
+source $TOP/tests/common
+
+check_prereq btrfs-convert
+check_prereq btrfs
+check_prereq btrfs-show-super
+check_global_prereq e2fsck
+check_global_prereq xzcat
+
+setup_root_helper
+prepare_test_dev 512M
+
+# override common function
+function check_image() {
+ TEST_DEV="$1"
+ run_check e2fsck -n -f $TEST_DEV
+ run_check $TOP/btrfs-convert $TEST_DEV
+ run_check $TOP/btrfs check $TEST_DEV
+ run_check $TOP/btrfs-show-super $TEST_DEV
+
+ run_check_mount_test_dev
+ run_check $SUDO_HELPER e2fsck -n -f $TEST_MNT/ext2_saved/image
+ run_check $SUDO_HELPER umount $TEST_MNT
+
+ run_check $TOP/btrfs check $TEST_DEV
+ run_check $TOP/btrfs-convert -r $TEST_DEV
+ run_check e2fsck -n -f $TEST_DEV
+
+ rm -f $TEST_DEV
+}
+
+check_all_images
diff --git a/tests/convert-tests/005-delete-all-rollback/test.sh b/tests/convert-tests/005-delete-all-rollback/test.sh
new file mode 100755
index 00000000..d498e5f8
--- /dev/null
+++ b/tests/convert-tests/005-delete-all-rollback/test.sh
@@ -0,0 +1,61 @@
+#!/bin/bash
+# create a base image, convert to btrfs, remove all files, rollback the ext4 image
+# note: ext4 only
+
+source $TOP/tests/common
+source $TOP/tests/common.convert
+
+setup_root_helper
+prepare_test_dev 512M
+check_prereq btrfs-convert
+
+# simple wrapper for a convert test
+# $1: btrfs features, argument to -O
+# $2: message
+# $3: nodesize value
+# $4 + rest: command to create the ext2 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 "$@"
+ 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"
+ convert_test_post_check "$CHECKSUMTMP"
+
+ run_check_mount_test_dev
+ here=$(pwd)
+ cd "$TEST_MNT" || _fail "cannot cd to TEST_MNT"
+ # ext2_saved/image must not be deleted
+ run_mayfail $SUDO_HELPER find "$TEST_MNT"/ -mindepth 1 -path '*ext2_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
+ convert_test_post_check "$CHECKSUMTMP"
+
+ # mount again and verify checksums
+ convert_test_post_check "$CHECKSUMTMP"
+ rm "$CHECKSUMTMP"
+}
+
+for feature in '' 'extref' 'skinny-metadata' 'no-holes'; do
+ do_test "$feature" "ext4 4k nodesize" 4096 mke2fs -t ext4 -b 4096
+ do_test "$feature" "ext4 8k nodesize" 8192 mke2fs -t ext4 -b 4096
+ do_test "$feature" "ext4 16k nodesize" 16384 mke2fs -t ext4 -b 4096
+ do_test "$feature" "ext4 32k nodesize" 32768 mke2fs -t ext4 -b 4096
+ do_test "$feature" "ext4 64k nodesize" 65536 mke2fs -t ext4 -b 4096
+done
diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh
index 2aab4ff2..d1cd7329 100755
--- a/tests/fsck-tests.sh
+++ b/tests/fsck-tests.sh
@@ -1,25 +1,21 @@
#!/bin/bash
#
# loop through all of our bad images and make sure fsck repairs them properly
-#
-# It's GPL, same as everything else in this tree.
-#
-unset TOP
-unset LANG
LANG=C
SCRIPT_DIR=$(dirname $(readlink -f $0))
TOP=$(readlink -f $SCRIPT_DIR/../)
TEST_DEV=${TEST_DEV:-}
RESULTS="$TOP/tests/fsck-tests-results.txt"
+IMAGE="$TOP/tests/test.img"
source $TOP/tests/common
-# Allow child test to use $TOP and $RESULTS
export TOP
export RESULTS
-# For custom script needs to verfiy recovery
export LANG
+export IMAGE
+export TEST_DEV
rm -f $RESULTS
diff --git a/tests/fsck-tests/020-extent-ref-cases/keyed_block_ref.img b/tests/fsck-tests/020-extent-ref-cases/keyed_block_ref.img
new file mode 100644
index 00000000..289d37bc
--- /dev/null
+++ b/tests/fsck-tests/020-extent-ref-cases/keyed_block_ref.img
Binary files differ
diff --git a/tests/fsck-tests/020-extent-ref-cases/keyed_data_ref.img b/tests/fsck-tests/020-extent-ref-cases/keyed_data_ref.img
new file mode 100644
index 00000000..2ac0ae53
--- /dev/null
+++ b/tests/fsck-tests/020-extent-ref-cases/keyed_data_ref.img
Binary files differ
diff --git a/tests/fsck-tests/020-extent-ref-cases/no_inline_ref.img b/tests/fsck-tests/020-extent-ref-cases/no_inline_ref.img
new file mode 100644
index 00000000..b05ae73f
--- /dev/null
+++ b/tests/fsck-tests/020-extent-ref-cases/no_inline_ref.img
Binary files differ
diff --git a/tests/fsck-tests/020-extent-ref-cases/no_skinny_ref.img b/tests/fsck-tests/020-extent-ref-cases/no_skinny_ref.img
new file mode 100644
index 00000000..900b65ca
--- /dev/null
+++ b/tests/fsck-tests/020-extent-ref-cases/no_skinny_ref.img
Binary files differ
diff --git a/tests/fsck-tests/020-extent-ref-cases/shared_block_ref.img b/tests/fsck-tests/020-extent-ref-cases/shared_block_ref.img
new file mode 100644
index 00000000..8d7b50f7
--- /dev/null
+++ b/tests/fsck-tests/020-extent-ref-cases/shared_block_ref.img
Binary files differ
diff --git a/tests/fsck-tests/020-extent-ref-cases/shared_data_ref.img b/tests/fsck-tests/020-extent-ref-cases/shared_data_ref.img
new file mode 100644
index 00000000..aa2dafa5
--- /dev/null
+++ b/tests/fsck-tests/020-extent-ref-cases/shared_data_ref.img
Binary files differ
diff --git a/tests/fsck-tests/020-extent-ref-cases/test.sh b/tests/fsck-tests/020-extent-ref-cases/test.sh
new file mode 100755
index 00000000..c2b6a006
--- /dev/null
+++ b/tests/fsck-tests/020-extent-ref-cases/test.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+# In order to confirm that btrfsck supports to check a variety of refs, add the
+# following cases:
+#
+# * keyed_block_ref
+# * keyed_data_ref
+# * shared_block_ref
+# * shared_data_ref
+# * no_inline_ref (a extent item without inline ref)
+# * no_skinny_ref
+
+source $TOP/tests/common
+
+check_prereq btrfs
+
+for img in *.img
+do
+ image=$(extract_image $img)
+ run_check_stdout $TOP/btrfs check "$image" 2>&1 |
+ grep -q "Errors found in extent allocation tree or chunk allocation" &&
+ _fail "unexpected error occurred when checking $img"
+ rm -f "$image"
+done
diff --git a/tests/fuzz-tests.sh b/tests/fuzz-tests.sh
index 204dce2d..29691cae 100755
--- a/tests/fuzz-tests.sh
+++ b/tests/fuzz-tests.sh
@@ -2,8 +2,6 @@
#
# misc tests on fuzzed or crafted images
-unset TOP
-unset LANG
LANG=C
SCRIPT_DIR=$(dirname $(readlink -f $0))
TOP=$(readlink -f $SCRIPT_DIR/../)
@@ -17,6 +15,7 @@ export TOP
export RESULTS
export LANG
export IMAGE
+export TEST_DEV
rm -f $RESULTS
diff --git a/tests/fuzz-tests/images/superblock-stripsize-bogus.raw.txt b/tests/fuzz-tests/images/superblock-stripsize-bogus.raw.txt
new file mode 100644
index 00000000..80e073f6
--- /dev/null
+++ b/tests/fuzz-tests/images/superblock-stripsize-bogus.raw.txt
@@ -0,0 +1,32 @@
+[ 125.415910] BTRFS info (device loop0): disk space caching is enabled
+[ 125.550479] ------------[ cut here ]------------
+[ 125.551145] WARNING: CPU: 6 PID: 1496 at fs/btrfs/locking.c:251 btrfs_tree_lock+0x22e/0x250
+[ 125.552292] Modules linked in:
+[ 125.552602] CPU: 6 PID: 1496 Comm: btrfs.exe Tainted: G W 4.6.0-rc5 #130
+[ 125.553138] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.8.2-20150714_191134- 04/01/2014
+[ 125.553775] 0000000000000286 000000009b4bdd50 ffff88006a7478e0 ffffffff8157e563
+[ 125.554299] 0000000000000000 0000000000000000 ffff88006a747920 ffffffff810a74ab
+[ 125.554825] 000000fb8146c531 ffff88006bfec460 ffff88006bc63000 0000000000000000
+[ 125.555373] Call Trace:
+[ 125.555545] [<ffffffff8157e563>] dump_stack+0x85/0xc2
+[ 125.555892] [<ffffffff810a74ab>] __warn+0xcb/0xf0
+[ 125.556226] [<ffffffff810a75dd>] warn_slowpath_null+0x1d/0x20
+[ 125.556654] [<ffffffff814871ee>] btrfs_tree_lock+0x22e/0x250
+[ 125.557041] [<ffffffff81423831>] btrfs_init_new_buffer+0x81/0x160
+[ 125.557458] [<ffffffff8143472a>] btrfs_alloc_tree_block+0x22a/0x430
+[ 125.557883] [<ffffffff8141ae61>] __btrfs_cow_block+0x141/0x590
+[ 125.558279] [<ffffffff8141b44f>] btrfs_cow_block+0x11f/0x1f0
+[ 125.558666] [<ffffffff8141f09e>] btrfs_search_slot+0x1fe/0xa30
+[ 125.559063] [<ffffffff81247c9d>] ? kmem_cache_alloc+0xfd/0x240
+[ 125.559482] [<ffffffff8143b1f0>] btrfs_del_inode_ref+0x80/0x380
+[ 125.559884] [<ffffffff8148e11a>] ? btrfs_del_inode_ref_in_log+0x8a/0x160
+[ 125.560340] [<ffffffff8148e14d>] btrfs_del_inode_ref_in_log+0xbd/0x160
+[ 125.560776] [<ffffffff814507f7>] __btrfs_unlink_inode+0x1d7/0x470
+[ 125.561188] [<ffffffff814567a7>] btrfs_rename2+0x327/0x790
+[ 125.561568] [<ffffffff8127b398>] vfs_rename+0x4d8/0x840
+[ 125.561928] [<ffffffff81281b21>] SyS_rename+0x371/0x390
+[ 125.562289] [<ffffffff819cfd3c>] entry_SYSCALL_64_fastpath+0x1f/0xbd
+[ 125.562743] ---[ end trace 3b751f511705fb90 ]---
+
+---------------------------------------------------------------------------
+Fixed by patch:
diff --git a/tests/fuzz-tests/images/superblock-stripsize-bogus.raw.xz b/tests/fuzz-tests/images/superblock-stripsize-bogus.raw.xz
new file mode 100644
index 00000000..f8b3bf54
--- /dev/null
+++ b/tests/fuzz-tests/images/superblock-stripsize-bogus.raw.xz
Binary files differ
diff --git a/tests/fuzz-tests/images/superblock-total-bytes-0.raw.txt b/tests/fuzz-tests/images/superblock-total-bytes-0.raw.txt
new file mode 100644
index 00000000..d5e1f936
--- /dev/null
+++ b/tests/fuzz-tests/images/superblock-total-bytes-0.raw.txt
@@ -0,0 +1,50 @@
+[342246.846031] BTRFS info (device loop0): disk space caching is enabled
+[342246.862115] ------------[ cut here ]------------
+[342246.862500] kernel BUG at fs/btrfs/inode.c:978!
+[342246.862861] invalid opcode: 0000 [#1] SMP
+[342246.863176] Modules linked in:
+[342246.863410] CPU: 2 PID: 14504 Comm: btrfs.exe Tainted: G W 4.6.0-rc5 #130
+[342246.864010] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.8.2-20150714_191134- 04/01/2014
+[342246.864674] task: ffff88006fdf0000 ti: ffff8800702e0000 task.ti: ffff8800702e0000
+[342246.865186] RIP: 0010:[<ffffffff8144e9c7>] [<ffffffff8144e9c7>] cow_file_range+0x3f7/0x440
+[342246.865770] RSP: 0018:ffff8800702e39e0 EFLAGS: 00010206
+[342246.866157] RAX: ffff88006bb23000 RBX: 0000000000000001 RCX: 0000000000010000
+[342246.866687] RDX: 0000000000000000 RSI: 0000000000001000 RDI: 0000000000010000
+[342246.867191] RBP: ffff8800702e3a70 R08: 0000000000000000 R09: 0000000000000000
+[342246.867682] R10: 000000000000ffff R11: 0000000000010000 R12: ffff8800702e3bc0
+[342246.868170] R13: ffff8800702e3b3c R14: 0000000000000000 R15: ffff880075369c10
+[342246.868660] FS: 00007f96f5a38700(0000) GS:ffff88007ca00000(0000) knlGS:0000000000000000
+[342246.869212] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
+[342246.869642] CR2: 000000000060f4bf CR3: 000000006fc9f000 CR4: 00000000000006e0
+[342246.870146] Stack:
+[342246.870295] 0000000000000000 0000000000000001 000000000000ffff ffffea00010c08c0
+[342246.870838] ffff8800753698e8 0000000000010000 ffff88006fe0f000 000000000000ffff
+[342246.871397] 000000000000ffff ffffffff814683e5 ffff8800753698c8 ffff8800753698e8
+[342246.871944] Call Trace:
+[342246.872124] [<ffffffff814683e5>] ? test_range_bit+0xe5/0x130
+[342246.872522] [<ffffffff8144f906>] run_delalloc_range+0x396/0x3d0
+[342246.872975] [<ffffffff8146873f>] writepage_delalloc.isra.42+0x10f/0x170
+[342246.873437] [<ffffffff8146a674>] __extent_writepage+0xf4/0x370
+[342246.873848] [<ffffffff8146abf4>] extent_write_cache_pages.isra.39.constprop.57+0x304/0x3f0
+[342246.874419] [<ffffffff8146beec>] extent_writepages+0x5c/0x90
+[342246.874818] [<ffffffff8144c870>] ? btrfs_real_readdir+0x5f0/0x5f0
+[342246.875245] [<ffffffff814498f8>] btrfs_writepages+0x28/0x30
+[342246.875641] [<ffffffff811ebc61>] do_writepages+0x21/0x30
+[342246.876031] [<ffffffff811dc1a6>] __filemap_fdatawrite_range+0xc6/0x100
+[342246.876487] [<ffffffff811dc2b3>] filemap_fdatawrite_range+0x13/0x20
+[342246.876949] [<ffffffff8145eae0>] btrfs_fdatawrite_range+0x20/0x50
+[342246.877375] [<ffffffff8145eb29>] start_ordered_ops+0x19/0x30
+[342246.877774] [<ffffffff8145ebc2>] btrfs_sync_file+0x82/0x3f0
+[342246.878166] [<ffffffff810fb717>] ? update_fast_ctr+0x17/0x30
+[342246.878564] [<ffffffff812a848b>] vfs_fsync_range+0x4b/0xb0
+[342246.878987] [<ffffffff8128fce6>] ? __fget_light+0x66/0x90
+[342246.879368] [<ffffffff812a854d>] do_fsync+0x3d/0x70
+[342246.879708] [<ffffffff812a8823>] SyS_fdatasync+0x13/0x20
+[342246.880099] [<ffffffff819cfd3c>] entry_SYSCALL_64_fastpath+0x1f/0xbd
+[342246.880554] Code: 03 00 00 48 c7 c7 00 b3 c9 81 c6 05 54 b6 b1 00 01 e8 0e 8c c5 ff e9 e5 fe ff ff 49 8b 57 40 e9 c0 fe ff ff bb f4 ff ff ff eb a1 <0f> 0b 48 8b 55 80 41 b9 0f 00 00 00 41 b8 68 00 00 00 31 c9 31
+[342246.882394] RIP [<ffffffff8144e9c7>] cow_file_range+0x3f7/0x440
+[342246.882810] RSP <ffff8800702e39e0>
+[342246.883076] ---[ end trace 094193b6df6e45e7 ]---
+
+--------------------------------------------------------
+Fixed by patch:
diff --git a/tests/fuzz-tests/images/superblock-total-bytes-0.raw.xz b/tests/fuzz-tests/images/superblock-total-bytes-0.raw.xz
new file mode 100644
index 00000000..4b25020e
--- /dev/null
+++ b/tests/fuzz-tests/images/superblock-total-bytes-0.raw.xz
Binary files differ
diff --git a/tests/fuzz-tests/images/sys-chunk-stripe-len-bogus.raw.txt b/tests/fuzz-tests/images/sys-chunk-stripe-len-bogus.raw.txt
new file mode 100644
index 00000000..d3dcb0a4
--- /dev/null
+++ b/tests/fuzz-tests/images/sys-chunk-stripe-len-bogus.raw.txt
@@ -0,0 +1,54 @@
+[ 135.166891] BTRFS info (device loop0): disk space caching is enabled
+[ 135.169199] divide error: 0000 [#1] SMP
+[ 135.169581] Modules linked in:
+[ 135.169819] CPU: 2 PID: 1512 Comm: btrfs.exe Tainted: G W 4.6.0-rc5 #130
+[ 135.170285] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.8.2-20150714_191134- 04/01/2014
+[ 135.170958] task: ffff880074925180 ti: ffff880077fa4000 task.ti: ffff880077fa4000
+[ 135.171583] RIP: 0010:[<ffffffff81475ba0>] [<ffffffff81475ba0>] __btrfs_map_block+0xc0/0x11b0
+[ 135.172096] RSP: 0000:ffff880077fa77b0 EFLAGS: 00010206
+[ 135.172374] RAX: 0000000000020000 RBX: 0000000000020000 RCX: 0000000000000000
+[ 135.172754] RDX: 0000000000000000 RSI: 0000000000400000 RDI: ffff880076258270
+[ 135.173143] RBP: ffff880077fa7898 R08: 0000000000400000 R09: 0000000000000000
+[ 135.173523] R10: 0000000000000001 R11: 0000000000000000 R12: 0000000000020000
+[ 135.173916] R13: ffff880076258270 R14: ffff880077fa78e0 R15: ffff88006bb3b000
+[ 135.174290] FS: 00007fd8267dc700(0000) GS:ffff88007ca00000(0000) knlGS:0000000000000000
+[ 135.174718] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
+[ 135.175019] CR2: 00007ffe9c378df7 CR3: 0000000078788000 CR4: 00000000000006e0
+[ 135.175392] Stack:
+[ 135.175503] ffff88007cbe2c40 0000000000000000 ffff88007cbe2c50 ffff880074925180
+[ 135.175924] ffff880074926560 ffff880074925180 0000000200000000 0000000000000000
+[ 135.176340] ffffffffffffffff 0007ffffffffffff ffffffff8143eb18 0240004000000000
+[ 135.176778] Call Trace:
+[ 135.176913] [<ffffffff8143eb18>] ? btrfs_bio_wq_end_io+0x28/0x70
+[ 135.177234] [<ffffffff81477218>] btrfs_map_bio+0x88/0x350
+[ 135.177522] [<ffffffff8143eb18>] ? btrfs_bio_wq_end_io+0x28/0x70
+[ 135.177960] [<ffffffff8143ed9d>] btree_submit_bio_hook+0x6d/0x110
+[ 135.178410] [<ffffffff81464d1d>] submit_one_bio+0x6d/0xa0
+[ 135.178814] [<ffffffff8146d6f1>] read_extent_buffer_pages+0x1c1/0x350
+[ 135.179276] [<ffffffff8143cd60>] ? free_root_pointers+0x70/0x70
+[ 135.179708] [<ffffffff8143e12c>] btree_read_extent_buffer_pages.constprop.55+0xac/0x110
+[ 135.180261] [<ffffffff8143f036>] read_tree_block+0x36/0x60
+[ 135.180647] [<ffffffff81443b52>] open_ctree+0x17a2/0x2900
+[ 135.181027] [<ffffffff81417225>] btrfs_mount+0xd05/0xe60
+[ 135.181400] [<ffffffff819cd15a>] ? __mutex_unlock_slowpath+0xfa/0x1c0
+[ 135.181850] [<ffffffff810fd3e4>] ? lockdep_init_map+0x64/0x710
+[ 135.182241] [<ffffffff81272918>] mount_fs+0x38/0x170
+[ 135.182609] [<ffffffff81292b7b>] vfs_kern_mount+0x6b/0x150
+[ 135.182998] [<ffffffff814166e6>] btrfs_mount+0x1c6/0xe60
+[ 135.183372] [<ffffffff819cd15a>] ? __mutex_unlock_slowpath+0xfa/0x1c0
+[ 135.183825] [<ffffffff810fd3e4>] ? lockdep_init_map+0x64/0x710
+[ 135.184233] [<ffffffff81272918>] mount_fs+0x38/0x170
+[ 135.184583] [<ffffffff81292b7b>] vfs_kern_mount+0x6b/0x150
+[ 135.184971] [<ffffffff812958c6>] do_mount+0x256/0xeb0
+[ 135.185318] [<ffffffff8124bb33>] ? __kmalloc_track_caller+0x113/0x290
+[ 135.185759] [<ffffffff812b0b63>] ? block_ioctl+0x43/0x50
+[ 135.186124] [<ffffffff811ff023>] ? memdup_user+0x53/0x80
+[ 135.186488] [<ffffffff81296865>] SyS_mount+0x95/0xe0
+[ 135.186877] [<ffffffff819cfd3c>] entry_SYSCALL_64_fastpath+0x1f/0xbd
+[ 135.187308] Code: 8b 70 20 4c 8d 04 31 4c 39 c3 0f 87 2f 0b 00 00 48 8b 45 a8 49 89 dc 31 d2 49 29 cc 48 8b 40 70 48 63 48 10 48 89 45 a0 4c 89 e0 <48> f7 f1 49 89 cf 48 89 45 b8 48 0f af c1 49 39 c4 0f 82 c3 0a
+[ 135.189097] RIP [<ffffffff81475ba0>] __btrfs_map_block+0xc0/0x11b0
+[ 135.189527] RSP <ffff880077fa77b0>
+[ 135.189819] ---[ end trace ea21fae64670799a ]---
+
+---------------------------------------------------------------------------
+Fixed by patch:
diff --git a/tests/fuzz-tests/images/sys-chunk-stripe-len-bogus.raw.xz b/tests/fuzz-tests/images/sys-chunk-stripe-len-bogus.raw.xz
new file mode 100644
index 00000000..57d2a72f
--- /dev/null
+++ b/tests/fuzz-tests/images/sys-chunk-stripe-len-bogus.raw.xz
Binary files differ
diff --git a/tests/fuzz-tests/images/sys-chunk-type-bogus.raw.txt b/tests/fuzz-tests/images/sys-chunk-type-bogus.raw.txt
new file mode 100644
index 00000000..2559924d
--- /dev/null
+++ b/tests/fuzz-tests/images/sys-chunk-type-bogus.raw.txt
@@ -0,0 +1,55 @@
+[ 145.676440] BTRFS error (device loop0): bad tree block start 0 131072
+[ 145.677032] ------------[ cut here ]------------
+[ 145.677307] kernel BUG at fs/btrfs/raid56.c:2142!
+[ 145.677627] invalid opcode: 0000 [#1] SMP
+[ 145.677955] Modules linked in:
+[ 145.678182] CPU: 3 PID: 1538 Comm: btrfs.exe Tainted: G W 4.6.0-rc5 #130
+[ 145.678734] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.8.2-20150714_191134- 04/01/2014
+[ 145.679402] task: ffff88006c830000 ti: ffff88006fc74000 task.ti: ffff88006fc74000
+[ 145.679919] RIP: 0010:[<ffffffff814c5794>] [<ffffffff814c5794>] raid56_parity_recover+0xc4/0x160
+[ 145.680514] RSP: 0018:ffff88006fc77868 EFLAGS: 00010286
+[ 145.680865] RAX: ffff88006f725280 RBX: ffff880070ba0a68 RCX: 0000000000020000
+[ 145.681373] RDX: 0000000000000100 RSI: 00000000ffffffff RDI: ffffffff831229e8
+[ 145.681866] RBP: ffff88006fc77898 R08: 0000000000010000 R09: ffff8800768ff400
+[ 145.682380] R10: ffff88007c003180 R11: 0000000000030000 R12: ffff88006f725280
+[ 145.682870] R13: ffff88007b449000 R14: 0000000000000001 R15: ffff8800768ff400
+[ 145.683363] FS: 00007f68b95a8700(0000) GS:ffff88007cc00000(0000) knlGS:0000000000000000
+[ 145.683941] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
+[ 145.684340] CR2: 00007fff0d130f98 CR3: 000000006bfd7000 CR4: 00000000000006e0
+[ 145.684832] Stack:
+[ 145.684977] 00000002e6816dd1 ffff880070ba0a68 ffff88007b449000 0000000000000001
+[ 145.685541] 0000000000020000 0000000000000002 ffff88006fc77920 ffffffff814773cd
+[ 145.686082] ffff880000000001 0000000002400040 ffff88006fc778f8 0000000081247c9d
+[ 145.686654] Call Trace:
+[ 145.686831] [<ffffffff814773cd>] btrfs_map_bio+0x23d/0x350
+[ 145.687217] [<ffffffff8143ed9d>] btree_submit_bio_hook+0x6d/0x110
+[ 145.687649] [<ffffffff81464d1d>] submit_one_bio+0x6d/0xa0
+[ 145.688028] [<ffffffff8146d6f1>] read_extent_buffer_pages+0x1c1/0x350
+[ 145.688501] [<ffffffff8143cd60>] ? free_root_pointers+0x70/0x70
+[ 145.688916] [<ffffffff8143e12c>] btree_read_extent_buffer_pages.constprop.55+0xac/0x110
+[ 145.689474] [<ffffffff8143f036>] read_tree_block+0x36/0x60
+[ 145.689861] [<ffffffff81443b52>] open_ctree+0x17a2/0x2900
+[ 145.690242] [<ffffffff81417225>] btrfs_mount+0xd05/0xe60
+[ 145.690623] [<ffffffff819cd15a>] ? __mutex_unlock_slowpath+0xfa/0x1c0
+[ 145.691064] [<ffffffff810fd3e4>] ? lockdep_init_map+0x64/0x710
+[ 145.691510] [<ffffffff81272918>] mount_fs+0x38/0x170
+[ 145.691852] [<ffffffff81292b7b>] vfs_kern_mount+0x6b/0x150
+[ 145.692227] [<ffffffff814166e6>] btrfs_mount+0x1c6/0xe60
+[ 145.692594] [<ffffffff819cd15a>] ? __mutex_unlock_slowpath+0xfa/0x1c0
+[ 145.693032] [<ffffffff810fd3e4>] ? lockdep_init_map+0x64/0x710
+[ 145.693453] [<ffffffff81272918>] mount_fs+0x38/0x170
+[ 145.693793] [<ffffffff81292b7b>] vfs_kern_mount+0x6b/0x150
+[ 145.694168] [<ffffffff812958c6>] do_mount+0x256/0xeb0
+[ 145.694537] [<ffffffff8124bb33>] ? __kmalloc_track_caller+0x113/0x290
+[ 145.694974] [<ffffffff812b0b63>] ? block_ioctl+0x43/0x50
+[ 145.695338] [<ffffffff811ff023>] ? memdup_user+0x53/0x80
+[ 145.695703] [<ffffffff81296865>] SyS_mount+0x95/0xe0
+[ 145.696046] [<ffffffff819cfd3c>] entry_SYSCALL_64_fastpath+0x1f/0xbd
+[ 145.696480] Code: 1f 48 8b 78 58 31 c0 48 8b 14 c7 48 39 d1 72 08 4c 01 c2 48 39 d1 72 15 48 83 c0 01 39 c6 7f e7 41 c7 87 3c 01 00 00 ff ff ff ff <0f> 0b 45 85 f6 41 89 87 3c 01 00 00 75 35 4c 89 e7 e8 e6 02 fb
+[ 145.698326] RIP [<ffffffff814c5794>] raid56_parity_recover+0xc4/0x160
+[ 145.698771] RSP <ffff88006fc77868>
+[ 145.699047] ---[ end trace 22f39f01df276367 ]---
+
+-----------------------------------------------------
+Fixed by patch:
+
diff --git a/tests/fuzz-tests/images/sys-chunk-type-bogus.raw.xz b/tests/fuzz-tests/images/sys-chunk-type-bogus.raw.xz
new file mode 100644
index 00000000..ef971ca3
--- /dev/null
+++ b/tests/fuzz-tests/images/sys-chunk-type-bogus.raw.xz
Binary files differ
diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh
index 2a7f57c5..eefe8a81 100755
--- a/tests/misc-tests.sh
+++ b/tests/misc-tests.sh
@@ -2,8 +2,6 @@
#
# Misc tests
-unset TOP
-unset LANG
LANG=C
SCRIPT_DIR=$(dirname $(readlink -f $0))
TOP=$(readlink -f $SCRIPT_DIR/../)
@@ -13,12 +11,10 @@ IMAGE="$TOP/tests/test.img"
source $TOP/tests/common
-# Allow child test to use $TOP and $RESULTS
export TOP
export RESULTS
-# For custom script needs to verfiy recovery
export LANG
-# For tests that only use a loop device
+export TEST_DEV
export IMAGE
rm -f $RESULTS
diff --git a/tests/misc-tests/007-subvolume-sync/test.sh b/tests/misc-tests/007-subvolume-sync/test.sh
index a745fb56..243bb8cc 100755
--- a/tests/misc-tests/007-subvolume-sync/test.sh
+++ b/tests/misc-tests/007-subvolume-sync/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# test btrfs subvolume run normally with more than one subvolume
#
-# - btrfs subvolume must not loop indefinetelly
+# - btrfs subvolume must not loop indefinitely
# - btrfs subvolume return 0 in normal case
source $TOP/tests/common
@@ -16,7 +16,7 @@ run_check $SUDO_HELPER $TOP/mkfs.btrfs -f "$TEST_DEV"
run_check_mount_test_dev
# to check following thing in both 1 and multiple subvolume case:
-# 1: is subvolume sync loop indefinetelly
+# 1: is subvolume sync loop indefinitely
# 2: is return value right
#
run_check $SUDO_HELPER $TOP/btrfs subvolume create "$TEST_MNT"/mysubvol1
diff --git a/tests/misc-tests/009-subvolume-sync-must-wait/test.sh b/tests/misc-tests/009-subvolume-sync-must-wait/test.sh
index 056584e5..92c896f9 100755
--- a/tests/misc-tests/009-subvolume-sync-must-wait/test.sh
+++ b/tests/misc-tests/009-subvolume-sync-must-wait/test.sh
@@ -1,6 +1,6 @@
#!/bin/bash
#
-# Verify that subovolume sync waits until the subvolume is cleaned
+# Verify that subvolume sync waits until the subvolume is cleaned
source $TOP/tests/common
diff --git a/tests/misc-tests/013-subvolume-sync-crash/test.sh b/tests/misc-tests/013-subvolume-sync-crash/test.sh
index c7955269..4cb1b4e7 100755
--- a/tests/misc-tests/013-subvolume-sync-crash/test.sh
+++ b/tests/misc-tests/013-subvolume-sync-crash/test.sh
@@ -1,6 +1,6 @@
#!/bin/bash
#
-# Verify that subovolume sync waits until the subvolume is cleaned and does not
+# Verify that subvolume sync waits until the subvolume is cleaned and does not
# crash at the end
source $TOP/tests/common
diff --git a/tests/mkfs-tests.sh b/tests/mkfs-tests.sh
index c0635ad1..1afc0282 100755
--- a/tests/mkfs-tests.sh
+++ b/tests/mkfs-tests.sh
@@ -2,8 +2,6 @@
#
# mkfs.btrfs tests
-unset TOP
-unset LANG
LANG=C
SCRIPT_DIR=$(dirname $(readlink -f $0))
TOP=$(readlink -f $SCRIPT_DIR/../)
@@ -13,13 +11,11 @@ IMAGE="$TOP/tests/test.img"
source $TOP/tests/common
-# Allow child test to use $TOP and $RESULTS
export TOP
export RESULTS
-# For custom script needs to verfiy recovery
export LANG
-# For tests that only use a loop device
export IMAGE
+export TEST_DEV
rm -f $RESULTS
diff --git a/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh b/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh
index 79cc2b22..151e7b77 100755
--- a/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh
+++ b/tests/mkfs-tests/008-secorsize-nodesize-combination/test.sh
@@ -34,7 +34,7 @@ do_test 8191 8191 && _fail
# Invalid: Aligned sectorsize with unaligned nodesize
do_test 4k 16385 && _fail
-# Invalid: Ungliend sectorsize with aligned nodesize
+# Invalid: Unaligned sectorsize with aligned nodesize
do_test 8191 16k && _fail
# Valid: Aligned sectorsize and nodesize
diff --git a/tests/test-console.sh b/tests/test-console.sh
new file mode 100755
index 00000000..cc1cdf3c
--- /dev/null
+++ b/tests/test-console.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+# a shell with test environment set up, logged commands and output
+
+LANG=C
+SCRIPT_DIR=$(dirname $(readlink -f $0))
+TOP=$(readlink -f $SCRIPT_DIR/../)
+TEST_DEV=${TEST_DEV:-}
+RESULTS="$TOP/tests/test-console.txt"
+IMAGE="$TOP/tests/test.img"
+
+source common
+source common.convert
+
+setup_root_helper
+
+echo "Eval loop in test environment (log: $RESULTS)"
+echo -e " ---------------------\nStarting session, `date`" >> "$RESULTS"
+echo -n "`pwd`> "
+while read x; do
+ echo "COMMAND: $x" >> "$RESULTS"
+ { eval $x; } 2>&1 | tee -a "$RESULTS"
+ echo -n "`pwd`> "
+done