generic: test for non-zero used blocks while writing into a file
[xfstests-dev.git] / tests / generic / 418
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Red Hat Inc.  All Rights Reserved.
4 #
5 # FS QA Test 418
6 #
7 # Test pagecache invalidation in buffer/direct write/read combination.
8 #
9 # Fork N children, each child writes to and reads from its own region of the
10 # same test file, and check if what it reads is what it writes. The test region
11 # is determined by N * blksz. Write and read operation can be either direct or
12 # buffered.
13 #
14 # Regression test for commit c771c14baa33 ("iomap: invalidate page caches
15 # should be after iomap_dio_complete() in direct write")
16 #
17 seq=`basename $0`
18 seqres=$RESULT_DIR/$seq
19 echo "QA output created by $seq"
20
21 here=`pwd`
22 tmp=/tmp/$$
23 status=1        # failure is the default!
24 trap "_cleanup; exit \$status" 0 1 2 3 15
25
26 _cleanup()
27 {
28         cd /
29         rm -f $tmp.*
30 }
31
32 # get standard environment, filters and checks
33 . ./common/rc
34 . ./common/filter
35
36 # remove previous $seqres.full before test
37 rm -f $seqres.full
38
39 # real QA test starts here
40 _supported_fs generic
41 _require_test
42 _require_odirect
43 _require_block_device $TEST_DEV
44 _require_test_program "dio-invalidate-cache"
45 _require_test_program "feature"
46
47 diotest=$here/src/dio-invalidate-cache
48 testfile=$TEST_DIR/$seq-diotest
49 sectorsize=`blockdev --getss $TEST_DEV`
50 pagesize=`$here/src/feature -s`
51
52 # test case array, test different write/read combinations
53 # -r: use direct read
54 # -w: use direct write
55 # -t: truncate file to final size before test, i.e. write to hole
56 # -p: fallocate whole file before test, i.e. write to allocated but unwritten extents
57 # -F: fulfill whole file before test, i.e. write to allocated & written extents
58 t_cases=(
59         "-w"
60         "-wt"
61         "-wp"
62         "-wF"
63         "-r"
64         "-rt"
65         "-rp"
66         "-rF"
67         "-rw"
68         "-rwt"
69         "-rwp"
70         "-rwF"
71 )
72
73 runtest()
74 {
75         local i=0
76         local tc=""
77         local loop=$1
78         shift
79
80         for tc in ${t_cases[*]}; do
81                 echo "diotest $tc $*" >> $seqres.full
82                 i=0
83                 while [ $i -lt $loop ]; do
84                         $diotest $tc $* -f $testfile
85                         if [ $? -ne 0 ]; then
86                                 echo "diotest $tc $* failed at loop $i" | \
87                                         tee -a $seqres.full
88                                 break
89                         fi
90                         let i=i+1
91                 done
92         done
93 }
94
95 while [ $sectorsize -le $((pagesize * 2)) ]; do
96         # reproducer for the original bug
97         runtest $((10 * LOAD_FACTOR)) -b $sectorsize -n 3 -i 1
98         # try more processes and iterations
99         runtest $((5 * LOAD_FACTOR))  -b $sectorsize -n 8 -i 4
100         sectorsize=$((sectorsize * 2))
101 done
102 echo "Silence is golden"
103
104 # success, all done
105 status=0
106 exit