generic/138,139,140: fix the name for check file
[xfstests-dev.git] / tests / generic / 139
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. 139
6 #
7 # Ensuring that copy on write in direct-io mode works:
8 #   - Reflink two files together
9 #   - Write to the beginning, middle, and end in direct-io mode
10 #   - Check that the files are now different where we say they're different.
11 #
12 . ./common/preamble
13 _begin_fstest auto quick clone
14
15 # Override the default cleanup function.
16 _cleanup()
17 {
18     cd /
19     rm -rf $tmp.* $testdir
20 }
21
22 # Import common functions.
23 . ./common/filter
24 . ./common/reflink
25
26 # real QA test starts here
27 _require_test_reflink
28 _require_cp_reflink
29 _require_odirect
30
31 testdir=$TEST_DIR/test-$seq
32 rm -rf $testdir
33 mkdir $testdir
34
35 echo "Create the original files"
36 blksz=65536
37 _pwrite_byte 0x61 0 $((blksz * 48 - 3)) $testdir/file1 >> $seqres.full
38 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
39 _pwrite_byte 0x61 0 $((blksz * 48 - 3)) $testdir/file2.chk >> $seqres.full
40 _test_cycle_mount
41
42 echo "Compare files"
43 md5sum $testdir/file1 | _filter_test_dir
44 md5sum $testdir/file2 | _filter_test_dir
45 md5sum $testdir/file2.chk | _filter_test_dir
46
47 cmp -s $testdir/file1 $testdir/file2 || echo "file1 and file2 should match"
48 cmp -s $testdir/file1 $testdir/file2.chk || echo "file1 and file2.chk should match"
49 cmp -s $testdir/file2 $testdir/file2.chk || echo "file2 and file2.chk should match"
50
51 echo "directio CoW the second file"
52 _pwrite_byte 0x62 0 $blksz $testdir/file2 -d >> $seqres.full
53 _pwrite_byte 0x62 0 $blksz $testdir/file2.chk -d >> $seqres.full
54
55 _pwrite_byte 0x62 $((blksz * 16 - 512)) 512 $testdir/file2 -d >> $seqres.full
56 _pwrite_byte 0x62 $((blksz * 16 - 512)) 512 $testdir/file2.chk -d >> $seqres.full
57
58 _pwrite_byte 0x62 $((blksz * 48)) $blksz $testdir/file2 -d >> $seqres.full
59 _pwrite_byte 0x62 $((blksz * 48)) $blksz $testdir/file2.chk -d >> $seqres.full
60 _test_cycle_mount
61
62 echo "Compare files"
63 md5sum $testdir/file1 | _filter_test_dir
64 md5sum $testdir/file2 | _filter_test_dir
65 md5sum $testdir/file2.chk | _filter_test_dir
66
67 cmp -s $testdir/file1 $testdir/file2 || echo "file1 and file2 should not match (intentional)"
68 cmp -s $testdir/file1 $testdir/file2.chk || echo "file1 and file2.chk should not match (intentional)"
69 cmp -s $testdir/file2 $testdir/file2.chk || echo "file2 and file2.chk should match"
70
71 echo "Compare the CoW'd section to the before file"
72 _compare_range $testdir/file1 0 $testdir/file2 0 $blksz \
73        || echo "Start sections do not match (intentional)"
74
75 _compare_range  $testdir/file1 $((blksz * 16 - 512)) \
76                 $testdir/file2 $((blksz * 16 - 512)) 512 \
77        || echo "Middle sections do not match (intentional)"
78
79 _compare_range  $testdir/file1 $((blksz * 48 - 512)) \
80                 $testdir/file2 $((blksz * 48 - 512)) $blksz \
81        || echo "End sections do not match (intentional)"
82
83 echo "Compare the CoW'd section to the after file"
84 _compare_range $testdir/file2 0 $testdir/file2.chk 0 $blksz \
85        || echo "Start sections do not match"
86
87 _compare_range  $testdir/file2 $((blksz * 16 - 512)) \
88                 $testdir/file2.chk $((blksz * 16 - 512)) 512 \
89        || echo "Middle sections do not match"
90
91 _compare_range  $testdir/file2 $((blksz * 48 - 512)) \
92                 $testdir/file2.chk $((blksz * 48 - 512)) $blksz \
93        || echo "End sections do not match"
94
95 echo "Compare the not CoW'd sections"
96 _compare_range $testdir/file1 $blksz $testdir/file2 $blksz 512 \
97        || echo "Start sections of file1 and file2 do not match"
98 _compare_range $testdir/file2 $blksz $testdir/file2.chk $blksz 512 \
99        || echo "Start sections of file2 and file2.chk do not match"
100
101 _compare_range  $testdir/file1 $((blksz * 16 - 1024)) \
102                 $testdir/file2 $((blksz * 16 - 1024)) 512 \
103        || echo "Middle sections of file1 and file2 do not match"
104
105 _compare_range  $testdir/file2 $((blksz * 16 - 1024)) \
106                 $testdir/file2.chk $((blksz * 16 - 1024)) 512 \
107        || echo "Middle sections of file2 and file2.chk do not match"
108
109 _compare_range  $testdir/file1 $((blksz * 48 - 1024)) \
110                 $testdir/file2 $((blksz * 48 - 1024)) 512 \
111        || echo "End sections of file1 and file2 do not match"
112
113 _compare_range  $testdir/file2 $((blksz * 48 - 1024)) \
114                 $testdir/file2.chk $((blksz * 48 - 1024)) 512 \
115        || echo "End sections of file2 and file2.chk do not match"
116
117 _compare_range  $testdir/file1 $((blksz * 16)) \
118                 $testdir/file2 $((blksz * 16)) 512 \
119        || echo "Untouched sections of file1 and file2 do not match"
120
121 _compare_range  $testdir/file2 $((blksz * 16)) \
122                 $testdir/file2.chk $((blksz * 16)) 512 \
123        || echo "Untouched sections of file2 and file2.chk do not match"
124
125 # success, all done
126 status=0
127 exit