btrfs-progs: introduce TEST_TOP and INTERNAL_BIN for tests
[platform/upstream/btrfs-progs.git] / tests / mkfs-tests.sh
1 #!/bin/bash
2 #
3 # mkfs.btrfs tests
4
5 LANG=C
6 SCRIPT_DIR=$(dirname $(readlink -f "$0"))
7 INTERNAL_BIN=$(readlink -f "$SCRIPT_DIR/../")
8 TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/")
9 TOP=$(readlink -f "$SCRIPT_DIR/../")
10 if ! [ -f "$TOP/btrfs" ];then
11         TOP=$(dirname `which btrfs`)
12 fi
13 TEST_DEV=${TEST_DEV:-}
14 RESULTS="$TEST_TOP/mkfs-tests-results.txt"
15 IMAGE="$TEST_TOP/test.img"
16
17 source "$TEST_TOP/common"
18
19 export INTERNAL_BIN
20 export TEST_TOP
21 export TOP
22 export RESULTS
23 export LANG
24 export IMAGE
25 export TEST_DEV
26
27 rm -f "$RESULTS"
28
29 check_prereq mkfs.btrfs
30 check_prereq btrfs
31 check_kernel_support
32
33 # The tests are driven by their custom script called 'test.sh'
34
35 for i in $(find "$TEST_TOP/mkfs-tests" -maxdepth 1 -mindepth 1 -type d  \
36         ${TEST:+-name "$TEST"} | sort)
37 do
38         echo "    [TEST/mkfs]   $(basename $i)"
39         cd "$i"
40         echo "=== Entering $i" >> "$RESULTS"
41         if [ -x test.sh ]; then
42                 ./test.sh
43                 if [ $? -ne 0 ]; then
44                         if [[ $TEST_LOG =~ dump ]]; then
45                                 cat "$RESULTS"
46                         fi
47                         _fail "test failed for case $(basename $i)"
48                 fi
49         fi
50         cd "$TEST_TOP"
51 done