btrfs-progs: introduce TEST_TOP and INTERNAL_BIN for tests
authorGu Jinxiang <gujx@cn.fujitsu.com>
Thu, 8 Feb 2018 06:34:19 +0000 (14:34 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 13 Feb 2018 14:41:32 +0000 (15:41 +0100)
Use TEST_TOP as base for tests to reference any files, this will be used
for git and external testsuite.

INTERNAL_BIN is needed for referencing binaries that could reside in
different paths in git vs external testsuite.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
[ add quotes around sourced files, update changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
88 files changed:
tests/cli-tests.sh
tests/cli-tests/001-btrfs/test.sh
tests/cli-tests/002-balance-full-no-filters/test.sh
tests/cli-tests/003-fi-resize-args/test.sh
tests/cli-tests/004-send-parent-multi-subvol/test.sh
tests/cli-tests/005-qgroup-show/test.sh
tests/cli-tests/006-qgroup-show-sync/test.sh
tests/cli-tests/007-check-force/test.sh
tests/cli-tests/008-subvolume-get-set-default/test.sh
tests/common
tests/convert-tests.sh
tests/convert-tests/001-ext2-basic/test.sh
tests/convert-tests/002-ext3-basic/test.sh
tests/convert-tests/003-ext4-basic/test.sh
tests/convert-tests/004-ext2-backup-superblock-ranges/test.sh
tests/convert-tests/005-delete-all-rollback/test.sh
tests/convert-tests/006-large-hole-extent/test.sh
tests/convert-tests/007-unsupported-block-sizes/test.sh
tests/convert-tests/008-readonly-image/test.sh
tests/convert-tests/009-common-inode-flags/test.sh
tests/convert-tests/010-reiserfs-basic/test.sh
tests/convert-tests/011-reiserfs-delete-all-rollback/test.sh
tests/convert-tests/012-reiserfs-large-hole-extent/test.sh
tests/convert-tests/013-reiserfs-common-inode-flags/test.sh
tests/convert-tests/014-reiserfs-tail-handling/test.sh
tests/convert-tests/015-no-rollback-after-balance/test.sh
tests/fsck-tests.sh
tests/fsck-tests/006-bad-root-items/test.sh
tests/fsck-tests/012-leaf-corruption/test.sh
tests/fsck-tests/013-extent-tree-rebuild/test.sh
tests/fsck-tests/018-leaf-crossing-stripes/test.sh
tests/fsck-tests/019-non-skinny-false-alert/test.sh
tests/fsck-tests/020-extent-ref-cases/test.sh
tests/fsck-tests/021-partially-dropped-snapshot-case/test.sh
tests/fsck-tests/022-qgroup-rescan-halfway/test.sh
tests/fsck-tests/023-qgroup-stack-overflow/test.sh
tests/fsck-tests/024-clear-space-cache/test.sh
tests/fsck-tests/025-file-extents/test.sh
tests/fsck-tests/026-bad-dir-item-name/test.sh
tests/fsck-tests/028-unaligned-super-dev-sizes/test.sh
tests/fuzz-tests.sh
tests/fuzz-tests/001-simple-check-unmounted/test.sh
tests/fuzz-tests/002-simple-image/test.sh
tests/fuzz-tests/003-multi-check-unmounted/test.sh
tests/fuzz-tests/004-simple-dump-tree/test.sh
tests/fuzz-tests/005-simple-dump-super/test.sh
tests/fuzz-tests/006-simple-tree-stats/test.sh
tests/fuzz-tests/007-simple-super-recover/test.sh
tests/fuzz-tests/008-simple-chunk-recover/test.sh
tests/fuzz-tests/009-simple-zero-log/test.sh
tests/misc-tests.sh
tests/misc-tests/001-btrfstune-features/test.sh
tests/misc-tests/002-uuid-rewrite/test.sh
tests/misc-tests/003-zero-log/test.sh
tests/misc-tests/004-shrink-fs/test.sh
tests/misc-tests/005-convert-progress-thread-crash/test.sh
tests/misc-tests/006-image-on-missing-device/test.sh
tests/misc-tests/007-subvolume-sync/test.sh
tests/misc-tests/008-leaf-crossing-stripes/test.sh
tests/misc-tests/009-subvolume-sync-must-wait/test.sh
tests/misc-tests/010-convert-delete-ext2-subvol/test.sh
tests/misc-tests/011-delete-missing-device/test.sh
tests/misc-tests/012-find-root-no-result/test.sh
tests/misc-tests/013-subvolume-sync-crash/test.sh
tests/misc-tests/014-filesystem-label/test.sh
tests/misc-tests/015-dump-super-garbage/test.sh
tests/misc-tests/016-send-clone-src/test.sh
tests/misc-tests/017-recv-stream-malformatted/test.sh
tests/misc-tests/018-recv-end-of-stream/test.sh
tests/misc-tests/019-receive-clones-on-mounted-subvol/test.sh
tests/misc-tests/020-fix-superblock-corruption/test.sh
tests/misc-tests/021-image-multi-devices/test.sh
tests/misc-tests/022-filesystem-du-on-empty-subvol/test.sh
tests/misc-tests/023-device-usage-with-missing-device/test.sh
tests/misc-tests/024-inspect-internal-rootid/test.sh
tests/misc-tests/025-zstd-compression/test.sh
tests/misc-tests/026-image-non-printable-chars/test.sh
tests/misc-tests/027-subvol-list-deleted-toplevel/test.sh
tests/mkfs-tests.sh
tests/mkfs-tests/001-basic-profiles/test.sh
tests/mkfs-tests/002-no-force-mixed-on-small-volume/test.sh
tests/mkfs-tests/003-mixed-with-wrong-nodesize/test.sh
tests/mkfs-tests/004-rootdir-keeps-size/test.sh
tests/mkfs-tests/005-long-device-name-for-ssd/test.sh
tests/mkfs-tests/006-partitioned-loopdev/test.sh
tests/mkfs-tests/007-mix-nodesize-sectorsize/test.sh
tests/mkfs-tests/008-sectorsize-nodesize-combination/test.sh
tests/mkfs-tests/009-special-files-for-rootdir/test.sh

index 16d6afc..b981f83 100755 (executable)
@@ -4,13 +4,18 @@
 
 LANG=C
 SCRIPT_DIR=$(dirname $(readlink -f "$0"))
+TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/")
 TOP=$(readlink -f "$SCRIPT_DIR/../")
+if ! [ -f "$TOP/btrfs" ];then
+       TOP=$(dirname `which btrfs`)
+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 TEST_TOP
 export TOP
 export RESULTS
 export LANG
@@ -24,7 +29,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 +45,5 @@ do
                        _fail "test failed for case $(basename $i)"
                fi
        fi
-       cd "$TOP"
+       cd "$TEST_TOP"
 done
index c680604..55ab0ad 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/bash
 # test commands of btrfs
 
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
 
 check_prereq btrfs
 
index 0475ea7..3403b70 100755 (executable)
@@ -2,7 +2,7 @@
 #
 # coverage of balance --full-balance
 
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
 
 check_prereq mkfs.btrfs
 check_prereq btrfs
index e4f262b..f6f598f 100755 (executable)
@@ -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
index c1348b5..165ef4a 100755 (executable)
@@ -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
index d9a9183..1052103 100755 (executable)
@@ -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
index d552b8b..aec7a4b 100755 (executable)
@@ -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
index 12b3020..597f2d6 100755 (executable)
@@ -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
index 9318002..706ee8c 100755 (executable)
@@ -10,7 +10,7 @@ check_default_id()
        fi
 }
 
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
 
 check_prereq mkfs.btrfs
 check_prereq btrfs
index 7f641a0..fae30f1 100644 (file)
@@ -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
 }
 
