fsx/fsstress: round blocksize properly
[xfstests-dev.git] / tests / generic / 140
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. 140
6 #
7 # Ensuring that mmap copy on write through the page cache works:
8 #   - Reflink two files together
9 #   - Write to the beginning, middle, and end
10 #   - Check that the files are now different where we say they're different.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1    # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23     cd /
24     rm -rf $tmp.* $testdir
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/reflink
31
32 # real QA test starts here
33 _require_test_reflink
34 _require_cp_reflink
35
36 rm -f $seqres.full
37
38 testdir=$TEST_DIR/test-$seq
39 rm -rf $testdir
40 mkdir $testdir
41
42 echo "Create the original files"
43 blksz=65536
44 _pwrite_byte 0x61 0 $((blksz * 48 - 3)) $testdir/file1 >> $seqres.full
45 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
46 _pwrite_byte 0x61 0 $((blksz * 48 - 3)) $testdir/file3 >> $seqres.full
47 _test_cycle_mount
48
49 echo "Compare files"
50 md5sum $testdir/file1 | _filter_test_dir
51 md5sum $testdir/file2 | _filter_test_dir
52 md5sum $testdir/file3 | _filter_test_dir
53
54 cmp -s $testdir/file1 $testdir/file2 || echo "Files 1-2 do not match"
55 cmp -s $testdir/file1 $testdir/file3 || echo "Files 1-3 do not match"
56 cmp -s $testdir/file2 $testdir/file3 || echo "Files 2-3 do not match"
57
58 echo "mmap CoW the second file"
59 _mwrite_byte 0x62 0 17 $((blksz * 48 - 3)) $testdir/file2 >> $seqres.full
60 _mwrite_byte 0x62 0 17 $((blksz * 48 - 3)) $testdir/file3 >> $seqres.full
61
62 _mwrite_byte 0x62 $((blksz * 16 - 34)) 17 $((blksz * 48 - 3)) $testdir/file2 >> $seqres.full
63 _mwrite_byte 0x62 $((blksz * 16 - 34)) 17 $((blksz * 48 - 3)) $testdir/file3 >> $seqres.full
64
65 _mwrite_byte 0x62 $((blksz * 48 - 20)) 17 $((blksz * 48 - 3)) $testdir/file2 >> $seqres.full
66 _mwrite_byte 0x62 $((blksz * 48 - 20)) 17 $((blksz * 48 - 3)) $testdir/file3 >> $seqres.full
67 _test_cycle_mount
68
69 echo "Compare files"
70 md5sum $testdir/file1 | _filter_test_dir
71 md5sum $testdir/file2 | _filter_test_dir
72 md5sum $testdir/file3 | _filter_test_dir
73
74 cmp -s $testdir/file1 $testdir/file2 || echo "Files 1-2 do not match (intentional)"
75 cmp -s $testdir/file1 $testdir/file3 || echo "Files 1-3 do not match (intentional)"
76 cmp -s $testdir/file2 $testdir/file3 || echo "Files 2-3 do not match"
77
78 echo "Compare the CoW'd section to the before file"
79 _compare_range $testdir/file1 0 $testdir/file2 0 17 \
80        || echo "Start sections do not match (intentional)"
81
82 _compare_range  $testdir/file1 $((blksz * 16 - 34)) \
83                 $testdir/file2 $((blksz * 16 - 34)) 17 \
84        || echo "Middle sections do not match (intentional)"
85
86 _compare_range  $testdir/file1 $((blksz * 48 - 20)) \
87                 $testdir/file2 $((blksz * 48 - 20)) 17 \
88        || echo "End sections do not match (intentional)"
89
90 echo "Compare the CoW'd section to the after file"
91 _compare_range $testdir/file2 0 $testdir/file3 0 17 \
92        || echo "Start sections do not match"
93
94 _compare_range  $testdir/file2 $((blksz * 16 - 34)) \
95                 $testdir/file3 $((blksz * 16 - 34)) 17 \
96        || echo "Middle sections do not match"
97
98 _compare_range  $testdir/file2 $((blksz * 48 - 20)) \
99                 $testdir/file3 $((blksz * 48 - 20)) 17 \
100        || echo "End sections do not match"
101
102 echo "Compare the not CoW'd sections"
103 _compare_range $testdir/file1 18 $testdir/file2 18 17 \
104        || echo "Start sections of 1-2 do not match"
105
106 _compare_range $testdir/file2 18 $testdir/file3 18 17 \
107        || echo "Start sections of 2-3 do not match"
108
109
110 _compare_range  $testdir/file1 $((blksz * 16 - 17)) \
111                 $testdir/file2 $((blksz * 16 - 17)) 82 \
112        || echo "Middle sections of 1-2 do not match"
113
114 _compare_range  $testdir/file2 $((blksz * 16 - 17)) \
115                 $testdir/file3 $((blksz * 16 - 17)) 82 \
116        || echo "Middle sections of 2-3 do not match"
117
118 _compare_range  $testdir/file1 $((blksz * 48 - 120)) \
119                 $testdir/file2 $((blksz * 48 - 120)) 100 \
120        || echo "End sections of 1-2 do not match"
121
122 _compare_range  $testdir/file2 $((blksz * 48 - 120)) \
123                 $testdir/file3 $((blksz * 48 - 120)) 100 \
124        || echo "End sections of 2-3 do not match"
125
126
127 _compare_range  $testdir/file1 $((blksz * 14)) \
128                 $testdir/file2 $((blksz * 14)) $blksz \
129        || echo "Untouched sections of 1-2 do not match"
130
131 _compare_range  $testdir/file2 $((blksz * 14)) \
132                 $testdir/file3 $((blksz * 14)) $blksz \
133        || echo "Untouched sections of 2-3 do not match"
134
135 # success, all done
136 status=0
137 exit