summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDimitri John Ledkov <xnox@ubuntu.com>2018-02-19 15:51:31 +0000
committerDimitri John Ledkov <xnox@ubuntu.com>2018-02-19 15:52:49 +0000
commitb70cb0d0a21394d5d6b00b51f064115c2724cea8 (patch)
treef001381d2ee826e6665e003e7c6dccb084a54316 /tests
parentf1b0adb46b2c193e940f8c22b35036d2ee76c673 (diff)
Diffstat (limited to 'tests')
-rw-r--r--tests/README.md86
-rwxr-xr-xtests/clean-tests.sh33
-rwxr-xr-xtests/cli-tests.sh34
-rwxr-xr-xtests/cli-tests/001-btrfs/test.sh2
-rwxr-xr-xtests/cli-tests/002-balance-full-no-filters/test.sh2
-rwxr-xr-xtests/cli-tests/003-fi-resize-args/test.sh2
-rwxr-xr-xtests/cli-tests/004-send-parent-multi-subvol/test.sh2
-rwxr-xr-xtests/cli-tests/005-qgroup-show/test.sh2
-rwxr-xr-xtests/cli-tests/006-qgroup-show-sync/test.sh2
-rwxr-xr-xtests/cli-tests/007-check-force/test.sh2
-rwxr-xr-xtests/cli-tests/008-subvolume-get-set-default/test.sh2
-rw-r--r--tests/common26
-rwxr-xr-xtests/convert-tests.sh34
-rwxr-xr-xtests/convert-tests/001-ext2-basic/test.sh4
-rwxr-xr-xtests/convert-tests/002-ext3-basic/test.sh4
-rwxr-xr-xtests/convert-tests/003-ext4-basic/test.sh4
-rwxr-xr-xtests/convert-tests/004-ext2-backup-superblock-ranges/test.sh2
-rwxr-xr-xtests/convert-tests/005-delete-all-rollback/test.sh4
-rwxr-xr-xtests/convert-tests/006-large-hole-extent/test.sh4
-rwxr-xr-xtests/convert-tests/007-unsupported-block-sizes/test.sh4
-rwxr-xr-xtests/convert-tests/008-readonly-image/test.sh4
-rwxr-xr-xtests/convert-tests/009-common-inode-flags/test.sh4
-rwxr-xr-xtests/convert-tests/010-reiserfs-basic/test.sh4
-rwxr-xr-xtests/convert-tests/011-reiserfs-delete-all-rollback/test.sh4
-rwxr-xr-xtests/convert-tests/012-reiserfs-large-hole-extent/test.sh4
-rwxr-xr-xtests/convert-tests/013-reiserfs-common-inode-flags/test.sh4
-rwxr-xr-xtests/convert-tests/014-reiserfs-tail-handling/test.sh4
-rwxr-xr-xtests/convert-tests/015-no-rollback-after-balance/test.sh4
-rwxr-xr-xtests/export-testsuite.sh55
-rwxr-xr-xtests/fsck-tests.sh34
-rwxr-xr-xtests/fsck-tests/006-bad-root-items/test.sh2
-rwxr-xr-xtests/fsck-tests/012-leaf-corruption/test.sh2
-rwxr-xr-xtests/fsck-tests/013-extent-tree-rebuild/test.sh4
-rwxr-xr-xtests/fsck-tests/015-tree-reloc-tree/test.sh (renamed from tests/fsck-tests/027-tree-reloc-tree/test.sh)0
-rw-r--r--tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz (renamed from tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz)bin2112 -> 2112 bytes
-rw-r--r--tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz (renamed from tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz)bin2424 -> 2424 bytes
-rwxr-xr-xtests/fsck-tests/018-leaf-crossing-stripes/test.sh2
-rwxr-xr-xtests/fsck-tests/019-non-skinny-false-alert/test.sh2
-rwxr-xr-xtests/fsck-tests/020-extent-ref-cases/test.sh2
-rwxr-xr-xtests/fsck-tests/021-partially-dropped-snapshot-case/test.sh2
-rwxr-xr-xtests/fsck-tests/022-qgroup-rescan-halfway/test.sh2
-rwxr-xr-xtests/fsck-tests/023-qgroup-stack-overflow/test.sh2
-rwxr-xr-xtests/fsck-tests/024-clear-space-cache/test.sh2
-rwxr-xr-xtests/fsck-tests/025-file-extents/test.sh2
-rwxr-xr-xtests/fsck-tests/026-bad-dir-item-name/test.sh2
-rwxr-xr-xtests/fsck-tests/028-unaligned-super-dev-sizes/test.sh17
-rw-r--r--tests/fssum.c27
-rwxr-xr-xtests/fuzz-tests.sh34
-rwxr-xr-xtests/fuzz-tests/001-simple-check-unmounted/test.sh4
-rwxr-xr-xtests/fuzz-tests/002-simple-image/test.sh4
-rwxr-xr-xtests/fuzz-tests/003-multi-check-unmounted/test.sh4
-rwxr-xr-xtests/fuzz-tests/004-simple-dump-tree/test.sh4
-rwxr-xr-xtests/fuzz-tests/005-simple-dump-super/test.sh4
-rwxr-xr-xtests/fuzz-tests/006-simple-tree-stats/test.sh4
-rwxr-xr-xtests/fuzz-tests/007-simple-super-recover/test.sh4
-rwxr-xr-xtests/fuzz-tests/008-simple-chunk-recover/test.sh4
-rwxr-xr-xtests/fuzz-tests/009-simple-zero-log/test.sh4
-rwxr-xr-xtests/misc-tests.sh36
-rwxr-xr-xtests/misc-tests/001-btrfstune-features/test.sh2
-rwxr-xr-xtests/misc-tests/002-uuid-rewrite/test.sh6
-rwxr-xr-xtests/misc-tests/003-zero-log/test.sh4
-rwxr-xr-xtests/misc-tests/004-shrink-fs/test.sh2
-rwxr-xr-xtests/misc-tests/005-convert-progress-thread-crash/test.sh2
-rwxr-xr-xtests/misc-tests/006-image-on-missing-device/test.sh2
-rwxr-xr-xtests/misc-tests/007-subvolume-sync/test.sh2
-rwxr-xr-xtests/misc-tests/008-leaf-crossing-stripes/test.sh2
-rwxr-xr-xtests/misc-tests/009-subvolume-sync-must-wait/test.sh2
-rwxr-xr-xtests/misc-tests/010-convert-delete-ext2-subvol/test.sh2
-rwxr-xr-xtests/misc-tests/011-delete-missing-device/test.sh2
-rwxr-xr-xtests/misc-tests/012-find-root-no-result/test.sh2
-rwxr-xr-xtests/misc-tests/013-subvolume-sync-crash/test.sh2
-rwxr-xr-xtests/misc-tests/014-filesystem-label/test.sh2
-rwxr-xr-xtests/misc-tests/015-dump-super-garbage/test.sh2
-rwxr-xr-xtests/misc-tests/016-send-clone-src/test.sh2
-rwxr-xr-xtests/misc-tests/017-recv-stream-malformatted/test.sh2
-rwxr-xr-xtests/misc-tests/018-recv-end-of-stream/test.sh2
-rwxr-xr-xtests/misc-tests/019-receive-clones-on-mounted-subvol/test.sh4
-rwxr-xr-xtests/misc-tests/020-fix-superblock-corruption/test.sh2
-rwxr-xr-xtests/misc-tests/021-image-multi-devices/test.sh2
-rwxr-xr-xtests/misc-tests/022-filesystem-du-on-empty-subvol/test.sh2
-rwxr-xr-xtests/misc-tests/023-device-usage-with-missing-device/test.sh2
-rwxr-xr-xtests/misc-tests/024-inspect-internal-rootid/test.sh2
-rwxr-xr-xtests/misc-tests/025-zstd-compression/test.sh2
-rwxr-xr-xtests/misc-tests/026-image-non-printable-chars/test.sh2
-rwxr-xr-xtests/misc-tests/027-subvol-list-deleted-toplevel/test.sh2
-rwxr-xr-xtests/misc-tests/028-superblock-recover/test.sh57
-rwxr-xr-xtests/mkfs-tests.sh34
-rwxr-xr-xtests/mkfs-tests/001-basic-profiles/test.sh2
-rwxr-xr-xtests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh2
-rwxr-xr-xtests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh2
-rwxr-xr-xtests/mkfs-tests/004-rootdir-keeps-size/test.sh4
-rwxr-xr-xtests/mkfs-tests/005-long-device-name-for-ssd/test.sh2
-rwxr-xr-xtests/mkfs-tests/006-partitioned-loopdev/test.sh2
-rwxr-xr-xtests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh2
-rwxr-xr-xtests/mkfs-tests/008-sectorsize-nodesize-combination/test.sh2
-rwxr-xr-xtests/mkfs-tests/009-special-files-for-rootdir/test.sh2
-rwxr-xr-xtests/mkfs-tests/010-minimal-size/test.sh63
-rwxr-xr-xtests/mkfs-tests/011-rootdir-create-file/test.sh15
-rwxr-xr-xtests/mkfs-tests/012-rootdir-no-shrink/test.sh39
-rwxr-xr-xtests/mkfs-tests/013-reserved-1M-for-single/test.sh44
-rw-r--r--tests/testsuite-files22
101 files changed, 700 insertions, 208 deletions
diff --git a/tests/README.md b/tests/README.md
index 04d2ce2a..d4b80da1 100644
--- a/tests/README.md
+++ b/tests/README.md
@@ -45,46 +45,51 @@ $ make TEST=001\* test-fsck
$ TEST=001\* ./fsck-tests.sh
```
-will run the first test in fsck-tests subdirectory.
+will run the first test in fsck-tests subdirectory. If the test directories
+follow a good naming scheme, it's possible to select a subset eg. like the
+convert tests for ext[234] filesystems.
## Test structure
-*tests/fsck-tests/:*
+*tests/fsck-tests/*
- * tests targeted at bugs that are fixable by fsck
+ * tests targeted at bugs that are fixable by fsck, the test directory can
+ contain images that will get fixed, or a custom script `./test.sh` that
+ will be run if present
-*tests/convert-tests/:*
+*tests/convert-tests/*
- * coverage tests of ext2/3/4 and btrfs-convert options
+ * coverage tests of ext2/3/4 or reiserfs and btrfs-convert options
-*tests/fuzz-tests/:*
+*tests/fuzz-tests/*
* collection of fuzzed or crafted images
* tests that are supposed to run various utilities on the images and not
crash
-*tests/cli-tests/:*
+*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/:*
+*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:*
+*tests/common, tests/common.convert*
- * script with shell helpers, separated by functionality
+ * scripts with shell helpers, separated by functionality
-*tests/test.img:*
+*tests/test.img*
- * default testing image, the file is never deleted by the scripts but
- truncated to 0 bytes, so it keeps it's permissions. It's eg. possible to
- host it on NFS, make it `chmod a+w` for root.
+ * default testing image, available as `TEST_DEV` variable, the file is never
+ deleted by the scripts but truncated to 0 bytes, so it keeps it's
+ permissions. It's eg. possible to host it on NFS, make it `chmod a+w` for
+ root.
## Other tuning, environment variables
@@ -125,10 +130,10 @@ Multiple values can be separated by `,`.
### Permissions
-Some commands require root privileges (to mount/umount, access loop devices).
-It is assumed that `sudo` will work in some way (no password, password asked
-and cached). Note that instrumentation is not applied in this case, for safety
-reasons. You need to modify the test script instead.
+Some commands require root privileges (to mount/umount, access loop devices or
+call privileged ioctls). It is assumed that `sudo` will work in some way (no
+password, password asked and cached). Note that instrumentation is not applied
+in this case, for safety reasons. You need to modify the test script instead.
### Cleanup
@@ -143,13 +148,14 @@ 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.
+logs the output with the testing environment set up. It sources the common
+helper scripts so the shell functions are available.
### 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`
+`e2fsprogs`, `reiserfsprogs`.
## New test
@@ -158,13 +164,15 @@ specific tests need the following packages installed: `acl`, `attr`,
an easy start copy an existing `test.sh` script from some test that might be
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.
+how to do mkfs, mount, unmount, check, loop device management etc.
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`.
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.
+begining of `test.sh`. You don't need to add the file to git yet. Don't forget
+to make the file executable, otherwise it's not going to be executed by the
+infrastructure.
4. Write the test commands, comment anything that's not obvious.
@@ -178,10 +186,12 @@ $ 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`
+7. A commit that fixes a bug should be applied before the test that verifies
+ the fix. This is to keep the git history bisectable.
### Crafted/fuzzed images
-Images that are create by fuzzing or specially crafted to trigger some error
+Images that are created by fuzzing or specially crafted to trigger some error
conditions should be added to the directory *fuzz-tests/images*, accompanied by
a textual description of the source (bugzilla, mail), the reporter, brief
description of the problem or the stack trace.
@@ -191,6 +201,31 @@ the fuzz tests always succeed when run on random checked out. This helps
bisectability.
+# Exported testsuite
+
+The tests are typically run from git on binaries built from the git sources. It
+is possible to extract only the testsuite files and run it independently. Use
+
+```shell
+$ make testsuite
+```
+
+This will gather scripts and generate `tests/btrfs-progs-tests.tar.gz`. The
+files inside the tar are in the top level directory, make sure you extract
+the contents to an empty directory. From there you can start the tests as
+described above (the non-make variant).
+
+By default the binaries found in `$PATH` are used, this will normally mean the
+system binaries. You can also override the `$TOP` shell variable and this
+path will be used as prefix for all btrfs binaries inside the tests.
+
+There are some utilities that are not distributed but are necessary for the
+tests. They are in the top level directory of the testsuite and their path
+cannot be set.
+
+The tests assume write acesss to their directories.
+
+
# Coding style, best practices
## do
@@ -206,8 +241,9 @@ bisectability.
always built when the tests are started through make
* use functions instead of repeating code
* generic helpers could be factored to the `common` script
-* cleanup after successful test
-* use common helpers and variables
+* cleanup files an intermediate state (mount, loop devices, device mapper
+ devices) a after successful test
+* use common helpers and variables where possible
## do not
diff --git a/tests/clean-tests.sh b/tests/clean-tests.sh
index 61baa069..342616f7 100755
--- a/tests/clean-tests.sh
+++ b/tests/clean-tests.sh
@@ -1,9 +1,34 @@
#!/bin/bash
# remove all intermediate files from tests
+LANG=C
SCRIPT_DIR=$(dirname $(readlink -f "$0"))
-TOP=$(readlink -f "$SCRIPT_DIR/../")
-source "$TOP/tests/common"
+if [ -z "$TOP" ]; then
+ TOP=$(readlink -f "$SCRIPT_DIR/../")
+ if [ -f "$TOP/configure.ac" ]; then
+ # inside git
+ TEST_TOP="$TOP/tests/"
+ INTERNAL_BIN="$TOP"
+ else
+ # external, defaults to system binaries
+ TOP=$(dirname `which btrfs`)
+ TEST_TOP="$SCRIPT_DIR"
+ INTERNAL_BIN="$TEST_TOP"
+ fi
+else
+ # assume external, TOP set from commandline
+ TEST_TOP="$SCRIPT_DIR"
+ INTERNAL_BIN="$TEST_TOP"
+fi
+if ! [ -x "$TOP/btrfs" ]; then
+ echo "ERROR: cannot execute btrfs from TOP=$TOP"
+ exit 1
+fi
+TEST_DEV=${TEST_DEV:-}
+RESULTS="$TEST_TOP/cli-tests-results.txt"
+IMAGE="$TEST_TOP/test.img"
+
+source "$TEST_TOP/common"
setup_root_helper
@@ -13,8 +38,8 @@ fi
$SUDO_HELPER umount "$TEST_MNT" &>/dev/null
-if ! cd "$TOP/tests"; then
- echo "ERROR: cannot cd to $TOP/tests"
+if ! cd "$TEST_TOP"; then
+ echo "ERROR: cannot cd to $TEST_TOP"
exit 1
fi
diff --git a/tests/cli-tests.sh b/tests/cli-tests.sh
index 16d6afcf..9e0fbae4 100755
--- a/tests/cli-tests.sh
+++ b/tests/cli-tests.sh
@@ -4,13 +4,35 @@
LANG=C
SCRIPT_DIR=$(dirname $(readlink -f "$0"))
-TOP=$(readlink -f "$SCRIPT_DIR/../")
+if [ -z "$TOP" ]; then
+ TOP=$(readlink -f "$SCRIPT_DIR/../")
+ if [ -f "$TOP/configure.ac" ]; then
+ # inside git
+ TEST_TOP="$TOP/tests/"
+ INTERNAL_BIN="$TOP"
+ else
+ # external, defaults to system binaries
+ TOP=$(dirname `which btrfs`)
+ TEST_TOP="$SCRIPT_DIR"
+ INTERNAL_BIN="$TEST_TOP"
+ fi
+else
+ # assume external, TOP set from commandline
+ TEST_TOP="$SCRIPT_DIR"
+ INTERNAL_BIN="$TEST_TOP"
+fi
+if ! [ -x "$TOP/btrfs" ]; then
+ echo "ERROR: cannot execute btrfs from TOP=$TOP"
+ exit 1
+fi
TEST_DEV=${TEST_DEV:-}
-RESULTS="$TOP/tests/cli-tests-results.txt"
-IMAGE="$TOP/tests/test.img"
+RESULTS="$TEST_TOP/cli-tests-results.txt"
+IMAGE="$TEST_TOP/test.img"
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
+export INTERNAL_BIN
+export TEST_TOP
export TOP
export RESULTS
export LANG
@@ -24,7 +46,7 @@ check_kernel_support
# The tests are driven by their custom script called 'test.sh'
-for i in $(find "$TOP/tests/cli-tests" -maxdepth 1 -mindepth 1 -type d \
+for i in $(find "$TEST_TOP/cli-tests" -maxdepth 1 -mindepth 1 -type d \
${TEST:+-name "$TEST"} | sort)
do
name=$(basename "$i")
@@ -40,5 +62,5 @@ do
_fail "test failed for case $(basename $i)"
fi
fi
- cd "$TOP"
+ cd "$TEST_TOP"
done
diff --git a/tests/cli-tests/001-btrfs/test.sh b/tests/cli-tests/001-btrfs/test.sh
index c680604b..55ab0ad5 100755
--- a/tests/cli-tests/001-btrfs/test.sh
+++ b/tests/cli-tests/001-btrfs/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# test commands of btrfs
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs
diff --git a/tests/cli-tests/002-balance-full-no-filters/test.sh b/tests/cli-tests/002-balance-full-no-filters/test.sh
index 0475ea73..3403b700 100755
--- a/tests/cli-tests/002-balance-full-no-filters/test.sh
+++ b/tests/cli-tests/002-balance-full-no-filters/test.sh
@@ -2,7 +2,7 @@
#
# coverage of balance --full-balance
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/cli-tests/003-fi-resize-args/test.sh b/tests/cli-tests/003-fi-resize-args/test.sh
index e4f262b6..f6f598f2 100755
--- a/tests/cli-tests/003-fi-resize-args/test.sh
+++ b/tests/cli-tests/003-fi-resize-args/test.sh
@@ -2,7 +2,7 @@
#
# test parsing of various resize arguments
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/cli-tests/004-send-parent-multi-subvol/test.sh b/tests/cli-tests/004-send-parent-multi-subvol/test.sh
index c1348b50..165ef4a6 100755
--- a/tests/cli-tests/004-send-parent-multi-subvol/test.sh
+++ b/tests/cli-tests/004-send-parent-multi-subvol/test.sh
@@ -2,7 +2,7 @@
#
# minimal test for the following syntax: btrfs send -p parent subvol1 subvol2
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/cli-tests/005-qgroup-show/test.sh b/tests/cli-tests/005-qgroup-show/test.sh
index d9a91831..10521039 100755
--- a/tests/cli-tests/005-qgroup-show/test.sh
+++ b/tests/cli-tests/005-qgroup-show/test.sh
@@ -2,7 +2,7 @@
#
# qgroup show behaviour when quotas are not enabled
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/cli-tests/006-qgroup-show-sync/test.sh b/tests/cli-tests/006-qgroup-show-sync/test.sh
index d552b8b9..aec7a4ba 100755
--- a/tests/cli-tests/006-qgroup-show-sync/test.sh
+++ b/tests/cli-tests/006-qgroup-show-sync/test.sh
@@ -2,7 +2,7 @@
#
# simple test of qgroup show --sync option
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/cli-tests/007-check-force/test.sh b/tests/cli-tests/007-check-force/test.sh
index 12b30205..597f2d60 100755
--- a/tests/cli-tests/007-check-force/test.sh
+++ b/tests/cli-tests/007-check-force/test.sh
@@ -2,7 +2,7 @@
#
# test 'btrfs check --force' on a mounted filesystem
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/cli-tests/008-subvolume-get-set-default/test.sh b/tests/cli-tests/008-subvolume-get-set-default/test.sh
index 9318002e..706ee8c5 100755
--- a/tests/cli-tests/008-subvolume-get-set-default/test.sh
+++ b/tests/cli-tests/008-subvolume-get-set-default/test.sh
@@ -10,7 +10,7 @@ check_default_id()
fi
}
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/common b/tests/common
index 734cd171..fae30f1d 100644
--- a/tests/common
+++ b/tests/common
@@ -290,8 +290,12 @@ run_mustfail_stdout()
check_prereq()
{
- if ! [ -f "$TOP/$1" ]; then
- _fail "Failed prerequisites: $1";
+ if [ "$1" = "btrfs-corrupt-block" -o "$1" = "fssum" ]; then
+ if ! [ -f "$INTERNAL_BIN/$1" ]; then
+ _fail "Failed prerequisites: $INTERNAL_BIN/$1";
+ fi
+ elif ! [ -f "$TOP/$1" ]; then
+ _fail "Failed prerequisites: $TOP/$1";
fi
}
@@ -331,7 +335,7 @@ extract_image()
case "$image" in
*.img)
rm -f "$image.restored"
- : ;;
+ ;;
*.img.xz)
xz --decompress --keep "$image" || \
_fail "failed to decompress image $image" >&2
@@ -444,14 +448,16 @@ prepare_test_dev()
[[ "$size" ]] || size='2G'
# Still truncate it to new size
if [ -n "$TEST_DEV" ]; then
+ truncate -s 0 "$TEST_DEV"
truncate -s "$size" "$TEST_DEV"
return;
fi
- echo "\$TEST_DEV not given, use $TOP/test/test.img as fallback" >> \
+ echo "\$TEST_DEV not given, using $TEST_TOP/test.img as fallback" >> \
"$RESULTS"
- TEST_DEV="$TOP/tests/test.img"
+ TEST_DEV="$TEST_TOP/test.img"
+ truncate -s 0 "$TEST_DEV"
truncate -s "$size" "$TEST_DEV" || _not_run "create file for loop device failed"
}
@@ -475,10 +481,14 @@ run_check_mount_test_dev()
run_check $SUDO_HELPER mount -t btrfs $loop_opt "$@" "$TEST_DEV" "$TEST_MNT"
}
+# $1-$n: optional paths to unmount, otherwise fallback to TEST_DEV
run_check_umount_test_dev()
{
setup_root_helper
- run_check $SUDO_HELPER umount "$@" "$TEST_DEV"
+ if [ "$#" = 0 ]; then
+ set -- "$TEST_DEV"
+ fi
+ run_check $SUDO_HELPER umount "$@"
}
check_kernel_support()
@@ -626,11 +636,11 @@ cleanup_loopdevs()
init_env()
{
- TEST_MNT="${TEST_MNT:-$TOP/tests/mnt}"
+ TEST_MNT="${TEST_MNT:-$TEST_TOP/mnt}"
export TEST_MNT
mkdir -p "$TEST_MNT" || { echo "Failed mkdir -p $TEST_MNT"; exit 1; }
- source $TOP/tests/common.local
+ source $TEST_TOP/common.local
if [ "$TEST_ENABLE_OVERRIDE" = 'true' -a -n "$RESULTS" ]; then
echo "INCLUDE common.local" >> "$RESULTS"
diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh
index 2a92a58b..4bc915db 100755
--- a/tests/convert-tests.sh
+++ b/tests/convert-tests.sh
@@ -5,14 +5,36 @@
LANG=C
SCRIPT_DIR=$(dirname $(readlink -f "$0"))
-TOP=$(readlink -f "$SCRIPT_DIR/../")
+if [ -z "$TOP" ]; then
+ TOP=$(readlink -f "$SCRIPT_DIR/../")
+ if [ -f "$TOP/configure.ac" ]; then
+ # inside git
+ TEST_TOP="$TOP/tests/"
+ INTERNAL_BIN="$TOP"
+ else
+ # external, defaults to system binaries
+ TOP=$(dirname `which btrfs`)
+ TEST_TOP="$SCRIPT_DIR"
+ INTERNAL_BIN="$TEST_TOP"
+ fi
+else
+ # assume external, TOP set from commandline
+ TEST_TOP="$SCRIPT_DIR"
+ INTERNAL_BIN="$TEST_TOP"
+fi
+if ! [ -x "$TOP/btrfs" ]; then
+ echo "ERROR: cannot execute btrfs from TOP=$TOP"
+ exit 1
+fi
TEST_DEV=${TEST_DEV:-}
-RESULTS="$TOP/tests/convert-tests-results.txt"
-IMAGE="$TOP/tests/test.img"
+RESULTS="$TEST_TOP/convert-tests-results.txt"
+IMAGE="$TEST_TOP/test.img"
-source "$TOP/tests/common"
-source "$TOP/tests/common.convert"
+source "$TEST_TOP/common"
+source "$TEST_TOP/common.convert"
+export INTERNAL_BIN
+export TEST_TOP
export TOP
export RESULTS
export LANG
@@ -54,7 +76,7 @@ run_one_test() {
}
# Test special images
-for i in $(find "$TOP/tests/convert-tests" -maxdepth 1 -mindepth 1 -type d \
+for i in $(find "$TEST_TOP/convert-tests" -maxdepth 1 -mindepth 1 -type d \
${TEST:+-name "$TEST"} | sort)
do
run_one_test "$i"
diff --git a/tests/convert-tests/001-ext2-basic/test.sh b/tests/convert-tests/001-ext2-basic/test.sh
index af75d948..74cc74e8 100755
--- a/tests/convert-tests/001-ext2-basic/test.sh
+++ b/tests/convert-tests/001-ext2-basic/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
-source "$TOP/tests/common"
-source "$TOP/tests/common.convert"
+source "$TEST_TOP/common"
+source "$TEST_TOP/common.convert"
setup_root_helper
prepare_test_dev
diff --git a/tests/convert-tests/002-ext3-basic/test.sh b/tests/convert-tests/002-ext3-basic/test.sh
index 233e2d94..f0869897 100755
--- a/tests/convert-tests/002-ext3-basic/test.sh
+++ b/tests/convert-tests/002-ext3-basic/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
-source "$TOP/tests/common"
-source "$TOP/tests/common.convert"
+source "$TEST_TOP/common"
+source "$TEST_TOP/common.convert"
setup_root_helper
prepare_test_dev
diff --git a/tests/convert-tests/003-ext4-basic/test.sh b/tests/convert-tests/003-ext4-basic/test.sh
index baf6115c..c5caf67c 100755
--- a/tests/convert-tests/003-ext4-basic/test.sh
+++ b/tests/convert-tests/003-ext4-basic/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
-source "$TOP/tests/common"
-source "$TOP/tests/common.convert"
+source "$TEST_TOP/common"
+source "$TEST_TOP/common.convert"
setup_root_helper
prepare_test_dev
diff --git a/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh b/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh
index cf354d40..dcb9772b 100755
--- a/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh
+++ b/tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh
@@ -10,7 +10,7 @@
# 4) Overlap file extents
# 5) Unable to rollback
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs-convert
check_prereq btrfs
diff --git a/tests/convert-tests/005-delete-all-rollback/test.sh b/tests/convert-tests/005-delete-all-rollback/test.sh
index 31fa2c4b..a5f9d594 100755
--- a/tests/convert-tests/005-delete-all-rollback/test.sh
+++ b/tests/convert-tests/005-delete-all-rollback/test.sh
@@ -2,8 +2,8 @@
# 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"
+source "$TEST_TOP/common"
+source "$TEST_TOP/common.convert"
setup_root_helper
prepare_test_dev
diff --git a/tests/convert-tests/006-large-hole-extent/test.sh b/tests/convert-tests/006-large-hole-extent/test.sh
index 38e97055..a37fcbdc 100755
--- a/tests/convert-tests/006-large-hole-extent/test.sh
+++ b/tests/convert-tests/006-large-hole-extent/test.sh
@@ -5,8 +5,8 @@
# Fast pinpoint regression test. No options combination nor checksum
# verification
-source "$TOP/tests/common"
-source "$TOP/tests/common.convert"
+source "$TEST_TOP/common"
+source "$TEST_TOP/common.convert"
setup_root_helper
prepare_test_dev
diff --git a/tests/convert-tests/007-unsupported-block-sizes/test.sh b/tests/convert-tests/007-unsupported-block-sizes/test.sh
index ef010202..9fda5add 100755
--- a/tests/convert-tests/007-unsupported-block-sizes/test.sh
+++ b/tests/convert-tests/007-unsupported-block-sizes/test.sh
@@ -1,8 +1,8 @@
#!/bin/bash
# Check if block sizes smaller than 4k expectedly fail to convert
-source "$TOP/tests/common"
-source "$TOP/tests/common.convert"
+source "$TEST_TOP/common"
+source "$TEST_TOP/common.convert"
setup_root_helper
prepare_test_dev
diff --git a/tests/convert-tests/008-readonly-image/test.sh b/tests/convert-tests/008-readonly-image/test.sh
index 064bc271..1a65ea6b 100755
--- a/tests/convert-tests/008-readonly-image/test.sh
+++ b/tests/convert-tests/008-readonly-image/test.sh
@@ -1,8 +1,8 @@
#!/bin/bash
# Check if the converted ext2 image is readonly
-source "$TOP/tests/common"
-source "$TOP/tests/common.convert"
+source "$TEST_TOP/common"
+source "$TEST_TOP/common.convert"
setup_root_helper
prepare_test_dev
diff --git a/tests/convert-tests/009-common-inode-flags/test.sh b/tests/convert-tests/009-common-inode-flags/test.sh
index 6d159993..428213bf 100755
--- a/tests/convert-tests/009-common-inode-flags/test.sh
+++ b/tests/convert-tests/009-common-inode-flags/test.sh
@@ -1,8 +1,8 @@
#!/bin/bash
# Check if btrfs-convert can copy common inode flags like SYNC/IMMUTABLE
-source "$TOP/tests/common"
-source "$TOP/tests/common.convert"
+source "$TEST_TOP/common"
+source "$TEST_TOP/common.convert"
setup_root_helper
prepare_test_dev
diff --git a/tests/convert-tests/010-reiserfs-basic/test.sh b/tests/convert-tests/010-reiserfs-basic/test.sh
index 87008f15..73652991 100755
--- a/tests/convert-tests/010-reiserfs-basic/test.sh
+++ b/tests/convert-tests/010-reiserfs-basic/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
-source "$TOP/tests/common"
-source "$TOP/tests/common.convert"
+source "$TEST_TOP/common"
+source "$TEST_TOP/common.convert"
if ! check_kernel_support_reiserfs >/dev/null; then
_not_run "no reiserfs support"
diff --git a/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh b/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh
index 0b8366c8..28877e14 100755
--- a/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh
+++ b/tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh
@@ -1,8 +1,8 @@
#!/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"
+source "$TEST_TOP/common"
+source "$TEST_TOP/common.convert"
if ! check_kernel_support_reiserfs >/dev/null; then
_not_run "no reiserfs support"
diff --git a/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh b/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh
index dde1b3eb..d492779a 100755
--- a/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh
+++ b/tests/convert-tests/012-reiserfs-large-hole-extent/test.sh
@@ -5,8 +5,8 @@
# Fast pinpoint regression test. No options combination nor checksum
# verification
-source "$TOP/tests/common"
-source "$TOP/tests/common.convert"
+source "$TEST_TOP/common"
+source "$TEST_TOP/common.convert"
if ! check_kernel_support_reiserfs >/dev/null; then
_not_run "no reiserfs support"
diff --git a/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh b/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh
index a15240ce..521e8bd4 100755
--- a/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh
+++ b/tests/convert-tests/013-reiserfs-common-inode-flags/test.sh
@@ -1,8 +1,8 @@
#!/bin/bash
# Check if btrfs-convert can copy common inode flags like SYNC/IMMUTABLE
-source "$TOP/tests/common"
-source "$TOP/tests/common.convert"
+source "$TEST_TOP/common"
+source "$TEST_TOP/common.convert"
if ! check_kernel_support_reiserfs >/dev/null; then
_not_run "no reiserfs support"
diff --git a/tests/convert-tests/014-reiserfs-tail-handling/test.sh b/tests/convert-tests/014-reiserfs-tail-handling/test.sh
index 335c0091..5714dc6c 100755
--- a/tests/convert-tests/014-reiserfs-tail-handling/test.sh
+++ b/tests/convert-tests/014-reiserfs-tail-handling/test.sh
@@ -6,8 +6,8 @@
# 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"
+source "$TEST_TOP/common"
+source "$TEST_TOP/common.convert"
if ! check_kernel_support_reiserfs >/dev/null; then
_not_run "no reiserfs support"
diff --git a/tests/convert-tests/015-no-rollback-after-balance/test.sh b/tests/convert-tests/015-no-rollback-after-balance/test.sh
index 47c9c6fa..2f6407f3 100755
--- a/tests/convert-tests/015-no-rollback-after-balance/test.sh
+++ b/tests/convert-tests/015-no-rollback-after-balance/test.sh
@@ -2,8 +2,8 @@
# Check if btrfs-convert refuses to rollback the filesystem, and leave the fs
# and the convert image untouched
-source "$TOP/tests/common"
-source "$TOP/tests/common.convert"
+source "$TEST_TOP/common"
+source "$TEST_TOP/common.convert"
setup_root_helper
prepare_test_dev
diff --git a/tests/export-testsuite.sh b/tests/export-testsuite.sh
new file mode 100755
index 00000000..31b6ecf4
--- /dev/null
+++ b/tests/export-testsuite.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+# export the testsuite files to a separate tar
+
+if ! [ -f testsuite-files ]; then
+ echo "ERROR: cannot find testsuite-files"
+ exit 1
+fi
+
+set -e
+
+TESTSUITE_TAR="btrfs-progs-tests.tar.gz"
+rm -f "$TESTSUITE_TAR"
+
+TIMESTAMP=`date -u "+%Y-%m-%d %T %Z"`
+
+{
+ echo "VERSION=`cat ../VERSION`"
+ echo "GIT_VERSION=`git describe`"
+ echo "TIMESTAMP='$TIMESTAMP'"
+} > testsuite-id
+
+# Due to potentially unwanted files in the testsuite (restored images or other
+# temporary files) we can't simply copy everything so the tar
+#
+# The testsuite-files specifier:
+# F file
+# - directly copy the file from the given path, may be a git tracked file or
+# a built binary
+# G path
+# - a path relative to the top of git, recursively traversed; path
+# postprocessing is needed so the tar gets it relative to tests/
+while read t f; do
+ case "$t" in
+ F) echo "$f";;
+ G)
+ here=`pwd`
+ cd ..
+ git ls-tree -r --name-only --full-name HEAD "$f" |
+ sed -e 's#^tests/##' |
+ sed -e 's#^Documentation#../Documentation#'
+ cd "$here"
+ ;;
+ esac
+done < testsuite-files > testsuite-files-all
+
+echo "create tar: $TESTSUITE_TAR"
+tar cz --sparse -f "$TESTSUITE_TAR" -T testsuite-files-all
+if [ $? -eq 0 ]; then
+ echo "tar created successfully"
+ cat testsuite-id
+ rm -f testsuite-files-all
+ rm -f testsuite-id
+else
+ exit $?
+fi
diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh
index 15d26c70..14287bbe 100755
--- a/tests/fsck-tests.sh
+++ b/tests/fsck-tests.sh
@@ -4,13 +4,35 @@
LANG=C
SCRIPT_DIR=$(dirname $(readlink -f "$0"))
-TOP=$(readlink -f "$SCRIPT_DIR/../")
+if [ -z "$TOP" ]; then
+ TOP=$(readlink -f "$SCRIPT_DIR/../")
+ if [ -f "$TOP/configure.ac" ]; then
+ # inside git
+ TEST_TOP="$TOP/tests/"
+ INTERNAL_BIN="$TOP"
+ else
+ # external, defaults to system binaries
+ TOP=$(dirname `which btrfs`)
+ TEST_TOP="$SCRIPT_DIR"
+ INTERNAL_BIN="$TEST_TOP"
+ fi
+else
+ # assume external, TOP set from commandline
+ TEST_TOP="$SCRIPT_DIR"
+ INTERNAL_BIN="$TEST_TOP"
+fi
+if ! [ -x "$TOP/btrfs" ]; then
+ echo "ERROR: cannot execute btrfs from TOP=$TOP"
+ exit 1
+fi
TEST_DEV=${TEST_DEV:-}
-RESULTS="$TOP/tests/fsck-tests-results.txt"
-IMAGE="$TOP/tests/test.img"
+RESULTS="$TEST_TOP/fsck-tests-results.txt"
+IMAGE="$TEST_TOP/test.img"
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
+export INTERNAL_BIN
+export TEST_TOP
export TOP
export RESULTS
export LANG
@@ -46,7 +68,7 @@ run_one_test() {
# Type 1
check_all_images
fi
- cd "$TOP"
+ cd "$TEST_TOP"
}
# Each dir contains one type of error for btrfsck test.
@@ -62,7 +84,7 @@ run_one_test() {
# This is for case btrfs-image can't dump or case needs extra
# check/verify
-for i in $(find "$TOP/tests/fsck-tests" -maxdepth 1 -mindepth 1 -type d \
+for i in $(find "$TEST_TOP/fsck-tests" -maxdepth 1 -mindepth 1 -type d \
${TEST:+-name "$TEST"} | sort)
do
run_one_test "$i"
diff --git a/tests/fsck-tests/006-bad-root-items/test.sh b/tests/fsck-tests/006-bad-root-items/test.sh
index bf3ef781..2cbf67a8 100755
--- a/tests/fsck-tests/006-bad-root-items/test.sh
+++ b/tests/fsck-tests/006-bad-root-items/test.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs
diff --git a/tests/fsck-tests/012-leaf-corruption/test.sh b/tests/fsck-tests/012-leaf-corruption/test.sh
index fc10a4ff..68d9f695 100755
--- a/tests/fsck-tests/012-leaf-corruption/test.sh
+++ b/tests/fsck-tests/012-leaf-corruption/test.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs-image
diff --git a/tests/fsck-tests/013-extent-tree-rebuild/test.sh b/tests/fsck-tests/013-extent-tree-rebuild/test.sh
index d71c1b2e..02afdda1 100755
--- a/tests/fsck-tests/013-extent-tree-rebuild/test.sh
+++ b/tests/fsck-tests/013-extent-tree-rebuild/test.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs-corrupt-block
check_prereq mkfs.btrfs
@@ -31,7 +31,7 @@ test_extent_tree_rebuild()
fi
# corrupt extent root node block
- run_check $SUDO_HELPER "$TOP/btrfs-corrupt-block" -l "$extent_root_bytenr" \
+ run_check $SUDO_HELPER "$INTERNAL_BIN/btrfs-corrupt-block" -l "$extent_root_bytenr" \
-b 4096 "$TEST_DEV"
$SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" >& /dev/null && \
diff --git a/tests/fsck-tests/027-tree-reloc-tree/test.sh b/tests/fsck-tests/015-tree-reloc-tree/test.sh
index afad1e8d..afad1e8d 100755
--- a/tests/fsck-tests/027-tree-reloc-tree/test.sh
+++ b/tests/fsck-tests/015-tree-reloc-tree/test.sh
diff --git a/tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz b/tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz
index 66d8bde6..66d8bde6 100644
--- a/tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz
+++ b/tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_data_reloc.img.xz
Binary files differ
diff --git a/tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz b/tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz
index 22af324b..22af324b 100644
--- a/tests/fsck-tests/027-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz
+++ b/tests/fsck-tests/015-tree-reloc-tree/tree_reloc_for_fs_tree.img.xz
Binary files differ
diff --git a/tests/fsck-tests/018-leaf-crossing-stripes/test.sh b/tests/fsck-tests/018-leaf-crossing-stripes/test.sh
index 29eb20b5..2a3f6379 100755
--- a/tests/fsck-tests/018-leaf-crossing-stripes/test.sh
+++ b/tests/fsck-tests/018-leaf-crossing-stripes/test.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs
diff --git a/tests/fsck-tests/019-non-skinny-false-alert/test.sh b/tests/fsck-tests/019-non-skinny-false-alert/test.sh
index 550f2947..32f595da 100755
--- a/tests/fsck-tests/019-non-skinny-false-alert/test.sh
+++ b/tests/fsck-tests/019-non-skinny-false-alert/test.sh
@@ -11,7 +11,7 @@
#
# a buggy check leads to the above messages
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs
diff --git a/tests/fsck-tests/020-extent-ref-cases/test.sh b/tests/fsck-tests/020-extent-ref-cases/test.sh
index 0c4f7848..9cf99a51 100755
--- a/tests/fsck-tests/020-extent-ref-cases/test.sh
+++ b/tests/fsck-tests/020-extent-ref-cases/test.sh
@@ -15,7 +15,7 @@
# the beginning of leaf.
# Which caused false alert for lowmem mode.
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs
diff --git a/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh b/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh
index 5d997e24..e6379f97 100755
--- a/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh
+++ b/tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh
@@ -2,7 +2,7 @@
# confirm whether 'btrfs check' supports check ing of a partially dropped
# snapshot
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs
diff --git a/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh b/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh
index dcdc1b42..615f003d 100755
--- a/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh
+++ b/tests/fsck-tests/022-qgroup-rescan-halfway/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# check whether btrfsck can detect running qgroup rescan
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs
diff --git a/tests/fsck-tests/023-qgroup-stack-overflow/test.sh b/tests/fsck-tests/023-qgroup-stack-overflow/test.sh
index ebb07f36..d7b85f07 100755
--- a/tests/fsck-tests/023-qgroup-stack-overflow/test.sh
+++ b/tests/fsck-tests/023-qgroup-stack-overflow/test.sh
@@ -5,7 +5,7 @@
# Fixed by patch:
# btrfs-progs: Fix stack overflow for checking qgroup on tree reloc tree
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs
diff --git a/tests/fsck-tests/024-clear-space-cache/test.sh b/tests/fsck-tests/024-clear-space-cache/test.sh
index 76ebcb6b..6a3a31ec 100755
--- a/tests/fsck-tests/024-clear-space-cache/test.sh
+++ b/tests/fsck-tests/024-clear-space-cache/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# confirm that clearing space cache works
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs
check_prereq mkfs.btrfs
diff --git a/tests/fsck-tests/025-file-extents/test.sh b/tests/fsck-tests/025-file-extents/test.sh
index ebe8a305..95707596 100755
--- a/tests/fsck-tests/025-file-extents/test.sh
+++ b/tests/fsck-tests/025-file-extents/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# Confirm btrfs check can check file extents without causing false alert
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs
check_prereq mkfs.btrfs
diff --git a/tests/fsck-tests/026-bad-dir-item-name/test.sh b/tests/fsck-tests/026-bad-dir-item-name/test.sh
index a1077a8d..a38bf045 100755
--- a/tests/fsck-tests/026-bad-dir-item-name/test.sh
+++ b/tests/fsck-tests/026-bad-dir-item-name/test.sh
@@ -2,7 +2,7 @@
#
# confirm whether check detects name and hash mismatch in dir_item
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs
diff --git a/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh b/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh
index 6f315fae..4015df2d 100755
--- a/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh
+++ b/tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh
@@ -3,24 +3,23 @@
# An image with mis-aligned superblock total_bytes, that will be found and
# fixed by 'check' or fixed by 'rescue fix-device-size'
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs
-prepare_test_dev
setup_root_helper
check_all_images
-image=$(extract_image "./dev_and_super_mismatch_unaligned.raw.xz")
+TEST_DEV=$(extract_image "./dev_and_super_mismatch_unaligned.raw.xz")
# detect and fix
-run_check "$TOP/btrfs" rescue fix-device-size "$image"
+run_check "$TOP/btrfs" rescue fix-device-size "$TEST_DEV"
# no problem found
-run_check "$TOP/btrfs" rescue fix-device-size "$image"
+run_check "$TOP/btrfs" rescue fix-device-size "$TEST_DEV"
# check if fix-device-size worked
-run_check "$TOP/btrfs" check "$image"
+run_check "$TOP/btrfs" check "$TEST_DEV"
# mount test
run_check_mount_test_dev
-run_check_umount_test_dev
-
-rm -f "$image"
+run_check_umount_test_dev "$TEST_MNT"
+# remove restored image
+rm -- "$TEST_DEV"
diff --git a/tests/fssum.c b/tests/fssum.c
index 5dde9984..2bda5df8 100644
--- a/tests/fssum.c
+++ b/tests/fssum.c
@@ -532,8 +532,8 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
}
ret = lstat64(namelist[i], &st);
if (ret) {
- fprintf(stderr, "stat failed for %s/%s: %s\n",
- path_prefix, path, strerror(errno));
+ fprintf(stderr, "stat failed for %s/%s: %m\n",
+ path_prefix, path);
exit(-1);
}
sum_add_u64(&meta, level);
@@ -557,8 +557,8 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
if (fd == -1 && flags[FLAG_OPEN_ERROR]) {
sum_add_u64(&meta, errno);
} else if (fd == -1) {
- fprintf(stderr, "open failed for %s/%s: %s\n",
- path_prefix, path, strerror(errno));
+ fprintf(stderr, "open failed for %s/%s: %m\n",
+ path_prefix, path);
exit(-1);
} else {
sum(fd, level + 1, &cs, path_prefix, path);
@@ -575,9 +575,8 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
sum_add_u64(&meta, errno);
} else if (fd == -1) {
fprintf(stderr,
- "open failed for %s/%s: %s\n",
- path_prefix, path,
- strerror(errno));
+ "open failed for %s/%s: %m\n",
+ path_prefix, path);
exit(-1);
}
if (fd != -1) {
@@ -585,9 +584,8 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
if (ret < 0) {
fprintf(stderr,
"read failed for "
- "%s/%s: %s\n",
- path_prefix, path,
- strerror(errno));
+ "%s/%s: %m\n",
+ path_prefix, path);
exit(-1);
}
close(fd);
@@ -693,8 +691,7 @@ main(int argc, char *argv[])
out_fp = fopen(optarg, "w");
if (!out_fp) {
fprintf(stderr,
- "failed to open output file: %s\n",
- strerror(errno));
+ "failed to open output file: %m\n");
exit(-1);
}
break;
@@ -702,8 +699,7 @@ main(int argc, char *argv[])
in_fp = fopen(optarg, "r");
if (!in_fp) {
fprintf(stderr,
- "failed to open input file: %s\n",
- strerror(errno));
+ "failed to open input file: %m\n");
exit(-1);
}
break;
@@ -788,8 +784,7 @@ main(int argc, char *argv[])
fd = open(path, O_RDONLY);
if (fd == -1) {
- fprintf(stderr, "failed to open %s: %s\n", path,
- strerror(errno));
+ fprintf(stderr, "failed to open %s: %m\n", path);
exit(-1);
}
diff --git a/tests/fuzz-tests.sh b/tests/fuzz-tests.sh
index f72385e5..7bc620f0 100755
--- a/tests/fuzz-tests.sh
+++ b/tests/fuzz-tests.sh
@@ -4,13 +4,35 @@
LANG=C
SCRIPT_DIR=$(dirname $(readlink -f "$0"))
-TOP=$(readlink -f "$SCRIPT_DIR/../")
+if [ -z "$TOP" ]; then
+ TOP=$(readlink -f "$SCRIPT_DIR/../")
+ if [ -f "$TOP/configure.ac" ]; then
+ # inside git
+ TEST_TOP="$TOP/tests/"
+ INTERNAL_BIN="$TOP"
+ else
+ # external, defaults to system binaries
+ TOP=$(dirname `which btrfs`)
+ TEST_TOP="$SCRIPT_DIR"
+ INTERNAL_BIN="$TEST_TOP"
+ fi
+else
+ # assume external, TOP set from commandline
+ TEST_TOP="$SCRIPT_DIR"
+ INTERNAL_BIN="$TEST_TOP"
+fi
+if ! [ -x "$TOP/btrfs" ]; then
+ echo "ERROR: cannot execute btrfs from TOP=$TOP"
+ exit 1
+fi
TEST_DEV=${TEST_DEV:-}
-RESULTS="$TOP/tests/fuzz-tests-results.txt"
-IMAGE="$TOP/tests/test.img"
+RESULTS="$TEST_TOP/fuzz-tests-results.txt"
+IMAGE="$TEST_TOP/test.img"
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
+export INTERNAL_BIN
+export TEST_TOP
export TOP
export RESULTS
export LANG
@@ -23,7 +45,7 @@ check_prereq btrfs
# The tests are driven by their custom script called 'test.sh'
-for i in $(find "$TOP/tests/fuzz-tests" -maxdepth 1 -mindepth 1 -type d \
+for i in $(find "$TEST_TOP/fuzz-tests" -maxdepth 1 -mindepth 1 -type d \
${TEST:+-name "$TEST"} | sort)
do
name=$(basename "$i")
@@ -39,5 +61,5 @@ do
_fail "test failed for case $(basename $i)"
fi
fi
- cd "$TOP"
+ cd "$TEST_TOP"
done
diff --git a/tests/fuzz-tests/001-simple-check-unmounted/test.sh b/tests/fuzz-tests/001-simple-check-unmounted/test.sh
index 98fe7b0c..905d37b7 100755
--- a/tests/fuzz-tests/001-simple-check-unmounted/test.sh
+++ b/tests/fuzz-tests/001-simple-check-unmounted/test.sh
@@ -2,7 +2,7 @@
# iterate over all fuzzed images and run 'btrfs check'
-source $TOP/tests/common
+source "$TEST_TOP/common"
setup_root_helper
check_prereq btrfs
@@ -15,6 +15,6 @@ check_image() {
run_mayfail $TOP/btrfs check "$image"
}
-check_all_images $TOP/tests/fuzz-tests/images
+check_all_images $TEST_TOP/fuzz-tests/images
exit 0
diff --git a/tests/fuzz-tests/002-simple-image/test.sh b/tests/fuzz-tests/002-simple-image/test.sh
index 42470ecc..034fcf46 100755
--- a/tests/fuzz-tests/002-simple-image/test.sh
+++ b/tests/fuzz-tests/002-simple-image/test.sh
@@ -2,7 +2,7 @@
# iterate over all fuzzed images and run 'btrfs-image'
-source $TOP/tests/common
+source "$TEST_TOP/common"
setup_root_helper
check_prereq btrfs-image
@@ -17,7 +17,7 @@ check_image() {
truncate -s0 target
}
-check_all_images $TOP/tests/fuzz-tests/images
+check_all_images $TEST_TOP/fuzz-tests/images
rm -- target
diff --git a/tests/fuzz-tests/003-multi-check-unmounted/test.sh b/tests/fuzz-tests/003-multi-check-unmounted/test.sh
index 9fd7b8aa..35dfe4fc 100755
--- a/tests/fuzz-tests/003-multi-check-unmounted/test.sh
+++ b/tests/fuzz-tests/003-multi-check-unmounted/test.sh
@@ -3,7 +3,7 @@
# iterate over all fuzzed images and run 'btrfs check', try various options to
# get more code coverage
-source $TOP/tests/common
+source "$TEST_TOP/common"
setup_root_helper
check_prereq btrfs
@@ -21,6 +21,6 @@ check_image() {
run_mayfail $TOP/btrfs check --repair "$image"
}
-check_all_images $TOP/tests/fuzz-tests/images
+check_all_images $TEST_TOP/fuzz-tests/images
exit 0
diff --git a/tests/fuzz-tests/004-simple-dump-tree/test.sh b/tests/fuzz-tests/004-simple-dump-tree/test.sh
index 89ff214c..6c9e8c45 100755
--- a/tests/fuzz-tests/004-simple-dump-tree/test.sh
+++ b/tests/fuzz-tests/004-simple-dump-tree/test.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-source $TOP/tests/common
+source "$TEST_TOP/common"
setup_root_helper
check_prereq btrfs
@@ -13,6 +13,6 @@ check_image() {
run_mayfail $TOP/btrfs inspect-internal dump-tree "$image"
}
-check_all_images $TOP/tests/fuzz-tests/images
+check_all_images $TEST_TOP/fuzz-tests/images
exit 0
diff --git a/tests/fuzz-tests/005-simple-dump-super/test.sh b/tests/fuzz-tests/005-simple-dump-super/test.sh
index fbce3d9f..01c7b628 100755
--- a/tests/fuzz-tests/005-simple-dump-super/test.sh
+++ b/tests/fuzz-tests/005-simple-dump-super/test.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-source $TOP/tests/common
+source "$TEST_TOP/common"
setup_root_helper
check_prereq btrfs
@@ -14,6 +14,6 @@ check_image() {
run_mayfail $TOP/btrfs inspect-internal dump-super -Ffa "$image"
}
-check_all_images $TOP/tests/fuzz-tests/images
+check_all_images $TEST_TOP/fuzz-tests/images
exit 0
diff --git a/tests/fuzz-tests/006-simple-tree-stats/test.sh b/tests/fuzz-tests/006-simple-tree-stats/test.sh
index c3410b06..dbed471a 100755
--- a/tests/fuzz-tests/006-simple-tree-stats/test.sh
+++ b/tests/fuzz-tests/006-simple-tree-stats/test.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-source $TOP/tests/common
+source "$TEST_TOP/common"
setup_root_helper
check_prereq btrfs
@@ -13,6 +13,6 @@ check_image() {
run_mayfail $TOP/btrfs inspect-internal tree-stats "$image"
}
-check_all_images $TOP/tests/fuzz-tests/images
+check_all_images $TEST_TOP/fuzz-tests/images
exit 0
diff --git a/tests/fuzz-tests/007-simple-super-recover/test.sh b/tests/fuzz-tests/007-simple-super-recover/test.sh
index 885cb352..ceb16348 100755
--- a/tests/fuzz-tests/007-simple-super-recover/test.sh
+++ b/tests/fuzz-tests/007-simple-super-recover/test.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-source $TOP/tests/common
+source "$TEST_TOP/common"
setup_root_helper
check_prereq btrfs
@@ -15,6 +15,6 @@ check_image() {
rm -- "$image".scratch
}
-check_all_images $TOP/tests/fuzz-tests/images
+check_all_images $TEST_TOP/fuzz-tests/images
exit 0
diff --git a/tests/fuzz-tests/008-simple-chunk-recover/test.sh b/tests/fuzz-tests/008-simple-chunk-recover/test.sh
index d53453f6..198f88e2 100755
--- a/tests/fuzz-tests/008-simple-chunk-recover/test.sh
+++ b/tests/fuzz-tests/008-simple-chunk-recover/test.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-source $TOP/tests/common
+source "$TEST_TOP/common"
setup_root_helper
check_prereq btrfs
@@ -15,6 +15,6 @@ check_image() {
rm -- "$image".scratch
}
-check_all_images $TOP/tests/fuzz-tests/images
+check_all_images $TEST_TOP/fuzz-tests/images
exit 0
diff --git a/tests/fuzz-tests/009-simple-zero-log/test.sh b/tests/fuzz-tests/009-simple-zero-log/test.sh
index 393db3f6..928c66b1 100755
--- a/tests/fuzz-tests/009-simple-zero-log/test.sh
+++ b/tests/fuzz-tests/009-simple-zero-log/test.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-source $TOP/tests/common
+source "$TEST_TOP/common"
setup_root_helper
check_prereq btrfs
@@ -15,6 +15,6 @@ check_image() {
rm -- "$image".scratch
}
-check_all_images $TOP/tests/fuzz-tests/images
+check_all_images $TEST_TOP/fuzz-tests/images
exit 0
diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh
index 08988016..94703a3e 100755
--- a/tests/misc-tests.sh
+++ b/tests/misc-tests.sh
@@ -4,18 +4,40 @@
LANG=C
SCRIPT_DIR=$(dirname $(readlink -f "$0"))
-TOP=$(readlink -f "$SCRIPT_DIR/../")
+if [ -z "$TOP" ]; then
+ TOP=$(readlink -f "$SCRIPT_DIR/../")
+ if [ -f "$TOP/configure.ac" ]; then
+ # inside git
+ TEST_TOP="$TOP/tests/"
+ INTERNAL_BIN="$TOP"
+ else
+ # external, defaults to system binaries
+ TOP=$(dirname `which btrfs`)
+ TEST_TOP="$SCRIPT_DIR"
+ INTERNAL_BIN="$TEST_TOP"
+ fi
+else
+ # assume external, TOP set from commandline
+ TEST_TOP="$SCRIPT_DIR"
+ INTERNAL_BIN="$TEST_TOP"
+fi
+if ! [ -x "$TOP/btrfs" ]; then
+ echo "ERROR: cannot execute btrfs from TOP=$TOP"
+ exit 1
+fi
TEST_DEV=${TEST_DEV:-}
-RESULTS="$TOP/tests/misc-tests-results.txt"
-IMAGE="$TOP/tests/test.img"
+RESULTS="$TEST_TOP/misc-tests-results.txt"
+IMAGE="$TEST_TOP/test.img"
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
+export INTERNAL_BIN
+export TEST_TOP
export TOP
export RESULTS
export LANG
-export TEST_DEV
export IMAGE
+export TEST_DEV
rm -f "$RESULTS"
@@ -31,7 +53,7 @@ check_kernel_support
# The tests are driven by their custom script called 'test.sh'
-for i in $(find "$TOP/tests/misc-tests" -maxdepth 1 -mindepth 1 -type d \
+for i in $(find "$TEST_TOP/misc-tests" -maxdepth 1 -mindepth 1 -type d \
${TEST:+-name "$TEST"} | sort)
do
echo " [TEST/misc] $(basename $i)"
@@ -46,5 +68,5 @@ do
_fail "test failed for case $(basename $i)"
fi
fi
- cd "$TOP"
+ cd "$TEST_TOP"
done
diff --git a/tests/misc-tests/001-btrfstune-features/test.sh b/tests/misc-tests/001-btrfstune-features/test.sh
index bfa7f43e..718e4b08 100755
--- a/tests/misc-tests/001-btrfstune-features/test.sh
+++ b/tests/misc-tests/001-btrfstune-features/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# test btrfstune options that enable filesystem features
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfstune
diff --git a/tests/misc-tests/002-uuid-rewrite/test.sh b/tests/misc-tests/002-uuid-rewrite/test.sh
index fd100fb3..e32aff0c 100755
--- a/tests/misc-tests/002-uuid-rewrite/test.sh
+++ b/tests/misc-tests/002-uuid-rewrite/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# test btrfstune uuid rewriting options
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfstune
@@ -25,7 +25,7 @@ test_uuid_random()
run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \
--uuid $origuuid \
- --rootdir $TOP/Documentation \
+ --rootdir $INTERNAL_BIN/Documentation \
$TEST_DEV
run_check $TOP/btrfs inspect-internal dump-super "$TEST_DEV"
currentfsid=$(run_check_stdout $TOP/btrfstune -f -u $TEST_DEV | \
@@ -47,7 +47,7 @@ test_uuid_user()
run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \
--uuid $origuuid \
- --rootdir $TOP/Documentation \
+ --rootdir $INTERNAL_BIN/Documentation \
$TEST_DEV
run_check $TOP/btrfs inspect-internal dump-super "$TEST_DEV"
run_check $TOP/btrfstune -f -U $newuuid \
diff --git a/tests/misc-tests/003-zero-log/test.sh b/tests/misc-tests/003-zero-log/test.sh
index e7c5c806..9d2940f5 100755
--- a/tests/misc-tests/003-zero-log/test.sh
+++ b/tests/misc-tests/003-zero-log/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# test zero-log
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
@@ -27,7 +27,7 @@ test_zero_log()
{
# FIXME: we need an image with existing log_root
run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \
- --rootdir $TOP/Documentation \
+ --rootdir $INTERNAL_BIN/Documentation \
$TEST_DEV
run_check $TOP/btrfs inspect-internal dump-super $TEST_DEV
if [ "$1" = 'standalone' ]; then
diff --git a/tests/misc-tests/004-shrink-fs/test.sh b/tests/misc-tests/004-shrink-fs/test.sh
index 88740358..2f08b0b0 100755
--- a/tests/misc-tests/004-shrink-fs/test.sh
+++ b/tests/misc-tests/004-shrink-fs/test.sh
@@ -4,7 +4,7 @@
# are able to resize (shrink) it to that size.
#
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/misc-tests/005-convert-progress-thread-crash/test.sh b/tests/misc-tests/005-convert-progress-thread-crash/test.sh
index bc71e1fd..b8012c9f 100755
--- a/tests/misc-tests/005-convert-progress-thread-crash/test.sh
+++ b/tests/misc-tests/005-convert-progress-thread-crash/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# test convert-thread-conflict
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq btrfs-convert
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 2766fb17..d8b1cef2 100755
--- a/tests/misc-tests/006-image-on-missing-device/test.sh
+++ b/tests/misc-tests/006-image-on-missing-device/test.sh
@@ -4,7 +4,7 @@
# - btrfs-image must not loop indefinetelly
# - btrfs-image will expectedly fail to produce the dump
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq btrfs-image
check_prereq mkfs.btrfs
diff --git a/tests/misc-tests/007-subvolume-sync/test.sh b/tests/misc-tests/007-subvolume-sync/test.sh
index 243bb8cc..ef03d16b 100755
--- a/tests/misc-tests/007-subvolume-sync/test.sh
+++ b/tests/misc-tests/007-subvolume-sync/test.sh
@@ -4,7 +4,7 @@
# - btrfs subvolume must not loop indefinitely
# - btrfs subvolume return 0 in normal case
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/misc-tests/008-leaf-crossing-stripes/test.sh b/tests/misc-tests/008-leaf-crossing-stripes/test.sh
index 03818062..517bd667 100755
--- a/tests/misc-tests/008-leaf-crossing-stripes/test.sh
+++ b/tests/misc-tests/008-leaf-crossing-stripes/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# test if btrfs-convert creates a filesystem without leaf crossing stripes
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq btrfs-convert
check_prereq btrfs
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 fa3f09ab..15de3355 100755
--- a/tests/misc-tests/009-subvolume-sync-must-wait/test.sh
+++ b/tests/misc-tests/009-subvolume-sync-must-wait/test.sh
@@ -2,7 +2,7 @@
#
# Verify that subvolume sync waits until the subvolume is cleaned
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh b/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh
index 7915867c..6d510fea 100755
--- a/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh
+++ b/tests/misc-tests/010-convert-delete-ext2-subvol/test.sh
@@ -3,7 +3,7 @@
# verify that convert rollback finds the ext2_subvolume intact and fails if it
# was partially deleted
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq btrfs-convert
check_prereq btrfs
diff --git a/tests/misc-tests/011-delete-missing-device/test.sh b/tests/misc-tests/011-delete-missing-device/test.sh
index 8a1b14b1..469c3be9 100755
--- a/tests/misc-tests/011-delete-missing-device/test.sh
+++ b/tests/misc-tests/011-delete-missing-device/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# make sure that 'missing' is accepted for device deletion
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/misc-tests/012-find-root-no-result/test.sh b/tests/misc-tests/012-find-root-no-result/test.sh
index 983a8a1e..f4a57e76 100755
--- a/tests/misc-tests/012-find-root-no-result/test.sh
+++ b/tests/misc-tests/012-find-root-no-result/test.sh
@@ -3,7 +3,7 @@
# recent fs or balanced fs, whose metadata chunk is the first chunk
# and the only metadata chunk
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq btrfs-find-root
check_prereq btrfs-image
diff --git a/tests/misc-tests/013-subvolume-sync-crash/test.sh b/tests/misc-tests/013-subvolume-sync-crash/test.sh
index cd445961..051b457a 100755
--- a/tests/misc-tests/013-subvolume-sync-crash/test.sh
+++ b/tests/misc-tests/013-subvolume-sync-crash/test.sh
@@ -3,7 +3,7 @@
# Verify that subvolume sync waits until the subvolume is cleaned and does not
# crash at the end
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/misc-tests/014-filesystem-label/test.sh b/tests/misc-tests/014-filesystem-label/test.sh
index 753aa9ea..bd6773cb 100755
--- a/tests/misc-tests/014-filesystem-label/test.sh
+++ b/tests/misc-tests/014-filesystem-label/test.sh
@@ -2,7 +2,7 @@
#
# test label settings
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/misc-tests/015-dump-super-garbage/test.sh b/tests/misc-tests/015-dump-super-garbage/test.sh
index 33fc8332..10d8d5b6 100755
--- a/tests/misc-tests/015-dump-super-garbage/test.sh
+++ b/tests/misc-tests/015-dump-super-garbage/test.sh
@@ -2,7 +2,7 @@
#
# let dump-super dump random data, must not crash
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq btrfs
diff --git a/tests/misc-tests/016-send-clone-src/test.sh b/tests/misc-tests/016-send-clone-src/test.sh
index 2780ebbd..e4fa16a7 100755
--- a/tests/misc-tests/016-send-clone-src/test.sh
+++ b/tests/misc-tests/016-send-clone-src/test.sh
@@ -3,7 +3,7 @@
# test for sending stream size of clone-src option, compare against a send
# stream generated by buggy version
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/misc-tests/017-recv-stream-malformatted/test.sh b/tests/misc-tests/017-recv-stream-malformatted/test.sh
index d199a72e..991f2569 100755
--- a/tests/misc-tests/017-recv-stream-malformatted/test.sh
+++ b/tests/misc-tests/017-recv-stream-malformatted/test.sh
@@ -2,7 +2,7 @@
#
# test receiving stream that's not valid, simple cases
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/misc-tests/018-recv-end-of-stream/test.sh b/tests/misc-tests/018-recv-end-of-stream/test.sh
index 9ca035f7..79e735ea 100755
--- a/tests/misc-tests/018-recv-end-of-stream/test.sh
+++ b/tests/misc-tests/018-recv-end-of-stream/test.sh
@@ -3,7 +3,7 @@
# end of stream conditions: test that no instructions in a stream are still
# received, at least the header must be present
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/misc-tests/019-receive-clones-on-mounted-subvol/test.sh b/tests/misc-tests/019-receive-clones-on-mounted-subvol/test.sh
index 182b0cf9..60ec5cf9 100755
--- a/tests/misc-tests/019-receive-clones-on-mounted-subvol/test.sh
+++ b/tests/misc-tests/019-receive-clones-on-mounted-subvol/test.sh
@@ -5,7 +5,7 @@
# have an entry with the same name that corresponds to different inodes in each
# snapshot.
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
@@ -14,7 +14,7 @@ check_prereq fssum
setup_root_helper
prepare_test_dev
-FSSUM_PROG="$TOP/fssum"
+FSSUM_PROG="$INTERNAL_BIN/fssum"
srcdir=./send-test-dir
rm -rf "$srcdir"
mkdir -p "$srcdir"
diff --git a/tests/misc-tests/020-fix-superblock-corruption/test.sh b/tests/misc-tests/020-fix-superblock-corruption/test.sh
index 77c1a5aa..8f3d20fe 100755
--- a/tests/misc-tests/020-fix-superblock-corruption/test.sh
+++ b/tests/misc-tests/020-fix-superblock-corruption/test.sh
@@ -2,7 +2,7 @@
#
# Corrupt primary superblock and restore it using backup superblock.
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs-select-super
check_prereq btrfs
diff --git a/tests/misc-tests/021-image-multi-devices/test.sh b/tests/misc-tests/021-image-multi-devices/test.sh
index abf67f90..d78c44fb 100755
--- a/tests/misc-tests/021-image-multi-devices/test.sh
+++ b/tests/misc-tests/021-image-multi-devices/test.sh
@@ -2,7 +2,7 @@
# Test btrfs-image with multiple devices filesystem and verify that restoring
# the created image works against a single device.
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs-image
check_prereq mkfs.btrfs
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
index 72cf076f..54365289 100755
--- a/tests/misc-tests/022-filesystem-du-on-empty-subvol/test.sh
+++ b/tests/misc-tests/022-filesystem-du-on-empty-subvol/test.sh
@@ -2,7 +2,7 @@
#
# btrfs fi du should handle empty subvolumes (with ino == 2)
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
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
index 3c8ba85c..05894cfe 100755
--- a/tests/misc-tests/023-device-usage-with-missing-device/test.sh
+++ b/tests/misc-tests/023-device-usage-with-missing-device/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# check if 'device slack' is reported as zero when a device is missing
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs-image
check_prereq mkfs.btrfs
diff --git a/tests/misc-tests/024-inspect-internal-rootid/test.sh b/tests/misc-tests/024-inspect-internal-rootid/test.sh
index 40e382bb..71e19044 100755
--- a/tests/misc-tests/024-inspect-internal-rootid/test.sh
+++ b/tests/misc-tests/024-inspect-internal-rootid/test.sh
@@ -2,7 +2,7 @@
#
# test commands of inspect-internal rootid
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/misc-tests/025-zstd-compression/test.sh b/tests/misc-tests/025-zstd-compression/test.sh
index e95dcb36..22795d27 100755
--- a/tests/misc-tests/025-zstd-compression/test.sh
+++ b/tests/misc-tests/025-zstd-compression/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# Test zstd compression support on a prebuilt btrfs image
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq btrfs
check_global_prereq md5sum
diff --git a/tests/misc-tests/026-image-non-printable-chars/test.sh b/tests/misc-tests/026-image-non-printable-chars/test.sh
index 8018586f..50441a21 100755
--- a/tests/misc-tests/026-image-non-printable-chars/test.sh
+++ b/tests/misc-tests/026-image-non-printable-chars/test.sh
@@ -2,7 +2,7 @@
# check that sanitized names with matching crc do not contain unprintable
# characters, namely 0x7f
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/misc-tests/027-subvol-list-deleted-toplevel/test.sh b/tests/misc-tests/027-subvol-list-deleted-toplevel/test.sh
index ee41d71f..3b73dd36 100755
--- a/tests/misc-tests/027-subvol-list-deleted-toplevel/test.sh
+++ b/tests/misc-tests/027-subvol-list-deleted-toplevel/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# check that the toplevel subvolume is not listed as regular or deleted
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/misc-tests/028-superblock-recover/test.sh b/tests/misc-tests/028-superblock-recover/test.sh
new file mode 100755
index 00000000..1175e480
--- /dev/null
+++ b/tests/misc-tests/028-superblock-recover/test.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+# Test that any superblock is correctly detected and fixed by btrfs rescue
+
+source "$TOP/tests/common"
+
+check_prereq btrfs
+check_prereq mkfs.btrfs
+check_prereq btrfs-select-super
+
+setup_root_helper
+prepare_test_dev 260G
+
+# Create the test file system.
+run_check $SUDO_HELPER "$TOP"/mkfs.btrfs -f "$TEST_DEV"
+
+function check_corruption {
+ local sb_offset=$1
+ local source_sb=$2
+
+ # First we ensure we can mount it successfully
+ run_check_mount_test_dev
+ run_check_umount_test_dev
+
+ # Now corrupt 1k of the superblock at sb_offset
+ run_check $SUDO_HELPER dd bs=1K count=1 seek=$(($sb_offset + 1)) if=/dev/zero of="$TEST_DEV" conv=notrunc
+
+ # if corrupting one of the sb copies, copy it over the initial superblock
+ if [ ! -z $source_sb ]; then
+ local shift_val=$((16 << $source_sb * 12 ))
+ run_check $SUDO_HELPER dd bs=1K count=4 seek=64 skip=$shift_val if="$TEST_DEV" of="$TEST_DEV" conv=notrunc
+ fi
+
+ # we can't use our mount helper, the following works for file image and
+ # block device as TEST_DEV
+ run_mustfail "mounted fs with corrupted superblock" \
+ $SUDO_HELPER mount "$TEST_DEV" "$TEST_MNT"
+
+ # Now run btrfs rescue which should fix the superblock. It uses 2
+ # to signal success of recovery use mayfail to ignore that retval
+ # but still log the output of the command
+ run_mayfail $SUDO_HELPER "$TOP"/btrfs rescue super-recover -yv "$TEST_DEV"
+ if [ $? != 2 ]; then
+ _fail "couldn't rescue super"
+ fi
+
+ run_check_mount_test_dev
+ run_check_umount_test_dev
+}
+
+# Corrupting first superblock
+check_corruption 64
+
+# Corrupting second superblock
+check_corruption 65536 1
+
+# Corrupting third superblock
+check_corruption 268435456 2
diff --git a/tests/mkfs-tests.sh b/tests/mkfs-tests.sh
index c8ff8c83..2ced4ac9 100755
--- a/tests/mkfs-tests.sh
+++ b/tests/mkfs-tests.sh
@@ -4,13 +4,35 @@
LANG=C
SCRIPT_DIR=$(dirname $(readlink -f "$0"))
-TOP=$(readlink -f "$SCRIPT_DIR/../")
+if [ -z "$TOP" ]; then
+ TOP=$(readlink -f "$SCRIPT_DIR/../")
+ if [ -f "$TOP/configure.ac" ]; then
+ # inside git
+ TEST_TOP="$TOP/tests/"
+ INTERNAL_BIN="$TOP"
+ else
+ # external, defaults to system binaries
+ TOP=$(dirname `which btrfs`)
+ TEST_TOP="$SCRIPT_DIR"
+ INTERNAL_BIN="$TEST_TOP"
+ fi
+else
+ # assume external, TOP set from commandline
+ TEST_TOP="$SCRIPT_DIR"
+ INTERNAL_BIN="$TEST_TOP"
+fi
+if ! [ -x "$TOP/btrfs" ]; then
+ echo "ERROR: cannot execute btrfs from TOP=$TOP"
+ exit 1
+fi
TEST_DEV=${TEST_DEV:-}
-RESULTS="$TOP/tests/mkfs-tests-results.txt"
-IMAGE="$TOP/tests/test.img"
+RESULTS="$TEST_TOP/mkfs-tests-results.txt"
+IMAGE="$TEST_TOP/test.img"
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
+export INTERNAL_BIN
+export TEST_TOP
export TOP
export RESULTS
export LANG
@@ -25,7 +47,7 @@ check_kernel_support
# The tests are driven by their custom script called 'test.sh'
-for i in $(find "$TOP/tests/mkfs-tests" -maxdepth 1 -mindepth 1 -type d \
+for i in $(find "$TEST_TOP/mkfs-tests" -maxdepth 1 -mindepth 1 -type d \
${TEST:+-name "$TEST"} | sort)
do
echo " [TEST/mkfs] $(basename $i)"
@@ -40,5 +62,5 @@ do
_fail "test failed for case $(basename $i)"
fi
fi
- cd "$TOP"
+ cd "$TEST_TOP"
done
diff --git a/tests/mkfs-tests/001-basic-profiles/test.sh b/tests/mkfs-tests/001-basic-profiles/test.sh
index 854ee007..b84016f7 100755
--- a/tests/mkfs-tests/001-basic-profiles/test.sh
+++ b/tests/mkfs-tests/001-basic-profiles/test.sh
@@ -2,7 +2,7 @@
# test various blockgroup profile combinations, use loop devices as block
# devices
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh b/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh
index 37846234..4bc9c262 100755
--- a/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh
+++ b/tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh
@@ -2,7 +2,7 @@
#
# Verify that we do not force mixed block groups on small volumes anymore
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
diff --git a/tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh b/tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh
index 074fc22e..f5327338 100755
--- a/tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh
+++ b/tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh
@@ -2,7 +2,7 @@
#
# Mixed mode needs equal sectorsize and nodesize
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
diff --git a/tests/mkfs-tests/004-rootdir-keeps-size/test.sh b/tests/mkfs-tests/004-rootdir-keeps-size/test.sh
index 7038c8ea..4a84e6db 100755
--- a/tests/mkfs-tests/004-rootdir-keeps-size/test.sh
+++ b/tests/mkfs-tests/004-rootdir-keeps-size/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# make sure that mkfs.btrfs --rootsize does not change size of the image
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
@@ -16,7 +16,7 @@ test_mkfs_with_size() {
run_check truncate -s$size $TEST_DEV
imgsize=$(run_check_stdout stat --format=%s $TEST_DEV)
run_check $SUDO_HELPER $TOP/mkfs.btrfs -f \
- --rootdir $TOP/Documentation \
+ --rootdir $INTERNAL_BIN/Documentation \
$TEST_DEV
tmp=$(run_check_stdout stat --format=%s $TEST_DEV)
if ! [ "$imgsize" = "$tmp" ]; then
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 5bdf50e0..55ce676e 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
@@ -1,7 +1,7 @@
#!/bin/bash
# a long device name must pass the SSD test
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
diff --git a/tests/mkfs-tests/006-partitioned-loopdev/test.sh b/tests/mkfs-tests/006-partitioned-loopdev/test.sh
index 0c77e5cd..06c254fd 100755
--- a/tests/mkfs-tests/006-partitioned-loopdev/test.sh
+++ b/tests/mkfs-tests/006-partitioned-loopdev/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# recognize partitioned loop devices
-source $TOP/tests/common
+source "$TEST_TOP/common"
if ! losetup --help | grep -q 'partscan'; then
_not_run "losetup --partscan not available"
diff --git a/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh b/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh
index 3980414f..f7e88c9a 100755
--- a/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh
+++ b/tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
# iterate over nodesize and sectorsize combinations
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/mkfs-tests/008-sectorsize-nodesize-combination/test.sh b/tests/mkfs-tests/008-sectorsize-nodesize-combination/test.sh
index 955cd2b1..9cc2f9e0 100755
--- a/tests/mkfs-tests/008-sectorsize-nodesize-combination/test.sh
+++ b/tests/mkfs-tests/008-sectorsize-nodesize-combination/test.sh
@@ -4,7 +4,7 @@
# only do mkfs and fsck check, no mounting as
# sub/multi-pagesize is not supported yet
-source $TOP/tests/common
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/mkfs-tests/009-special-files-for-rootdir/test.sh b/tests/mkfs-tests/009-special-files-for-rootdir/test.sh
index d327a0d9..a94d5209 100755
--- a/tests/mkfs-tests/009-special-files-for-rootdir/test.sh
+++ b/tests/mkfs-tests/009-special-files-for-rootdir/test.sh
@@ -6,7 +6,7 @@
#
# Note: sock type is skipped in this test
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
check_prereq mkfs.btrfs
check_prereq btrfs
diff --git a/tests/mkfs-tests/010-minimal-size/test.sh b/tests/mkfs-tests/010-minimal-size/test.sh
new file mode 100755
index 00000000..62f8e16a
--- /dev/null
+++ b/tests/mkfs-tests/010-minimal-size/test.sh
@@ -0,0 +1,63 @@
+#!/bin/bash
+# test if the reported minimal size of mkfs.btrfs is valid
+
+source "$TOP/tests/common"
+
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+setup_root_helper
+
+do_test()
+{
+ # 1M should be small enough to reliably fail, we use the output to get
+ # the minimal device size for the given option combination
+ prepare_test_dev 1M
+ output=$(run_mustfail_stdout "mkfs.btrfs for small image" \
+ "$TOP/mkfs.btrfs" -f $@ "$TEST_DEV")
+ good_size=$(echo "$output" | grep -oP "(?<=is )\d+")
+
+ prepare_test_dev "$good_size"
+ echo "Minimal device size is $good_size" >> "$RESULTS"
+ run_check $TOP/mkfs.btrfs -f $@ "$TEST_DEV"
+ run_check_mount_test_dev
+ run_check_umount_test_dev
+}
+
+do_test -n 4k -m single -d single
+do_test -n 4k -m single -d dup
+do_test -n 4k -m dup -d single
+do_test -n 4k -m dup -d dup
+
+do_test -n 8k -m single -d single
+do_test -n 8k -m single -d dup
+do_test -n 8k -m dup -d single
+do_test -n 8k -m dup -d dup
+
+do_test -n 16k -m single -d single
+do_test -n 16k -m single -d dup
+do_test -n 16k -m dup -d single
+do_test -n 16k -m dup -d dup
+
+# Temporary: disable the following tests as they fail inside travis but run
+# fine otherwise. This is probably caused by kernel version, 4.4 fails and 4.14
+# is ok.
+#
+# root_helper mount -t btrfs -o loop /home/travis/build/kdave/btrfs-progs/tests/test.img /home/travis/build/kdave/btrfs-progs/tests/mnt
+# mount: No space left on device
+# failed: root_helper mount -t btrfs -o loop /home/travis/build/kdave/btrfs-progs/tests/test.img /home/travis/build/kdave/btrfs-progs/tests/mnt
+# test failed for case 010-minimal-size
+#
+if [ "$TRAVIS" = true ]; then
+ exit 0
+fi
+
+do_test -n 32k -m single -d single
+do_test -n 32k -m single -d dup
+do_test -n 32k -m dup -d single
+do_test -n 32k -m dup -d dup
+
+do_test -n 64k -m single -d single
+do_test -n 64k -m single -d dup
+do_test -n 64k -m dup -d single
+do_test -n 64k -m dup -d dup
diff --git a/tests/mkfs-tests/011-rootdir-create-file/test.sh b/tests/mkfs-tests/011-rootdir-create-file/test.sh
new file mode 100755
index 00000000..c04f711d
--- /dev/null
+++ b/tests/mkfs-tests/011-rootdir-create-file/test.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+# Regression test for mkfs.btrfs --rootdir on non-existent file.
+# Expected behavior: it should create a new file if destination doesn't exist
+# Regression 460e93f25754 ("btrfs-progs: mkfs: check the status of file at mkfs")
+
+source "$TOP/tests/common"
+
+check_prereq mkfs.btrfs
+
+tmp=$(mktemp -d --tmpdir btrfs-progs-mkfs.rootdirXXXXXXX)
+# we can't use TEST_DEV, a file is needed
+img=$(mktemp btrfs-progs-mkfs.rootdirXXXXXXX)
+run_check "$TOP/mkfs.btrfs" -f --rootdir "$TOP/Documentation/" "$img"
+
+rm -rf -- "$img"
diff --git a/tests/mkfs-tests/012-rootdir-no-shrink/test.sh b/tests/mkfs-tests/012-rootdir-no-shrink/test.sh
new file mode 100755
index 00000000..c1cb04f5
--- /dev/null
+++ b/tests/mkfs-tests/012-rootdir-no-shrink/test.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+# Test if mkfs.btrfs --rootdir will skip shrinking correctly
+
+source "$TOP/tests/common"
+
+check_prereq mkfs.btrfs
+
+setup_root_helper
+
+fs_size=$((512 * 1024 * 1024))
+bs=$((1024 * 1024))
+tmp=$(mktemp -d --tmpdir btrfs-progs-mkfs.rootdirXXXXXXX)
+
+prepare_test_dev $fs_size
+
+# No shrink case
+
+run_check "$TOP/mkfs.btrfs" -f --rootdir "$tmp" "$TEST_DEV"
+run_check_mount_test_dev
+
+# We should be able to write at least half of the fs size data since the fs is
+# not shrunk
+run_check $SUDO_HELPER dd if=/dev/zero bs=$bs count=$(($fs_size / $bs / 2)) \
+ of="$TEST_MNT/file"
+
+run_check_umount_test_dev
+
+# Shrink case
+
+run_check "$TOP/mkfs.btrfs" -f --rootdir "$tmp" --shrink "$TEST_DEV"
+run_check_mount_test_dev
+
+run_mustfail "mkfs.btrfs for shrink rootdir" \
+ $SUDO_HELPER dd if=/dev/zero bs=$bs count=$(($fs_size / $bs / 2)) \
+ of="$TEST_MNT/file"
+
+run_check_umount_test_dev
+
+rm -rf -- "$tmp"
diff --git a/tests/mkfs-tests/013-reserved-1M-for-single/test.sh b/tests/mkfs-tests/013-reserved-1M-for-single/test.sh
new file mode 100755
index 00000000..1490df2c
--- /dev/null
+++ b/tests/mkfs-tests/013-reserved-1M-for-single/test.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+# Test if "-m single" or "--mixed" can cause dev extent to use the reserved 1M
+# range
+#
+# Other profiles will cause mkfs.btrfs to allocate new meta/sys chunks
+# using btrfs_alloc_chunk() which won't use the 0~1M range, so other profiles
+# are safe, but we test them nevertheless.
+
+source "$TOP/tests/common"
+
+check_prereq mkfs.btrfs
+check_prereq btrfs
+
+prepare_test_dev
+
+do_one_test ()
+{
+ run_check "$TOP/mkfs.btrfs" -f "$@" "$TEST_DEV"
+
+ # Use dev-extent tree to find first device extent
+ first_dev_extent=$(run_check_stdout "$TOP/btrfs" inspect-internal \
+ dump-tree -t device "$TEST_DEV" | \
+ grep -oP '(?<=DEV_EXTENT )[[:digit:]]*' | head -n1)
+
+ if [ -z $first_dev_extent ]; then
+ _fail "failed to get first device extent"
+ fi
+
+ echo "first dev extent starts at $first_dev_extent" >> "$RESULTS"
+ echo "reserved range is [0, $(( 1024 * 1024)))" >> "$RESULTS"
+ # First device extent should not start below 1M
+ if [ $first_dev_extent -lt $(( 1024 * 1024 )) ]; then
+ _fail "first device extent occupies reserved 0~1M range"
+ fi
+}
+
+do_one_test --mixed
+do_one_test -m single
+
+do_one_test
+do_one_test -m dup
+do_one_test -d dup
+do_one_test -m dup -d dup
+do_one_test --mixed -m dup -d dup
diff --git a/tests/testsuite-files b/tests/testsuite-files
new file mode 100644
index 00000000..d75e2356
--- /dev/null
+++ b/tests/testsuite-files
@@ -0,0 +1,22 @@
+F README.md
+G Documentation/
+F testsuite-id
+F ../fssum
+F ../btrfs-corrupt-block
+F common
+F common.convert
+F common.local
+G tests/cli-tests/
+F cli-tests.sh
+G tests/convert-tests/
+F convert-tests.sh
+G tests/fsck-tests/
+F fsck-tests.sh
+G tests/fuzz-tests/
+F fuzz-tests.sh
+G tests/misc-tests/
+F misc-tests.sh
+G tests/mkfs-tests/
+F mkfs-tests.sh
+F scan-results.sh
+F test-console.sh