@@ -449,9 +453,9 @@ prepare_test_dev()
                return;
        fi
 
-       echo "\$TEST_DEV not given, using $TOP/tests/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"
@@ -632,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"
index 2a92a58..52c59d4 100755 (executable)
@@ -5,14 +5,19 @@
 
 LANG=C
 SCRIPT_DIR=$(dirname $(readlink -f "$0"))
+TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/")
 TOP=$(readlink -f "$SCRIPT_DIR/../")
+if ! [ -f "$TOP/btrfs" ];then
+       TOP=$(dirname `which btrfs`)
+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 TEST_TOP
 export TOP
 export RESULTS
 export LANG
@@ -54,7 +59,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"
index af75d94..74cc74e 100755 (executable)
@@ -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
index 233e2d9..f086989 100755 (executable)
@@ -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
index baf6115..c5caf67 100755 (executable)
@@ -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
index cf354d4..dcb9772 100755 (executable)
@@ -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
index 31fa2c4..a5f9d59 100755 (executable)
@@ -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
index 38e9705..a37fcbd 100755 (executable)
@@ -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
index ef01020..9fda5ad 100755 (executable)
@@ -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
index 064bc27..1a65ea6 100755 (executable)
@@ -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
index 6d15999..428213b 100755 (executable)
@@ -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
index 87008f1..7365299 100755 (executable)
@@ -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"
index 0b8366c..28877e1 100755 (executable)
@@ -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"
index dde1b3e..d492779 100755 (executable)
@@ -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"
index a15240c..521e8bd 100755 (executable)
@@ -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"
index 335c009..5714dc6 100755 (executable)
@@ -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"
index 47c9c6f..2f6407f 100755 (executable)
@@ -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
index 15d26c7..f97ae98 100755 (executable)
@@ -4,13 +4,20 @@
 
 LANG=C
 SCRIPT_DIR=$(dirname $(readlink -f "$0"))
