btrfs-progs: Introduce a misc test for thread conflict in btrfs-convert
[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 # It's GPL, same as everything else in this tree.
6 #
7
8 unset TOP
9 unset LANG
10 LANG=C
11 SCRIPT_DIR=$(dirname $(readlink -f $0))
12 TOP=$(readlink -f $SCRIPT_DIR/../)
13 TEST_DEV=${TEST_DEV:-}
14 TEST_MNT=${TEST_MNT:-$TOP/tests/mnt}
15 RESULTS="$TOP/tests/fsck-tests-results.txt"
16
17 source $TOP/tests/common
18
19 # Allow child test to use $TOP and $RESULTS
20 export TOP
21 export RESULTS
22 # For custom script needs to verfiy recovery
23 export TEST_MNT
24 export LANG
25
26 rm -f $RESULTS
27 mkdir -p $TEST_MNT || _fail "unable to create mount point on $TEST_MNT"
28
29 # test rely on corrupting blocks tool
30 check_prereq btrfs-corrupt-block
31 check_prereq btrfs-image
32 check_prereq btrfs
33
34 run_one_test() {
35         local testname
36
37         testname="$1"
38         echo "    [TEST]   $(basename $testname)"
39         cd $testname
40         echo "=== Entering $testname" >> $RESULTS
41         if [ -x test.sh ]; then
42                 # Type 2
43                 ./test.sh
44                 if [ $? -ne 0 ]; then
45                         _fail "test failed for case $(basename $testname)"
46                 fi
47         else
48                 # Type 1
49                 check_all_images `pwd`
50         fi
51         cd $TOP
52 }
53
54 # Each dir contains one type of error for btrfsck test.
55 # Each dir must be one of the following 2 types:
56 # 1) Only btrfs-image dump
57 #    Only contains one or several btrfs-image dumps (.img)
58 #    Each image will be tested by generic test routine
59 #    (btrfsck --repair and btrfsck).
60 #    This is for case that btree-healthy images.
61 # 2) Custom test script
62 #    This dir contains test.sh which will do custom image
63 #    generation/check/verification.
64 #    This is for case btrfs-image can't dump or case needs extra
65 #    check/verify
66
67 for i in $(find $TOP/tests/fsck-tests -maxdepth 1 -mindepth 1 -type d   \
68         ${TEST:+-name "$TEST"} | sort)
69 do
70         run_one_test "$i"
71 done