btrfs-progs: free-space-cache: Enhance free space cache free space check
[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 if [ -z "$TOP" ]; then
9         TOP=$(readlink -f "$SCRIPT_DIR/../")
10         if [ -f "$TOP/configure.ac" ]; then
11                 # inside git
12                 TEST_TOP="$TOP/tests/"
13                 INTERNAL_BIN="$TOP"
14         else
15                 # external, defaults to system binaries
16                 TOP=$(dirname `which btrfs`)
17                 TEST_TOP="$SCRIPT_DIR"
18                 INTERNAL_BIN="$TEST_TOP"
19         fi
20 else
21         # assume external, TOP set from commandline
22         TEST_TOP="$SCRIPT_DIR"
23         INTERNAL_BIN="$TEST_TOP"
24 fi
25 if ! [ -x "$TOP/btrfs" ]; then
26         echo "ERROR: cannot execute btrfs from TOP=$TOP"
27         exit 1
28 fi
29 TEST_DEV=${TEST_DEV:-}
30 RESULTS="$TEST_TOP/convert-tests-results.txt"
31 IMAGE="$TEST_TOP/test.img"
32
33 source "$TEST_TOP/common"
34 source "$TEST_TOP/common.convert"
35
36 export INTERNAL_BIN
37 export TEST_TOP
38 export TOP
39 export RESULTS
40 export LANG
41 export IMAGE
42 export TEST_DEV
43
44 rm -f "$RESULTS"
45
46 check_kernel_support
47 check_kernel_support_reiserfs
48 # anything expected by common.convert
49 check_global_prereq getfacl
50 check_global_prereq setfacl
51 check_global_prereq md5sum
52
53 run_one_test() {
54         local testdir
55         local testname
56
57         testdir="$1"
58         testname=$(basename "$testdir")
59         echo "    [TEST/conv]   $testname"
60         cd "$testdir"
61         echo "=== Entering $testname" >> "$RESULTS"
62         if [ -x test.sh ]; then
63                 # Only support custom test scripts
64                 ./test.sh
65                 if [ $? -ne 0 ]; then
66                         if [[ $TEST_LOG =~ dump ]]; then
67                                 # the logs can be large and may exceed the
68                                 # limits, use 4MB for now
69                                 tail -c 3900000 "$RESULTS"
70                         fi
71                         _fail "test failed for case $testname"
72                 fi
73         else
74                 _fail "custom test script not found"
75         fi
76 }
77
78 # Test special images
79 for i in $(find "$TEST_TOP/convert-tests" -maxdepth 1 -mindepth 1 -type d \
80            ${TEST:+-name "$TEST"} | sort)
81 do
82         run_one_test "$i"
83 done