diff --git a/tests/clean-tests.sh b/tests/clean-tests.sh index 61baa069..f5f63092 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/tests/common" setup_root_helper diff --git a/tests/cli-tests.sh b/tests/cli-tests.sh index b981f833..9e0fbae4 100755 --- a/tests/cli-tests.sh +++ b/tests/cli-tests.sh @@ -4,10 +4,26 @@ 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`) +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" @@ -15,6 +31,7 @@ IMAGE="$TEST_TOP/test.img" source "$TEST_TOP/common" +export INTERNAL_BIN export TEST_TOP export TOP export RESULTS diff --git a/tests/convert-tests.sh b/tests/convert-tests.sh index 52c59d4d..4bc915db 100755 --- a/tests/convert-tests.sh +++ b/tests/convert-tests.sh @@ -5,10 +5,26 @@ 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`) +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/convert-tests-results.txt" @@ -17,6 +33,7 @@ IMAGE="$TEST_TOP/test.img" source "$TEST_TOP/common" source "$TEST_TOP/common.convert" +export INTERNAL_BIN export TEST_TOP export TOP export RESULTS diff --git a/tests/fsck-tests.sh b/tests/fsck-tests.sh index f97ae986..14287bbe 100755 --- a/tests/fsck-tests.sh +++ b/tests/fsck-tests.sh @@ -4,11 +4,26 @@ 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`) +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/fsck-tests-results.txt" diff --git a/tests/fuzz-tests.sh b/tests/fuzz-tests.sh index dca84f10..7bc620f0 100755 --- a/tests/fuzz-tests.sh +++ b/tests/fuzz-tests.sh @@ -4,10 +4,26 @@ 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`) +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/fuzz-tests-results.txt" @@ -15,6 +31,7 @@ IMAGE="$TEST_TOP/test.img" source "$TEST_TOP/common" +export INTERNAL_BIN export TEST_TOP export TOP export RESULTS diff --git a/tests/misc-tests.sh b/tests/misc-tests.sh index fed1b36c..94703a3e 100755 --- a/tests/misc-tests.sh +++ b/tests/misc-tests.sh @@ -4,11 +4,26 @@ 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`) +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/misc-tests-results.txt" @@ -21,8 +36,8 @@ export TEST_TOP export TOP export RESULTS export LANG -export TEST_DEV export IMAGE +export TEST_DEV rm -f "$RESULTS" diff --git a/tests/mkfs-tests.sh b/tests/mkfs-tests.sh index 1a84b37c..2ced4ac9 100755 --- a/tests/mkfs-tests.sh +++ b/tests/mkfs-tests.sh @@ -4,11 +4,26 @@ 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`) +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/mkfs-tests-results.txt"