libbtrfsutil: use pkg-config detection for the right Python version
[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 if [ -z "$TOP" ]; then
8         TOP=$(readlink -f "$SCRIPT_DIR/../")
9         if [ -f "$TOP/configure.ac" ]; then
10                 # inside git
11                 TEST_TOP="$TOP/tests/"
12                 INTERNAL_BIN="$TOP"
13         else
14                 # external, defaults to system binaries
15                 TOP=$(dirname `which btrfs`)
16                 TEST_TOP="$SCRIPT_DIR"
17                 INTERNAL_BIN="$TEST_TOP"
18         fi
19 else
20         # assume external, TOP set from commandline
21         TEST_TOP="$SCRIPT_DIR"
22         INTERNAL_BIN="$TEST_TOP"
23 fi
24 if ! [ -x "$TOP/btrfs" ]; then
25         echo "ERROR: cannot execute btrfs from TOP=$TOP"
26         exit 1
27 fi
28 TEST_DEV=${TEST_DEV:-}
29 RESULTS="$TEST_TOP/fsck-tests-results.txt"
30 IMAGE="$TEST_TOP/test.img"
31
32 source "$TEST_TOP/common"
33
34 export INTERNAL_BIN
35 export TEST_TOP
36 export TOP
37 export RESULTS
38 export LANG
39 export IMAGE
40 export TEST_DEV
41
42 rm -f "$RESULTS"
43
44 # test rely on corrupting blocks tool
45 check_prereq btrfs-corrupt-block
46 check_prereq btrfs-image
47 check_prereq btrfs
48 check_prereq btrfstune
49 check_kernel_support
50
51 run_one_test() {
52         local testname
53
54         testname="$1"
55         echo "    [TEST/fsck]   $(basename $testname)"
56         cd "$testname"
57         echo "=== Entering $testname" >> "$RESULTS"
58         if [ -x test.sh ]; then
59                 # Type 2
60                 ./test.sh
61                 if [ $? -ne 0 ]; then
62                         if [[ $TEST_LOG =~ dump ]]; then
63                                 cat "$RESULTS"
64                         fi
65                         _fail "test failed for case $(basename $testname)"
66                 fi
67         else
68                 # Type 1
69                 check_all_images
70         fi
71         cd "$TEST_TOP"
72 }
73
74 # Each dir contains one type of error for btrfsck test.
75 # Each dir must be one of the following 2 types:
76 # 1) Only btrfs-image dump
77 #    Only contains one or several btrfs-image dumps (.img)
78 #    Each image will be tested by generic test routine
79 #    (btrfsck --repair and btrfsck).
80 #    This is for case that btree-healthy images.
81 # 2) Custom test script
82 #    This dir contains test.sh which will do custom image
83 #    generation/check/verification.
84 #    This is for case btrfs-image can't dump or case needs extra
85 #    check/verify
86
87 for i in $(find "$TEST_TOP/fsck-tests" -maxdepth 1 -mindepth 1 -type d  \
88         ${TEST:+-name "$TEST"} | sort)
89 do
90         run_one_test "$i"
91 done