generic/520: Remove sync in clean_dir
[xfstests-dev.git] / tests / generic / 136
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 136
6 #
7 # Ensure that we can dedupe the last block of a file whose size isn't
8 # block-aligned.
9 #   - Create two 'a' files file whose size isn't block-aligned.
10 #   - Create two 'b' files file whose size isn't block-aligned.
11 #   - Dedupe the last block of file1 to the last block in file2 and file3.
12 #   - Check that files 1-2 match, and that 3-4 match.
13 #   - Check that the ends of 1-2 and 3-4 match, and that 1-3 don't match.
14 #
15 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 tmp=/tmp/$$
21 status=1    # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
23
24 _cleanup()
25 {
26     cd /
27     rm -rf $tmp.* $testdir
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33 . ./common/reflink
34
35 # real QA test starts here
36 _supported_os Linux
37 _require_test_dedupe
38
39 rm -f $seqres.full
40
41 testdir=$TEST_DIR/test-$seq
42 rm -rf $testdir
43 mkdir $testdir
44
45 echo "Create the original files"
46 blksz=65536
47 _pwrite_byte 0x61 0 $((blksz + 37)) $testdir/file1 >> $seqres.full
48 _pwrite_byte 0x61 0 $((blksz + 37)) $testdir/file2 >> $seqres.full
49 _pwrite_byte 0x62 0 $((blksz + 37)) $testdir/file3 >> $seqres.full
50 _pwrite_byte 0x62 0 $((blksz + 37)) $testdir/file4 >> $seqres.full
51 _test_cycle_mount
52
53 md5sum $testdir/file1 | _filter_test_dir
54 md5sum $testdir/file2 | _filter_test_dir
55 md5sum $testdir/file3 | _filter_test_dir
56 md5sum $testdir/file4 | _filter_test_dir
57
58 c1="$(_md5_checksum $testdir/file1)"
59 c2="$(_md5_checksum $testdir/file2)"
60 c3="$(_md5_checksum $testdir/file3)"
61 c4="$(_md5_checksum $testdir/file4)"
62
63 test ${c1} = ${c2} || echo "file1 and file2 should match"
64 test ${c1} != ${c3} || echo "file1 and file3 should not match"
65 test ${c1} != ${c4} || echo "file1 and file4 should not match"
66 test ${c2} != ${c3} || echo "file2 and file3 should not match"
67 test ${c2} != ${c4} || echo "file2 and file4 should not match"
68 test ${c3} = ${c4} || echo "file3 and file4 should match"
69
70 echo "Dedupe the last blocks together"
71 echo "1->2"
72 _dedupe_range $testdir/file1 $blksz $testdir/file2 $blksz 37 >> $seqres.full
73 echo "1->3"
74 _dedupe_range $testdir/file1 $blksz $testdir/file3 $blksz 37 2>&1 | _filter_dedupe_error
75 _test_cycle_mount
76
77 md5sum $testdir/file1 | _filter_test_dir
78 md5sum $testdir/file2 | _filter_test_dir
79 md5sum $testdir/file3 | _filter_test_dir
80 md5sum $testdir/file4 | _filter_test_dir
81
82 c1="$(_md5_checksum $testdir/file1)"
83 c2="$(_md5_checksum $testdir/file2)"
84 c3="$(_md5_checksum $testdir/file3)"
85 c4="$(_md5_checksum $testdir/file4)"
86
87 echo "Compare files"
88 test ${c1} = ${c2} || echo "file1 and file2 should match"
89 test ${c1} != ${c3} || echo "file1 and file3 should not match"
90 test ${c1} != ${c4} || echo "file1 and file4 should not match"
91 test ${c2} != ${c3} || echo "file2 and file3 should not match"
92 test ${c2} != ${c4} || echo "file2 and file4 should not match"
93 test ${c3} = ${c4} || echo "file3 and file4 should match"
94
95 echo "Compare sections"
96 _compare_range $testdir/file1 $blksz $testdir/file2 $blksz 37 \
97        || echo "End sections of files 1-2 do not match"
98
99 _compare_range $testdir/file1 $blksz $testdir/file3 $blksz 37 \
100        || echo "End sections of files 1-3 do not match (intentional)"
101
102 _compare_range $testdir/file1 $blksz $testdir/file4 $blksz 37 \
103        || echo "End sections of files 1-4 do not match (intentional)"
104
105 _compare_range $testdir/file2 $blksz $testdir/file3 $blksz 37 \
106        || echo "End sections of files 2-3 do not match (intentional)"
107
108 _compare_range $testdir/file2 $blksz $testdir/file4 $blksz 37 \
109        || echo "End sections of files 2-4 do not match (intentional)"
110
111 _compare_range $testdir/file3 $blksz $testdir/file4 $blksz 37 \
112        || echo "End sections of files 3-4 do not match"
113
114 # success, all done
115 status=0
116 exit