btrfs-progs: tests: Remove misleading BCP 78 boilerplate from SHA implementation
[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 check_prereq btrfstune
27 check_kernel_support
28
29 run_one_test() {
30         local testname
31
32         testname="$1"
33         echo "    [TEST/fsck]   $(basename $testname)"
34         cd "$testname"
35         echo "=== Entering $testname" >> "$RESULTS"
36         if [ -x test.sh ]; then
37                 # Type 2
38                 ./test.sh
39                 if [ $? -ne 0 ]; then
40                         if [[ $TEST_LOG =~ dump ]]; then
41                                 cat "$RESULTS"
42                         fi
43                         _fail "test failed for case $(basename $testname)"
44                 fi
45         else
46                 # Type 1
47                 check_all_images
48         fi
49         cd "$TOP"
50 }
51
52 # Each dir contains one type of error for btrfsck test.
53 # Each dir must be one of the following 2 types:
54 # 1) Only btrfs-image dump
55 #    Only contains one or several btrfs-image dumps (.img)
56 #    Each image will be tested by generic test routine
57 #    (btrfsck --repair and btrfsck).
58 #    This is for case that btree-healthy images.
59 # 2) Custom test script
60 #    This dir contains test.sh which will do custom image
61 #    generation/check/verification.
62 #    This is for case btrfs-image can't dump or case needs extra
63 #    check/verify
64
65 for i in $(find "$TOP/tests/fsck-tests" -maxdepth 1 -mindepth 1 -type d \
66         ${TEST:+-name "$TEST"} | sort)
67 do
68         run_one_test "$i"
69 done