+INTERNAL_BIN=$(readlink -f "$SCRIPT_DIR/../")
+TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/")
 TOP=$(readlink -f "$SCRIPT_DIR/../")
+if ! [ -f "$TOP/btrfs" ];then
+       TOP=$(dirname `which btrfs`)
+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 +53,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 +69,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"
index bf3ef78..2cbf67a 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
 
 check_prereq btrfs
 
index fc10a4f..68d9f69 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
 
 check_prereq btrfs-image
 
index d71c1b2..02afdda 100755 (executable)
@@ -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 && \
index 29eb20b..2a3f637 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
 
 check_prereq btrfs
 
index 550f294..32f595d 100755 (executable)
@@ -11,7 +11,7 @@
 #
 # a buggy check leads to the above messages
 
-source "$TOP/tests/common"
+source "$TEST_TOP/common"
 
 check_prereq btrfs
 
index 0c4f784..9cf99a5 100755 (executable)
@@ -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
 
index 5d997e2..e6379f9 100755 (executable)
@@ -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
 
index dcdc1b4..615f003 100755 (executable)
@@ -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
 
index ebb07f3..d7b85f0 100755 (executable)
@@ -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
 
index 76ebcb6..6a3a31e 100755 (executable)
@@ -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
index ebe8a30..9570759 100755 (executable)
@@ -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
index a1077a8..a38bf04 100755 (executable)
@@ -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
 
index 2c72c7e..4015df2 100755 (executable)
@@ -3,7 +3,7 @@
 # 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
 setup_root_helper
index f72385e..dca84f1 100755 (executable)
@@ -4,13 +4,18 @@
 
 LANG=C
 SCRIPT_DIR=$(dirname $(readlink -f "$0"))
+TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/")
 TOP=$(readlink -f "$SCRIPT_DIR/../")
+if ! [ -f "$TOP/btrfs" ];then
+       TOP=$(dirname `which btrfs`)
+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 TEST_TOP
 export TOP
 export RESULTS
 export LANG
@@ -23,7 +28,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 +44,5 @@ do
                        _fail "test failed for case $(basename $i)"
                fi
        fi
-       cd "$TOP"
+       cd "$TEST_TOP"
 done
index 98fe7b0..905d37b 100755 (executable)
@@ -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
index 42470ec..034fcf4 100755 (executable)
@@ -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
 
index 9fd7b8a..35dfe4f 100755 (executable)
@@ -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
index 89ff214..6c9e8c4 100755 (executable)
@@ -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
index fbce3d9..01c7b62 100755 (executable)
@@ -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
index c3410b0..dbed471 100755 (executable)
@@ -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
index 885cb35..ceb1634 100755 (executable)
@@ -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
index d53453f..198f88e 100755 (executable)
@@ -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
index 393db3f..928c66b 100755 (executable)
@@ -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
index 0898801..fed1b36 100755 (executable)
@@ -4,13 +4,20 @@
 
 LANG=C
 SCRIPT_DIR=$(dirname $(readlink -f "$0"))
+TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/")
+INTERNAL_BIN=$(readlink -f "$SCRIPT_DIR/../")
 TOP=$(readlink -f "$SCRIPT_DIR/../")
