generic/405: test mkfs against thin provision device
[xfstests-dev.git] / tests / generic / 118
1 #! /bin/bash
2 # FS QA Test No. 118
3 #
4 # Ensuring that we can reflink non-matching parts of files:
5 #   - Reflink identical ranges of two different files
6 #   - Check that the non-linked ranges still do not match
7 #   - Check that we end up with identical contents in the linked ranges
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1    # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37     cd /
38     rm -rf $tmp.* $testdir
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44 . ./common/reflink
45
46 # real QA test starts here
47 _supported_os Linux
48 _require_test_reflink
49
50 rm -f $seqres.full
51
52 testdir=$TEST_DIR/test-$seq
53 rm -rf $testdir
54 mkdir $testdir
55
56 echo "Create the original files"
57 blksz=65536
58 _pwrite_byte 0x61 $((blksz * 2)) $((blksz * 6)) $testdir/file1 >> $seqres.full
59 _pwrite_byte 0x62 $((blksz * 2)) $((blksz * 6)) $testdir/file2 >> $seqres.full
60 _test_cycle_mount
61
62 md5sum $testdir/file1 | _filter_test_dir
63 md5sum $testdir/file2 | _filter_test_dir
64
65 _compare_range $testdir/file1 0 $testdir/file2 0 $((blksz * 8)) \
66        || echo "Files do not match (intentional)"
67
68 echo "Reflink the middle blocks together"
69 free_before=$(stat -f -c '%a' $testdir)
70 _reflink_range $testdir/file1 $((blksz * 4)) $testdir/file2 \
71                 $((blksz * 4)) $((blksz * 2)) >> $seqres.full
72 _test_cycle_mount
73 free_after=$(stat -f -c '%a' $testdir)
74 echo "freesp changed by $free_before -> $free_after" >> $seqres.full
75
76 echo "Compare sections"
77 md5sum $testdir/file1 | _filter_test_dir
78 md5sum $testdir/file2 | _filter_test_dir
79
80 _compare_range $testdir/file1 0 $testdir/file2 0 $((blksz * 4)) \
81        || echo "Start sections do not match (intentional)"
82
83 _compare_range $testdir/file1 $((blksz * 4)) $testdir/file2 \
84                 $((blksz * 4)) $((blksz * 2)) \
85        || echo "Middle sections do not match"
86
87 _compare_range $testdir/file1 $((blksz * 6)) $testdir/file2 \
88                 $((blksz * 6)) $((blksz * 2)) \
89        || echo "End sections do not match (intentional)"
90
91 # success, all done
92 status=0
93 exit