common/fuzzy: try to clear blocking flags first in _scratch_fuzz_modify
[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 _supported_os Linux
42 _require_test
43 _require_odirect
44 _require_block_device $TEST_DEV
45 _require_test_program "dio-invalidate-cache"
46 _require_test_program "feature"
47
48 diotest=$here/src/dio-invalidate-cache
49 testfile=$TEST_DIR/$seq-diotest
50 sectorsize=`blockdev --getss $TEST_DEV`
51 pagesize=`$here/src/feature -s`
52
53 # test case array, test different write/read combinations
54 # -r: use direct read
55 # -w: use direct write
56 # -t: truncate file to final size before test, i.e. write to hole
57 # -p: fallocate whole file before test, i.e. write to allocated but unwritten extents
58 # -F: fulfill whole file before test, i.e. write to allocated & written extents
59 t_cases=(
60         "-w"
61         "-wt"
62         "-wp"
63         "-wF"
64         "-r"
65         "-rt"
66         "-rp"
67         "-rF"
68         "-rw"
69         "-rwt"
70         "-rwp"
71         "-rwF"
72 )
73
74 runtest()
75 {
76         local i=0
77         local tc=""
78         local loop=$1
79         shift
80
81         for tc in ${t_cases[*]}; do
82                 echo "diotest $tc $*" >> $seqres.full
83                 i=0
84                 while [ $i -lt $loop ]; do
85                         $diotest $tc $* -f $testfile
86                         if [ $? -ne 0 ]; then
87                                 echo "diotest $tc $* failed at loop $i" | \
88                                         tee -a $seqres.full
89                                 break
90                         fi
91                         let i=i+1
92                 done
93         done
94 }
95
96 while [ $sectorsize -le $((pagesize * 2)) ]; do
97         # reproducer for the original bug
98         runtest $((10 * LOAD_FACTOR)) -b $sectorsize -n 3 -i 1
99         # try more processes and iterations
100         runtest $((5 * LOAD_FACTOR))  -b $sectorsize -n 8 -i 4
101         sectorsize=$((sectorsize * 2))
102 done
103 echo "Silence is golden"
104
105 # success, all done
106 status=0
107 exit