+if ! [ -f "$TOP/btrfs" ];then
+       TOP=$(dirname `which btrfs`)
+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
@@ -31,7 +38,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 +53,5 @@ do
                        _fail "test failed for case $(basename $i)"
                fi
        fi
-       cd "$TOP"
+       cd "$TEST_TOP"
 done
index bfa7f43..718e4b0 100755 (executable)
@@ -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
index fd100fb..e32aff0 100755 (executable)
@@ -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 \
index e7c5c80..9d2940f 100755 (executable)
@@ -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
index 8874035..2f08b0b 100755 (executable)
@@ -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
index bc71e1f..b8012c9 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/bash
 # test convert-thread-conflict
 
-source $TOP/tests/common
+source "$TEST_TOP/common"
 
 check_prereq btrfs-convert
 
index 2766fb1..d8b1cef 100755 (executable)
@@ -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
index 243bb8c..ef03d16 100755 (executable)
@@ -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
index 0381806..517bd66 100755 (executable)
@@ -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
index fa3f09a..15de335 100755 (executable)
@@ -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
index 7915867..6d510fe 100755 (executable)
@@ -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
index 8a1b14b..469c3be 100755 (executable)
@@ -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
index 983a8a1..f4a57e7 100755 (executable)
@@ -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
index cd44596..051b457 100755 (executable)
@@ -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
index 753aa9e..bd6773c 100755 (executable)
@@ -2,7 +2,7 @@
 #
 # test label settings
 
-source $TOP/tests/common
+source "$TEST_TOP/common"
 
 check_prereq mkfs.btrfs
 check_prereq btrfs
index 33fc833..10d8d5b 100755 (executable)
@@ -2,7 +2,7 @@
 #
 # let dump-super dump random data, must not crash
 
-source $TOP/tests/common
+source "$TEST_TOP/common"
 
 check_prereq btrfs
 
index 2780ebb..e4fa16a 100755 (executable)
@@ -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
index d199a72..991f256 100755 (executable)
@@ -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
index 9ca035f..79e735e 100755 (executable)
@@ -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
index 182b0cf..60ec5cf 100755 (executable)
@@ -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"
index 77c1a5a..8f3d20f 100755 (executable)
@@ -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
index abf67f9..d78c44f 100755 (executable)
@@ -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
index 72cf076..5436528 100755 (executable)
@@ -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
index 3c8ba85..05894cf 100755 (executable)
@@ -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
index 40e382b..71e1904 100755 (executable)
@@ -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
index e95dcb3..22795d2 100755 (executable)
@@ -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
index 8018586..50441a2 100755 (executable)
@@ -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
index ee41d71..3b73dd3 100755 (executable)
@@ -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
index c8ff8c8..1a84b37 100755 (executable)
@@ -4,13 +4,20 @@
 
 LANG=C
 SCRIPT_DIR=$(dirname $(readlink -f "$0"))
+INTERNAL_BIN=$(readlink -f "$SCRIPT_DIR/../")
+TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/")
 TOP=$(readlink -f "$SCRIPT_DIR/../")
+if ! [ -f "$TOP/btrfs" ];then
+       TOP=$(dirname `which btrfs`)
+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 +32,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 +47,5 @@ do
                        _fail "test failed for case $(basename $i)"
                fi
        fi
-       cd "$TOP"
+       cd "$TEST_TOP"
 done
index 854ee00..b84016f 100755 (executable)
@@ -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
index 3784623..4bc9c26 100755 (executable)
@@ -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
 
index 074fc22..f532733 100755 (executable)
@@ -2,7 +2,7 @@
 #
 # Mixed mode needs equal sectorsize and nodesize
 
-source $TOP/tests/common
+source "$TEST_TOP/common"
 
 check_prereq mkfs.btrfs
 
index 7038c8e..4a84e6d 100755 (executable)
@@ -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
index 5bdf50e..55ce676 100755 (executable)
@@ -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
 
index 0c77e5c..06c254f 100755 (executable)
@@ -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"
index 3980414..f7e88c9 100755 (executable)
@@ -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
index 955cd2b..9cc2f9e 100755 (executable)
@@ -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
index d327a0d..a94d520 100755 (executable)
@@ -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