2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates. All Rights Reserved.
7 # Ensure that we can reflink the last block of a file whose size isn't
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 # - Reflink the last block of file1 to the last block in file2 and file3.
12 # - Check that files 1-2 match, 3-4 don't match, and that nothing matches 3.
13 # - Check that the ends of 1-3 match, and 1-3 do not match the end of file4.
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
21 status=1 # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
27 rm -rf $tmp.* $testdir
30 # get standard environment, filters and checks
35 # real QA test starts here
41 testdir=$TEST_DIR/test-$seq
45 echo "Create the original files"
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
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
58 c1="$(_md5_checksum $testdir/file1)"
59 c2="$(_md5_checksum $testdir/file2)"
60 c3="$(_md5_checksum $testdir/file3)"
61 c4="$(_md5_checksum $testdir/file4)"
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"
70 echo "Reflink the last blocks together, 1-2 1-3"
71 _reflink_range $testdir/file1 $blksz $testdir/file2 $blksz 37 >> $seqres.full
72 _reflink_range $testdir/file1 $blksz $testdir/file3 $blksz 37 >> $seqres.full
75 md5sum $testdir/file1 | _filter_test_dir
76 md5sum $testdir/file2 | _filter_test_dir
77 md5sum $testdir/file3 | _filter_test_dir
78 md5sum $testdir/file4 | _filter_test_dir
80 c1="$(_md5_checksum $testdir/file1)"
81 c2="$(_md5_checksum $testdir/file2)"
82 c3="$(_md5_checksum $testdir/file3)"
83 c4="$(_md5_checksum $testdir/file4)"
86 test ${c1} = ${c2} || echo "file1 and file2 should match"
87 test ${c1} != ${c3} || echo "file1 and file3 should not match"
88 test ${c1} != ${c4} || echo "file1 and file4 should not match"
89 test ${c2} != ${c3} || echo "file2 and file3 should not match"
90 test ${c2} != ${c4} || echo "file2 and file4 should not match"
91 test ${c3} != ${c4} || echo "file3 and file4 should match"
93 echo "Compare sections"
94 _compare_range $testdir/file1 $blksz $testdir/file2 $blksz 37 \
95 || echo "End sections of files 1-2 do not match"
97 _compare_range $testdir/file1 $blksz $testdir/file3 $blksz 37 \
98 || echo "End sections of files 1-3 do not match"
100 _compare_range $testdir/file1 $blksz $testdir/file4 $blksz 37 \
101 || echo "End sections of files 1-4 do not match (intentional)"
103 _compare_range $testdir/file2 $blksz $testdir/file3 $blksz 37 \
104 || echo "End sections of files 2-3 do not match"
106 _compare_range $testdir/file2 $blksz $testdir/file4 $blksz 37 \
107 || echo "End sections of files 2-4 do not match (intentional)"
109 _compare_range $testdir/file3 $blksz $testdir/file4 $blksz 37 \
110 || echo "End sections of files 3-4 do not match (intentional)"