btrfs-progs: introduce TEST_TOP and INTERNAL_BIN for tests
[platform/upstream/btrfs-progs.git] / tests / misc-tests / 016-send-clone-src / test.sh
1 #!/bin/bash
2 #
3 # test for sending stream size of clone-src option, compare against a send
4 # stream generated by buggy version
5
6 source "$TEST_TOP/common"
7
8 check_prereq mkfs.btrfs
9 check_prereq btrfs
10
11 setup_root_helper
12
13 prepare_test_dev
14 run_check "$TOP/mkfs.btrfs" -f "$TEST_DEV"
15 run_check_mount_test_dev
16
17 here=`pwd`
18 cd "$TEST_MNT" || _fail "cannot chdir to TEST_MNT"
19
20 run_check $SUDO_HELPER $TOP/btrfs subvolume create subv-parent1
21 for i in 1 2 3; do
22         run_check $SUDO_HELPER dd if=/dev/zero of=subv-parent1/file1_$i bs=1M count=1
23         run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot -r subv-parent1 subv-snap1_$i
24 done
25
26 run_check $SUDO_HELPER $TOP/btrfs subvolume create subv-parent2
27 for i in 1 2 3; do
28         run_check $SUDO_HELPER dd if=/dev/zero of=subv-parent2/file2_$i bs=1M count=1
29         run_check $SUDO_HELPER $TOP/btrfs subvolume snapshot -r subv-parent2 subv-snap2_$i
30 done
31
32 truncate -s0 "$here"/send-stream.img
33 chmod a+w "$here"/send-stream.img
34 run_check $SUDO_HELPER $TOP/btrfs send -f "$here"/send-stream.img \
35         -c subv-snap1_1 -c subv-snap2_1 subv-snap1_[23] subv-snap2_[23]
36
37 image=$(extract_image "$here"/multi-clone-src-v4.8.2.stream.xz)
38 old_stream_size=`stat --format=%s "$image"`
39 stream_size=`stat --format=%s "$here"/send-stream.img`
40
41 if [ $old_stream_size -lt $stream_size ]; then
42         run_check ls -l "$image" "$here"/send-stream.img
43         _fail "sending stream size is bigger than old stream"
44 fi
45
46 run_check rm -f -- "$image" "$here"/send-stream.img
47
48 cd "$here" || _fail "cannot chdir back to test directory"
49
50 run_check_umount_test_dev