btrfs-progs: tests: convert/014 use shell builtin for generating content
[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
22 printf "%0.sa" {1..8192} > input
23 printf "%0.sb" {1..8192} > input2
24
25 default_mkfs="mkreiserfs -b 4096"
26 convert_test_preamble '' 'tail conversion test' 16k "$default_mkfs"
27 convert_test_prep_fs reiserfs $default_mkfs
28
29 # Hole alone
30 run_check $SUDO_HELPER truncate -s 81920 "$TEST_MNT/hole"
31
32 # Tail alone
33 run_check $SUDO_HELPER dd if=input of="$TEST_MNT/1k" bs=1k count=1 \
34                       > /dev/null 2>&1
35
36 # Single indirect block
37 run_check $SUDO_HELPER dd if=input of="$TEST_MNT/4k" bs=1k count=4 \
38                       > /dev/null 2>&1
39
40 # Indirect block + tail
41 run_check $SUDO_HELPER dd if=input of="$TEST_MNT/5k" bs=1k count=4 \
42                       > /dev/null 2>&1
43 run_check $SUDO_HELPER dd if=input2 of="$TEST_MNT/5k" bs=1k count=1 \
44                          seek=4 > /dev/null 2>&1
45
46 # Hole followed by tail
47 run_check $SUDO_HELPER dd if=input of="$TEST_MNT/hole-1k" bs=1k count=1 \
48                          seek=4 > /dev/null 2>&1
49
50 # Indirect block followed by hole
51 run_check $SUDO_HELPER dd if=input of="$TEST_MNT/4k-hole" bs=1k count=4 \
52                       > /dev/null 2>&1
53 run_check $SUDO_HELPER truncate -s 81920 "$TEST_MNT/4k-hole"
54
55 # Indirect block followed by hole followed by tail
56 run_check $SUDO_HELPER dd if=input of="$TEST_MNT/4k-hole-1k" bs=1k count=4 \
57                       > /dev/null 2>&1
58 run_check $SUDO_HELPER truncate -s 8192 "$TEST_MNT/4k-hole-1k"
59 run_check $SUDO_HELPER dd if=input2 of="$TEST_MNT/4k-hole-1k" bs=1k count=1 \
60                          seek=8 > /dev/null 2>&1
61
62 rm -f input input2
63
64 declare -A SUMS
65 for file in "$TEST_MNT"/*; do
66        SUM=$(md5sum "$file")
67        SUMS["$file"]=$SUM
68 done
69
70 run_check_umount_test_dev
71 convert_test_do_convert
72
73 run_check_mount_test_dev
74 for file in "${!SUMS[@]}"; do
75        SUM=$(md5sum "$file")
76        run_check test "$SUM" = "${SUMS[$file]}"
77 done
78 run_check_umount_test_dev