btrfs-progs: tests: limit size of log dump from conver tests
[platform/upstream/btrfs-progs.git] / tests / convert-tests.sh
1 #!/bin/bash
2 #
3 # convert ext2/3/4 images to btrfs images, and make sure the results are
4 # clean.
5
6 LANG=C
7 SCRIPT_DIR=$(dirname $(readlink -f "$0"))
8 TOP=$(readlink -f "$SCRIPT_DIR/../")
9 TEST_DEV=${TEST_DEV:-}
10 RESULTS="$TOP/tests/convert-tests-results.txt"
11 IMAGE="$TOP/tests/test.img"
12
13 source "$TOP/tests/common"
14 source "$TOP/tests/common.convert"
15
16 export TOP
17 export RESULTS
18 export LANG
19 export IMAGE
20 export TEST_DEV
21
22 rm -f "$RESULTS"
23
24 check_kernel_support
25 # anything expected by common.convert
26 check_global_prereq getfacl
27 check_global_prereq setfacl
28 check_global_prereq md5sum
29
30 run_one_test() {
31         local testdir
32         local testname
33
34         testdir="$1"
35         testname=$(basename "$testdir")
36         echo "    [TEST/conv]   $testname"
37         cd "$testdir"
38         echo "=== Entering $testname" >> "$RESULTS"
39         if [ -x test.sh ]; then
40                 # Only support custom test scripts
41                 ./test.sh
42                 if [ $? -ne 0 ]; then
43                         if [[ $TEST_LOG =~ dump ]]; then
44                                 # the logs can be large and may exceed the
45                                 # limits, use 4MB for now
46                                 tail -c 3900000 "$RESULTS"
47                         fi
48                         _fail "test failed for case $testname"
49                 fi
50         else
51                 _fail "custom test script not found"
52         fi
53 }
54
55 # Test special images
56 for i in $(find "$TOP/tests/convert-tests" -maxdepth 1 -mindepth 1 -type d \
57            ${TEST:+-name "$TEST"} | sort)
58 do
59         run_one_test "$i"
60 done