dad397ecaeec028b0b18e93710c86384148a75b2
[platform/upstream/btrfs-progs.git] / tests / misc-tests.sh
1 #!/bin/bash
2 #
3 # Misc tests
4
5 LANG=C
6 SCRIPT_DIR=$(dirname $(readlink -f "$0"))
7 if [ -z "$TOP" ]; then
8         TOP=$(readlink -f "$SCRIPT_DIR/../")
9         if [ -f "$TOP/configure.ac" ]; then
10                 # inside git
11                 TEST_TOP="$TOP/tests/"
12                 INTERNAL_BIN="$TOP"
13         else
14                 # external, defaults to system binaries
15                 TOP=$(dirname `which btrfs`)
16                 TEST_TOP="$SCRIPT_DIR"
17                 INTERNAL_BIN="$TEST_TOP"
18         fi
19 else
20         # assume external, TOP set from commandline
21         TEST_TOP="$SCRIPT_DIR"
22         INTERNAL_BIN="$TEST_TOP"
23 fi
24 if ! [ -x "$TOP/btrfs" ]; then
25         echo "ERROR: cannot execute btrfs from TOP=$TOP"
26         exit 1
27 fi
28 TEST_DEV=${TEST_DEV:-}
29 RESULTS="$TEST_TOP/misc-tests-results.txt"
30 IMAGE="$TEST_TOP/test.img"
31
32 source "$TEST_TOP/common"
33
34 export INTERNAL_BIN
35 export TEST_TOP
36 export TOP
37 export RESULTS
38 export LANG
39 export IMAGE
40 export TEST_DEV
41
42 rm -f "$RESULTS"
43
44 # test rely on corrupting blocks tool
45 check_prereq btrfs-corrupt-block
46 check_prereq btrfs-image
47 check_prereq btrfstune
48 check_prereq btrfs
49 check_prereq btrfs-find-root
50 check_prereq btrfs-select-super
51 check_kernel_support
52
53 # The tests are driven by their custom script called 'test.sh'
54
55 for i in $(find "$TEST_TOP/misc-tests" -maxdepth 1 -mindepth 1 -type d  \
56         ${TEST:+-name "$TEST"} | sort)
57 do
58         echo "    [TEST/misc]   $(basename $i)"
59         cd "$i"
60         echo "=== Entering $i" >> "$RESULTS"
61         if [ -x test.sh ]; then
62                 ./test.sh
63                 if [ $? -ne 0 ]; then
64                         if [[ $TEST_LOG =~ dump ]]; then
65                                 cat "$RESULTS"
66                         fi
67                         _fail "test failed for case $(basename $i)"
68                 fi
69         fi
70         cd "$TEST_TOP"
71 done