btrfs-progs: tests: unify test drivers
[platform/upstream/btrfs-progs.git] / tests / fsck-tests.sh
1 #!/bin/bash
2 #
3 # loop through all of our bad images and make sure fsck repairs them properly
4
5 LANG=C
6 SCRIPT_DIR=$(dirname $(readlink -f $0))
7 TOP=$(readlink -f $SCRIPT_DIR/../)
8 TEST_DEV=${TEST_DEV:-}
9 RESULTS="$TOP/tests/fsck-tests-results.txt"
10 IMAGE="$TOP/tests/test.img"
11
12 source $TOP/tests/common
13
14 export TOP
15 export RESULTS
16 export LANG
17 export IMAGE
18 export TEST_DEV
19
20 rm -f $RESULTS
21
22 # test rely on corrupting blocks tool
23 check_prereq btrfs-corrupt-block
24 check_prereq btrfs-image
25 check_prereq btrfs
26
27 run_one_test() {
28         local testname
29
30         testname="$1"
31         echo "    [TEST/fsck]   $(basename $testname)"
32         cd $testname
33         echo "=== Entering $testname" >> $RESULTS
34         if [ -x test.sh ]; then
35                 # Type 2
36                 ./test.sh
37                 if [ $? -ne 0 ]; then
38                         _fail "test failed for case $(basename $testname)"
39                 fi
40         else
41                 # Type 1
42                 check_all_images `pwd`
43         fi
44         cd $TOP
45 }
46
47 # Each dir contains one type of error for btrfsck test.
48 # Each dir must be one of the following 2 types:
49 # 1) Only btrfs-image dump
50 #    Only contains one or several btrfs-image dumps (.img)
51 #    Each image will be tested by generic test routine
52 #    (btrfsck --repair and btrfsck).
53 #    This is for case that btree-healthy images.
54 # 2) Custom test script
55 #    This dir contains test.sh which will do custom image
56 #    generation/check/verification.
57 #    This is for case btrfs-image can't dump or case needs extra
58 #    check/verify
59
60 for i in $(find $TOP/tests/fsck-tests -maxdepth 1 -mindepth 1 -type d   \
61         ${TEST:+-name "$TEST"} | sort)
62 do
63         run_one_test "$i"
64 done