btrfs-progs: tests: convert: set common variables
[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
7 unset TOP
8 unset LANG
9 LANG=C
10 SCRIPT_DIR=$(dirname $(readlink -f $0))
11 TOP=$(readlink -f $SCRIPT_DIR/../)
12 TEST_DEV=${TEST_DEV:-}
13 RESULTS="$TOP/tests/convert-tests-results.txt"
14 IMAGE="$TOP/tests/test.img"
15
16 source $TOP/tests/common
17 source $TOP/tests/common.convert
18
19 # Allow child test to use $TOP and $RESULTS
20 export TOP
21 export RESULTS
22 export LANG
23
24 rm -f $RESULTS
25
26 run_one_test() {
27         local testname
28
29         testname="$1"
30         echo "    [TEST/conv]   $testname"
31         cd $testname
32         echo "=== Entering $testname" >> $RESULTS
33         if [ -x test.sh ]; then
34                 # Difference convert test case needs different tools to restore
35                 # and check image, so only support custom test scripts
36                 ./test.sh
37                 if [ $? -ne 0 ]; then
38                         _fail "test failed for case $(basename $testname)"
39                 fi
40         else
41                 _fail "custom test script not found"
42         fi
43 }
44
45 # Test special images
46 for i in $(find $TOP/tests/convert-tests -maxdepth 1 -mindepth 1 -type d \
47            ${TEST:+-name "$TEST"} | sort)
48 do
49         run_one_test "$i"
50 done