generic: test for non-zero used blocks while writing into a file
[xfstests-dev.git] / tests / generic / 147
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. 812
6 #
7 # Ensure that insert range steps around reflinked ranges:
8 #   - Create three reflink clones of a file
9 #   - Insert into 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 _require_test_reflink
35 _require_cp_reflink
36 _require_xfs_io_command "finsert"
37
38 rm -f $seqres.full
39
40 testdir=$TEST_DIR/test-$seq
41 rm -rf $testdir
42 mkdir $testdir
43
44 echo "Create the original files"
45 blksz=65536
46 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
47 _pwrite_byte 0x62 $blksz $blksz $testdir/file1 >> $seqres.full
48 _pwrite_byte 0x63 $((blksz * 2)) $blksz $testdir/file1 >> $seqres.full
49
50 _cp_reflink $testdir/file1 $testdir/file2
51 _cp_reflink $testdir/file1 $testdir/file3
52 _cp_reflink $testdir/file1 $testdir/file4
53
54 _pwrite_byte 0x00 0 $blksz $testdir/file2.chk >> $seqres.full
55 _pwrite_byte 0x61 $blksz $blksz $testdir/file2.chk >> $seqres.full
56 _pwrite_byte 0x62 $((blksz * 2)) $blksz $testdir/file2.chk >> $seqres.full
57 _pwrite_byte 0x63 $((blksz * 3)) $blksz $testdir/file2.chk >> $seqres.full
58
59 _pwrite_byte 0x61 0 $blksz $testdir/file3.chk >> $seqres.full
60 _pwrite_byte 0x00 $blksz $blksz $testdir/file3.chk >> $seqres.full
61 _pwrite_byte 0x62 $((blksz * 2)) $blksz $testdir/file3.chk >> $seqres.full
62 _pwrite_byte 0x63 $((blksz * 3)) $blksz $testdir/file3.chk >> $seqres.full
63
64 _pwrite_byte 0x61 0 $blksz $testdir/file4.chk >> $seqres.full
65 _pwrite_byte 0x62 $blksz $blksz $testdir/file4.chk >> $seqres.full
66 _pwrite_byte 0x00 $((blksz * 2)) $blksz $testdir/file4.chk >> $seqres.full
67 _pwrite_byte 0x63 $((blksz * 3)) $blksz $testdir/file4.chk >> $seqres.full
68 _test_cycle_mount
69
70 md5sum $testdir/file1 | _filter_test_dir
71 md5sum $testdir/file2 | _filter_test_dir
72 md5sum $testdir/file3 | _filter_test_dir
73 md5sum $testdir/file4 | _filter_test_dir
74 md5sum $testdir/file2.chk | _filter_test_dir
75 md5sum $testdir/file3.chk | _filter_test_dir
76 md5sum $testdir/file4.chk | _filter_test_dir
77
78 c1=$(_md5_checksum $testdir/file1)
79 c2=$(_md5_checksum $testdir/file2)
80 c3=$(_md5_checksum $testdir/file3)
81 c4=$(_md5_checksum $testdir/file4)
82
83 test ${c1} = ${c2} || echo "file1 and file2 should match"
84 test ${c1} = ${c3} || echo "file1 and file3 should match"
85 test ${c1} = ${c4} || echo "file1 and file4 should match"
86 test ${c2} = ${c3} || echo "file2 and file3 should match"
87 test ${c2} = ${c4} || echo "file2 and file4 should match"
88 test ${c3} = ${c4} || echo "file3 and file4 should match"
89
90 echo "finsert files"
91 $XFS_IO_PROG -f -c "finsert 0 $blksz" $testdir/file2
92 $XFS_IO_PROG -f -c "finsert $blksz $blksz" $testdir/file3
93 $XFS_IO_PROG -f -c "finsert $((blksz * 2)) $blksz" $testdir/file4
94 _test_cycle_mount
95
96 echo "Compare files"
97 md5sum $testdir/file1 | _filter_test_dir
98 md5sum $testdir/file2 | _filter_test_dir
99 md5sum $testdir/file3 | _filter_test_dir
100 md5sum $testdir/file4 | _filter_test_dir
101 md5sum $testdir/file2.chk | _filter_test_dir
102 md5sum $testdir/file3.chk | _filter_test_dir
103 md5sum $testdir/file4.chk | _filter_test_dir
104
105 c1=$(_md5_checksum $testdir/file1)
106 c2=$(_md5_checksum $testdir/file2)
107 c3=$(_md5_checksum $testdir/file3)
108 c4=$(_md5_checksum $testdir/file4)
109
110 test ${c1} != ${c2} || echo "file1 and file2 should not match"
111 test ${c1} != ${c3} || echo "file1 and file3 should not match"
112 test ${c1} != ${c4} || echo "file1 and file4 should not match"
113 test ${c2} != ${c3} || echo "file2 and file3 should not match"
114 test ${c2} != ${c4} || echo "file2 and file4 should not match"
115 test ${c3} != ${c4} || echo "file3 and file4 should not match"
116
117 echo "Compare against check files"
118 cmp -s $testdir/file2 $testdir/file2.chk || echo "file2 and file2.chk do not match"
119 cmp -s $testdir/file3 $testdir/file3.chk || echo "file3 and file3.chk do not match"
120 cmp -s $testdir/file4 $testdir/file4.chk || echo "file4 and file4.chk do not match"
121
122 # success, all done
123 status=0
124 exit