5714dc6ca256960830aa528c11bb99f932b57248
[platform/upstream/btrfs-progs.git] / tests / convert-tests / 014-reiserfs-tail-handling / test.sh
1 #!/bin/bash
2 # Check the various combinations of real blocks, holes, and tails
3 # Since it's possible to have a valid extent layout that check will
4 # happily accept AND have garbage in the output, compare the results
5 # as well.
6 # We use separate inputs for tails and real blocks so we can determine
7 # if there was a failure in copying either.
8
9 source "$TEST_TOP/common"
10 source "$TEST_TOP/common.convert"
11
12 if ! check_kernel_support_reiserfs >/dev/null; then
13         _not_run "no reiserfs support"
14 fi
15
16 setup_root_helper
17 prepare_test_dev
18 check_prereq btrfs-convert
19 check_global_prereq md5sum
20 check_global_prereq mkreiserfs
21 check_global_prereq perl
22
23 perl -e "print 'a'x8192;" > input
24 perl -e "print 'b'x8192;" > input2
25
26 default_mkfs="mkreiserfs -b 4096"
27 convert_test_preamble '' 'tail conversion test' 16k "$default_mkfs"
28 convert_test_prep_fs reiserfs $default_mkfs
29
30 # Hole alone
31 run_check $SUDO_HELPER truncate -s 81920 "$TEST_MNT/hole"
32
33 # Tail alone
34 run_check $SUDO_HELPER dd if=input of="$TEST_MNT/1k" bs=1k count=1 \
35                       > /dev/null 2>&1
36
37 # Single indirect block
38 run_check $SUDO_HELPER dd if=input of="$TEST_MNT/4k" bs=1k count=4 \
39                       > /dev/null 2>&1
40
41 # Indirect block + tail
42 run_check $SUDO_HELPER dd if=input of="$TEST_MNT/5k" bs=1k count=4 \
43                       > /dev/null 2>&1
44 run_check $SUDO_HELPER dd if=input2 of="$TEST_MNT/5k" bs=1k count=1 \
45                          seek=4 > /dev/null 2>&1
46
47 # Hole followed by tail
48 run_check $SUDO_HELPER dd if=input of="$TEST_MNT/hole-1k" bs=1k count=1 \
49                          seek=4 > /dev/null 2>&1
50
51 # Indirect block followed by hole
52 run_check $SUDO_HELPER dd if=input of="$TEST_MNT/4k-hole" bs=1k count=4 \
53                       > /dev/null 2>&1
54 run_check $SUDO_HELPER truncate -s 81920 "$TEST_MNT/4k-hole"
55
56 # Indirect block followed by hole followed by tail
57 run_check $SUDO_HELPER dd if=input of="$TEST_MNT/4k-hole-1k" bs=1k count=4 \
58                       > /dev/null 2>&1
59 run_check $SUDO_HELPER truncate -s 8192 "$TEST_MNT/4k-hole-1k"
60 run_check $SUDO_HELPER dd if=input2 of="$TEST_MNT/4k-hole-1k" bs=1k count=1 \
61                          seek=8 > /dev/null 2>&1
62
63 rm -f input input2
64
65 declare -A SUMS
66 for file in "$TEST_MNT"/*; do
67        SUM=$(md5sum "$file")
68        SUMS["$file"]=$SUM
69 done
70
71 run_check_umount_test_dev
72 convert_test_do_convert
73
74 run_check_mount_test_dev
75 for file in "${!SUMS[@]}"; do
76        SUM=$(md5sum "$file")
77        run_check test "$SUM" = "${SUMS[$file]}"
78 done
79 run_check_umount_test_dev