libbtrfsutil: use pkg-config detection for the right Python version
[platform/upstream/btrfs-progs.git] / tests / cli-tests.sh
1 #!/bin/bash
2 #
3 # command line interface coverage tests
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/cli-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 check_kernel_support
46
47 # The tests are driven by their custom script called 'test.sh'
48
49 for i in $(find "$TEST_TOP/cli-tests" -maxdepth 1 -mindepth 1 -type d   \
50         ${TEST:+-name "$TEST"} | sort)
51 do
52         name=$(basename "$i")
53         cd "$i"
54         if [ -x test.sh ]; then
55                 echo "=== Entering $i" >> "$RESULTS"
56                 echo "    [TEST/cli]   $name"
57                 ./test.sh
58                 if [ $? -ne 0 ]; then
59                         if [[ $TEST_LOG =~ dump ]]; then
60                                 cat "$RESULTS"
61                         fi
62                         _fail "test failed for case $(basename $i)"
63                 fi
64         fi
65         cd "$TEST_TOP"
66 done