fstests: move test group info to test files
[xfstests-dev.git] / tests / generic / 404
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Roman Penyaev.  All Rights Reserved.
4 #
5 # FS QA Test 404
6 #
7 # Regression test which targets two nasty ext4 bugs in a logic which
8 # shifts extents:
9 #
10 # 1) 14d981f468a1 ("ext4: Include forgotten start block on fallocate insert range")
11 #
12 # An incorrect right shift (insert range) for the first extent in
13 # a range.
14 #
15 # Test tries to insert many blocks at the same offset to reproduce
16 # the following layout:
17 #
18 #    block #0  block #1
19 #    |ext0 ext1|ext2 ext3 ...|
20 #         ^
21 #      insert of a new block
22 #
23 # Because of an incorrect range first block is never reached,
24 # thus ext1 is untouched, resulting to a hole at a wrong offset:
25 #
26 # What we got:
27 #
28 #    block #0   block #1
29 #    |ext0 ext1|   ext2 ext3 ...|
30 #               ^
31 #               hole at a wrong offset
32 #
33 # What we expect:
34 #
35 #    block #0    block #1
36 #    |ext0   ext1|ext2 ext3 ...|
37 #         ^
38 #         hole at a correct offset
39 #
40 # 2) 2b3864b32403 ("ext4: do not polute the extents cache while shifting extents")
41 #
42 # Extents status tree is filled in with outdated offsets while doing
43 # extents shift, that leads to wrong data blocks.  That is why test
44 # writes unique block content and checks md5sum of a result file after
45 # each block insert.
46 #
47 . ./common/preamble
48 _begin_fstest auto quick insert
49
50 testfile=$TEST_DIR/$seq.file
51 pattern=$tmp.pattern
52
53 # Override the default cleanup function.
54 _cleanup()
55 {
56         cd /
57         rm -f $tmp.*
58         rm -f $testfile
59 }
60
61 # Import common functions.
62 . ./common/filter
63
64 # real QA test starts here
65
66 # Modify as appropriate.
67 _supported_fs generic
68 _require_test
69 _require_xfs_io_command "falloc"
70 _require_xfs_io_command "finsert"
71
72 blksize=`_get_block_size $TEST_DIR`
73
74 # Generate a block with a repeating number represented as 4 bytes decimal.
75 # The test generates unique pattern for each block in order to observe a
76 # wrong order if any.
77 function generate_pattern() {
78         blkind=$1
79         printf "%04d" $blkind | awk  '{ while (c++ < '$(($blksize/4))') \
80                 printf "%s", $0 }' > $pattern
81 }
82
83 $XFS_IO_PROG -f -c "falloc 0 $(($blksize * 2))" $testfile \
84                          >> $seqres.full 2>&1
85
86 # First block, has 0001 as a pattern
87 generate_pattern 1
88 $XFS_IO_PROG -c "pwrite -i $pattern        0 $blksize" $testfile \
89                          >> $seqres.full 2>&1
90
91 # Second block, has 0002 as a pattern
92 generate_pattern 2
93 $XFS_IO_PROG -c "pwrite -i $pattern $blksize $blksize" $testfile \
94                          >> $seqres.full 2>&1
95
96 # Insert 498 blocks after the first block.  We use this quite big
97 # number to increase the reproduction probability.
98 for (( block=3; block<=500; block++ )); do
99         $XFS_IO_PROG -c "finsert $blksize $blksize" $testfile \
100                                  >> $seqres.full 2>&1
101
102         generate_pattern $block
103         $XFS_IO_PROG -c "pwrite -i $pattern $blksize $blksize" $testfile \
104                                  >> $seqres.full 2>&1
105
106         # Avoid offsets in hexdump output, because block size can vary.
107         # Here we check md5 after each insert to be sure that zero blocks
108         # do not appear, targets this commit:
109         #   14d981f468a1 ("ext4: Include forgotten start block on fallocate insert range")
110         # or blocks are in correct order, this commit:
111         #   2b3864b32403 ("ext4: do not polute the extents cache while shifting extents")
112         #
113         md5=`hexdump -e '16/1 "%_p" "\n"' $testfile | md5sum`
114         printf "#%d %s\n" "$block" "$md5"
115 done
116
117 # Eventually output file has 500 blocks in the following order:
118 #   0001 0500 0499 0498 ... 0002
119
120 # success, all done
121 status=0
122 exit