btrfs-progs: add tool to edit super blocks
[platform/upstream/btrfs-progs.git] / tests / fuzz-tests.sh
1 #!/bin/bash
2 #
3 # misc tests on fuzzed or crafted images
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/fuzz-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 check_prereq btrfs
45
46 # The tests are driven by their custom script called 'test.sh'
47
48 for i in $(find "$TEST_TOP/fuzz-tests" -maxdepth 1 -mindepth 1 -type d  \
49         ${TEST:+-name "$TEST"} | sort)
50 do
51         name=$(basename "$i")
52         cd $i
53         if [ -x test.sh ]; then
54                 echo "=== Entering $i" >> "$RESULTS"
55                 echo "    [TEST/fuzz]   $name"
56                 ./test.sh
57                 if [ $? -ne 0 ]; then
58                         if [[ $TEST_LOG =~ dump ]]; then
59                                 cat "$RESULTS"
60                         fi
61                         _fail "test failed for case $(basename $i)"
62                 fi
63         fi
64         cd "$TEST_TOP"
65 done