summaryrefslogtreecommitdiff
path: root/tests/generic/418
blob: 501b2912034ada1b91242f921b5ace1940d2fccf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2017 Red Hat Inc.  All Rights Reserved.
#
# FS QA Test 418
#
# Test pagecache invalidation in buffer/direct write/read combination.
#
# Fork N children, each child writes to and reads from its own region of the
# same test file, and check if what it reads is what it writes. The test region
# is determined by N * blksz. Write and read operation can be either direct or
# buffered.
#
# Regression test for commit c771c14baa33 ("iomap: invalidate page caches
# should be after iomap_dio_complete() in direct write")
#
. ./common/preamble
_begin_fstest auto rw

# Import common functions.
. ./common/filter

# real QA test starts here
_supported_fs generic
_require_test
_require_odirect
_require_block_device $TEST_DEV
_require_test_program "dio-invalidate-cache"
_require_test_program "feature"

diotest=$here/src/dio-invalidate-cache
testfile=$TEST_DIR/$seq-diotest
sectorsize=`blockdev --getss $TEST_DEV`
pagesize=`$here/src/feature -s`

# test case array, test different write/read combinations
# -r: use direct read
# -w: use direct write
# -t: truncate file to final size before test, i.e. write to hole
# -p: fallocate whole file before test, i.e. write to allocated but unwritten extents
# -F: fulfill whole file before test, i.e. write to allocated & written extents
t_cases=(
	"-w"
	"-wt"
	"-wp"
	"-wF"
	"-r"
	"-rt"
	"-rp"
	"-rF"
	"-rw"
	"-rwt"
	"-rwp"
	"-rwF"
)

runtest()
{
	local i=0
	local tc=""
	local loop=$1
	shift

	for tc in ${t_cases[*]}; do
		echo "diotest $tc $*" >> $seqres.full
		i=0
		while [ $i -lt $loop ]; do
			$diotest $tc $* -f $testfile
			if [ $? -ne 0 ]; then
				echo "diotest $tc $* failed at loop $i" | \
					tee -a $seqres.full
				break
			fi
			let i=i+1
		done
	done
}

while [ $sectorsize -le $((pagesize * 2)) ]; do
	# reproducer for the original bug
	runtest $((10 * LOAD_FACTOR)) -b $sectorsize -n 3 -i 1
	# try more processes and iterations
	runtest $((5 * LOAD_FACTOR))  -b $sectorsize -n 8 -i 4
	sectorsize=$((sectorsize * 2))
done
echo "Silence is golden"

# success, all done
status=0
exit