common/fuzzy: try to clear blocking flags first in _scratch_fuzz_modify
[xfstests-dev.git] / tests / generic / 145
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. 145
6 #
7 # Ensure that collapse range steps around reflinked ranges:
8 #   - Create three reflink clones of a file
9 #   - Collapse the start, middle, and end of the reflink range of each
10 #     of the three files, respectively
11 #   - Check that the reflinked areas are still there.
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1    # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24     cd /
25     rm -rf $tmp.* $testdir
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31 . ./common/reflink
32
33 # real QA test starts here
34 _supported_os Linux
35 _require_test_reflink
36 _require_cp_reflink
37 _require_xfs_io_command "falloc"
38 _require_xfs_io_command "fcollapse"
39
40 rm -f $seqres.full
41
42 testdir=$TEST_DIR/test-$seq
43 rm -rf $testdir
44 mkdir $testdir
45
46 echo "Create the original files"
47 blksz=65536
48 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
49 _pwrite_byte 0x62 $blksz $blksz $testdir/file1 >> $seqres.full
50 _pwrite_byte 0x63 $((blksz * 2)) $blksz $testdir/file1 >> $seqres.full
51
52 _cp_reflink $testdir/file1 $testdir/file2
53 _cp_reflink $testdir/file1 $testdir/file3
54 _cp_reflink $testdir/file1 $testdir/file4
55
56 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 4))" $testdir/file1
57 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 4))" $testdir/file2
58 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 4))" $testdir/file3
59 $XFS_IO_PROG -f -c "falloc 0 $((blksz * 4))" $testdir/file4
60
61 _pwrite_byte 0x62 0 $blksz $testdir/file2.chk >> $seqres.full
62 _pwrite_byte 0x63 $blksz $blksz $testdir/file2.chk >> $seqres.full
63 _pwrite_byte 0x00 $((blksz * 2)) $blksz $testdir/file2.chk >> $seqres.full
64
65 _pwrite_byte 0x61 0 $blksz $testdir/file3.chk >> $seqres.full
66 _pwrite_byte 0x63 $blksz $blksz $testdir/file3.chk >> $seqres.full
67 _pwrite_byte 0x00 $((blksz * 2)) $blksz $testdir/file3.chk >> $seqres.full
68
69 _pwrite_byte 0x61 0 $blksz $testdir/file4.chk >> $seqres.full
70 _pwrite_byte 0x62 $blksz $blksz $testdir/file4.chk >> $seqres.full
71 _pwrite_byte 0x00 $((blksz * 2)) $blksz $testdir/file4.chk >> $seqres.full
72 _test_cycle_mount
73
74 md5sum $testdir/file1 | _filter_test_dir
75 md5sum $testdir/file2 | _filter_test_dir
76 md5sum $testdir/file3 | _filter_test_dir
77 md5sum $testdir/file4 | _filter_test_dir
78 md5sum $testdir/file2.chk | _filter_test_dir
79 md5sum $testdir/file3.chk | _filter_test_dir
80 md5sum $testdir/file4.chk | _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 test ${c1} = ${c2} || echo "file1 and file2 should match"
88 test ${c1} = ${c3} || echo "file1 and file3 should match"
89 test ${c1} = ${c4} || echo "file1 and file4 should match"
90 test ${c2} = ${c3} || echo "file2 and file3 should match"
91 test ${c2} = ${c4} || echo "file2 and file4 should match"
92 test ${c3} = ${c4} || echo "file3 and file4 should match"
93
94 echo "fcollapse files"
95 $XFS_IO_PROG -f -c "fcollapse 0 $blksz" $testdir/file2
96 $XFS_IO_PROG -f -c "fcollapse $blksz $blksz" $testdir/file3
97 $XFS_IO_PROG -f -c "fcollapse $((blksz * 2)) $blksz" $testdir/file4
98 _test_cycle_mount
99
100 echo "Compare files"
101 md5sum $testdir/file1 | _filter_test_dir
102 md5sum $testdir/file2 | _filter_test_dir
103 md5sum $testdir/file3 | _filter_test_dir
104 md5sum $testdir/file4 | _filter_test_dir
105 md5sum $testdir/file2.chk | _filter_test_dir
106 md5sum $testdir/file3.chk | _filter_test_dir
107 md5sum $testdir/file4.chk | _filter_test_dir
108
109 c1=$(_md5_checksum $testdir/file1)
110 c2=$(_md5_checksum $testdir/file2)
111 c3=$(_md5_checksum $testdir/file3)
112 c4=$(_md5_checksum $testdir/file4)
113
114 test ${c1} != ${c2} || echo "file1 and file2 should not match"
115 test ${c1} != ${c3} || echo "file1 and file3 should not match"
116 test ${c1} != ${c4} || echo "file1 and file4 should not match"
117 test ${c2} != ${c3} || echo "file2 and file3 should not match"
118 test ${c2} != ${c4} || echo "file2 and file4 should not match"
119 test ${c3} != ${c4} || echo "file3 and file4 should not match"
120
121 echo "Compare against check files"
122 cmp -s $testdir/file2 $testdir/file2.chk || echo "file2 and file2.chk do not match"
123 cmp -s $testdir/file3 $testdir/file3.chk || echo "file3 and file3.chk do not match"
124 cmp -s $testdir/file4 $testdir/file4.chk || echo "file4 and file4.chk do not match"
125
126 # success, all done
127 status=0
128 exit