btrfs-progs: introduce TEST_TOP and INTERNAL_BIN for tests
[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 TEST_TOP=$(readlink -f "$SCRIPT_DIR/../tests/")
8 TOP=$(readlink -f "$SCRIPT_DIR/../")
9 if ! [ -f "$TOP/btrfs" ];then
10         TOP=$(dirname `which btrfs`)
11 fi
12 TEST_DEV=${TEST_DEV:-}
13 RESULTS="$TEST_TOP/fuzz-tests-results.txt"
14 IMAGE="$TEST_TOP/test.img"
15
16 source "$TEST_TOP/common"
17
18 export TEST_TOP
19 export TOP
20 export RESULTS
21 export LANG
22 export IMAGE
23 export TEST_DEV
24
25 rm -f "$RESULTS"
26
27 check_prereq btrfs
28
29 # The tests are driven by their custom script called 'test.sh'
30
31 for i in $(find "$TEST_TOP/fuzz-tests" -maxdepth 1 -mindepth 1 -type d  \
32         ${TEST:+-name "$TEST"} | sort)
33 do
34         name=$(basename "$i")
35         cd $i
36         if [ -x test.sh ]; then
37                 echo "=== Entering $i" >> "$RESULTS"
38                 echo "    [TEST/fuzz]   $name"
39                 ./test.sh
40                 if [ $? -ne 0 ]; then
41                         if [[ $TEST_LOG =~ dump ]]; then
42                                 cat "$RESULTS"
43                         fi
44                         _fail "test failed for case $(basename $i)"
45                 fi
46         fi
47         cd "$TEST_TOP"
48 done