fsx/fsstress: round blocksize properly
[xfstests-dev.git] / tests / generic / 142
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. 142
6 #
7 # Ensure that reflinking a file N times and CoWing the copies leaves the
8 # original intact.
9 #   - Create a file and record its hash
10 #   - Create some reflink copies
11 #   - Rewrite all the reflink copies
12 #   - Compare the contents of the original file
13 #
14 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17
18 here=`pwd`
19 tmp=/tmp/$$
20 status=1    # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
22
23 _cleanup()
24 {
25     cd /
26     rm -rf $tmp.* $testdir
27 }
28
29 # get standard environment, filters and checks
30 . ./common/rc
31 . ./common/filter
32 . ./common/reflink
33
34 # real QA test starts here
35 _require_test_reflink
36 _require_cp_reflink
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 file blocks"
45 blksz=65536
46 nr=9
47 filesize=$((blksz * nr))
48 _pwrite_byte 0x61 0 $((blksz * 256)) $testdir/file1 >> $seqres.full
49 _test_cycle_mount
50
51 md5sum $testdir/file1 | _filter_test_dir
52 csum=$(_md5_checksum $testdir/file1)
53
54 echo "Create the reflink copies"
55 seq 2 $nr | while read i; do
56         _cp_reflink $testdir/file1 $testdir/file$i
57 done
58 _test_cycle_mount
59
60 echo "Rewrite the copies"
61 seq 2 $nr | while read i; do
62         _pwrite_byte 0x62 0 $((blksz * 256)) $testdir/file$i >> $seqres.full
63 done
64 _test_cycle_mount
65
66 echo "Examine original file"
67 md5sum $testdir/file1 | _filter_test_dir
68 md5sum $testdir/file2 | _filter_test_dir
69
70 mod_csum=$(_md5_checksum $testdir/file2)
71 new_csum=$(_md5_checksum $testdir/file1)
72 test ${csum} != ${mod_csum} || echo "checksums do not match"
73 test ${csum} = ${new_csum} || echo "checksums do not match"
74
75 # success, all done
76 status=0
77 exit