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