generic: copy_file_range swapfile test
[xfstests-dev.git] / tests / generic / 118
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. 118
6 #
7 # Ensuring that we can reflink non-matching parts of files:
8 #   - Reflink identical ranges of two different files
9 #   - Check that the non-linked ranges still do not match
10 #   - Check that we end up with identical contents in the linked ranges
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 _supported_os Linux
34 _require_test_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 $((blksz * 2)) $((blksz * 6)) $testdir/file1 >> $seqres.full
45 _pwrite_byte 0x62 $((blksz * 2)) $((blksz * 6)) $testdir/file2 >> $seqres.full
46 _test_cycle_mount
47
48 md5sum $testdir/file1 | _filter_test_dir
49 md5sum $testdir/file2 | _filter_test_dir
50
51 _compare_range $testdir/file1 0 $testdir/file2 0 $((blksz * 8)) \
52        || echo "Files do not match (intentional)"
53
54 echo "Reflink the middle blocks together"
55 free_before=$(stat -f -c '%a' $testdir)
56 _reflink_range $testdir/file1 $((blksz * 4)) $testdir/file2 \
57                 $((blksz * 4)) $((blksz * 2)) >> $seqres.full
58 _test_cycle_mount
59 free_after=$(stat -f -c '%a' $testdir)
60 echo "freesp changed by $free_before -> $free_after" >> $seqres.full
61
62 echo "Compare sections"
63 md5sum $testdir/file1 | _filter_test_dir
64 md5sum $testdir/file2 | _filter_test_dir
65
66 _compare_range $testdir/file1 0 $testdir/file2 0 $((blksz * 4)) \
67        || echo "Start sections do not match (intentional)"
68
69 _compare_range $testdir/file1 $((blksz * 4)) $testdir/file2 \
70                 $((blksz * 4)) $((blksz * 2)) \
71        || echo "Middle sections do not match"
72
73 _compare_range $testdir/file1 $((blksz * 6)) $testdir/file2 \
74                 $((blksz * 6)) $((blksz * 2)) \
75        || echo "End sections do not match (intentional)"
76
77 # success, all done
78 status=0
79 exit