reflink: basic tests of the reflink and dedupe ioctls
[xfstests-dev.git] / tests / generic / 136
1 #! /bin/bash
2 # FS QA Test No. 136
3 #
4 # Ensure that we can dedupe the last block of a file whose size isn't
5 # block-aligned.
6 #   - Create two 'a' files file whose size isn't block-aligned.
7 #   - Create two 'b' files file whose size isn't block-aligned.
8 #   - Dedupe the last block of file1 to the last block in file2 and file3.
9 #   - Check that files 1-2 match, and that 3-4 match.
10 #   - Check that the ends of 1-2 and 3-4 match, and that 1-3 don't match.
11 #
12 #-----------------------------------------------------------------------
13 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
14 #
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License as
17 # published by the Free Software Foundation.
18 #
19 # This program is distributed in the hope that it would be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write the Free Software Foundation,
26 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
27 #-----------------------------------------------------------------------
28
29 seq=`basename "$0"`
30 seqres="$RESULT_DIR/$seq"
31 echo "QA output created by $seq"
32
33 here=`pwd`
34 tmp=/tmp/$$
35 status=1    # failure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
37
38 _cleanup()
39 {
40     cd /
41     rm -rf "$tmp".* "$TESTDIR"
42 }
43
44 # get standard environment, filters and checks
45 . ./common/rc
46 . ./common/filter
47 . ./common/reflink
48
49 # real QA test starts here
50 _supported_os Linux
51 _require_test_dedupe
52
53 rm -f "$seqres.full"
54
55 TESTDIR="$TEST_DIR/test-$seq"
56 rm -rf "$TESTDIR"
57 mkdir "$TESTDIR"
58
59 echo "Create the original files"
60 BLKSZ=65536
61 _pwrite_byte 0x61 0 $((BLKSZ + 37)) "$TESTDIR/file1" >> "$seqres.full"
62 _pwrite_byte 0x61 0 $((BLKSZ + 37)) "$TESTDIR/file2" >> "$seqres.full"
63 _pwrite_byte 0x62 0 $((BLKSZ + 37)) "$TESTDIR/file3" >> "$seqres.full"
64 _pwrite_byte 0x62 0 $((BLKSZ + 37)) "$TESTDIR/file4" >> "$seqres.full"
65 _test_remount
66
67 md5sum "$TESTDIR/file1" | _filter_test_dir
68 md5sum "$TESTDIR/file2" | _filter_test_dir
69 md5sum "$TESTDIR/file3" | _filter_test_dir
70 md5sum "$TESTDIR/file4" | _filter_test_dir
71
72 C1="$(_md5_checksum $TESTDIR/file1)"
73 C2="$(_md5_checksum $TESTDIR/file2)"
74 C3="$(_md5_checksum $TESTDIR/file3)"
75 C4="$(_md5_checksum $TESTDIR/file4)"
76
77 test "${C1}" = "${C2}" || echo "file1 and file2 should match"
78 test "${C1}" != "${C3}" || echo "file1 and file3 should not match"
79 test "${C1}" != "${C4}" || echo "file1 and file4 should not match"
80 test "${C2}" != "${C3}" || echo "file2 and file3 should not match"
81 test "${C2}" != "${C4}" || echo "file2 and file4 should not match"
82 test "${C3}" = "${C4}" || echo "file3 and file4 should match"
83
84 echo "Dedupe the last blocks together"
85 _dedupe_range "$TESTDIR/file1" $BLKSZ "$TESTDIR/file2" $BLKSZ 37 >> "$seqres.full"
86 _dedupe_range "$TESTDIR/file1" $BLKSZ "$TESTDIR/file3" $BLKSZ 37 >> "$seqres.full"
87 _test_remount
88
89 md5sum "$TESTDIR/file1" | _filter_test_dir
90 md5sum "$TESTDIR/file2" | _filter_test_dir
91 md5sum "$TESTDIR/file3" | _filter_test_dir
92 md5sum "$TESTDIR/file4" | _filter_test_dir
93
94 C1="$(_md5_checksum $TESTDIR/file1)"
95 C2="$(_md5_checksum $TESTDIR/file2)"
96 C3="$(_md5_checksum $TESTDIR/file3)"
97 C4="$(_md5_checksum $TESTDIR/file4)"
98
99 echo "Compare files"
100 test "${C1}" = "${C2}" || echo "file1 and file2 should match"
101 test "${C1}" != "${C3}" || echo "file1 and file3 should not match"
102 test "${C1}" != "${C4}" || echo "file1 and file4 should not match"
103 test "${C2}" != "${C3}" || echo "file2 and file3 should not match"
104 test "${C2}" != "${C4}" || echo "file2 and file4 should not match"
105 test "${C3}" = "${C4}" || echo "file3 and file4 should match"
106
107 echo "Compare sections"
108 _compare_range "$TESTDIR/file1" $BLKSZ "$TESTDIR/file2" $BLKSZ 37 \
109        || echo "End sections of files 1-2 do not match"
110
111 _compare_range "$TESTDIR/file1" $BLKSZ "$TESTDIR/file3" $BLKSZ 37 \
112        || echo "End sections of files 1-3 do not match (intentional)"
113
114 _compare_range "$TESTDIR/file1" $BLKSZ "$TESTDIR/file4" $BLKSZ 37 \
115        || echo "End sections of files 1-4 do not match (intentional)"
116
117 _compare_range "$TESTDIR/file2" $BLKSZ "$TESTDIR/file3" $BLKSZ 37 \
118        || echo "End sections of files 2-3 do not match (intentional)"
119
120 _compare_range "$TESTDIR/file2" $BLKSZ "$TESTDIR/file4" $BLKSZ 37 \
121        || echo "End sections of files 2-4 do not match (intentional)"
122
123 _compare_range "$TESTDIR/file3" $BLKSZ "$TESTDIR/file4" $BLKSZ 37 \
124        || echo "End sections of files 3-4 do not match"
125
126 # success, all done
127 status=0
128 exit