btrfs-progs: introduce TEST_TOP and INTERNAL_BIN for tests
[platform/upstream/btrfs-progs.git] / tests / convert-tests.sh
1 #!/bin/bash
2 #
3 # convert ext2/3/4 images to btrfs images, and make sure the results are
4 # clean.
5
6 LANG=C
7 SCRIPT_DIR=$(dirname $(readlink -f "$0"))
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/convert-tests-results.txt"
15 IMAGE="$TEST_TOP/test.img"
16
17 source "$TEST_TOP/common"
18 source "$TEST_TOP/common.convert"
19
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_kernel_support
30 check_kernel_support_reiserfs
31 # anything expected by common.convert
32 check_global_prereq getfacl
33 check_global_prereq setfacl
34 check_global_prereq md5sum
35
36 run_one_test() {
37         local testdir
38         local testname
39
40         testdir="$1"
41         testname=$(basename "$testdir")
42         echo "    [TEST/conv]   $testname"
43         cd "$testdir"
44         echo "=== Entering $testname" >> "$RESULTS"
45         if [ -x test.sh ]; then
46                 # Only support custom test scripts
47                 ./test.sh
48                 if [ $? -ne 0 ]; then
49                         if [[ $TEST_LOG =~ dump ]]; then
50                                 # the logs can be large and may exceed the
51                                 # limits, use 4MB for now
52                                 tail -c 3900000 "$RESULTS"
53                         fi
54                         _fail "test failed for case $testname"
55                 fi
56         else
57                 _fail "custom test script not found"
58         fi
59 }
60
61 # Test special images
62 for i in $(find "$TEST_TOP/convert-tests" -maxdepth 1 -mindepth 1 -type d \
63            ${TEST:+-name "$TEST"} | sort)
64 do
65         run_one_test "$i"
66 done