generic: add new test for fsync() on directories
[xfstests-dev.git] / tests / generic / 311
1 #! /bin/bash
2 # FS QA Test No. 311
3 #
4 # Run various fsync tests with dm flakey in freeze() mode and non freeze()
5 # mode. The idea is that we do random writes and randomly fsync and verify that
6 # after a fsync() followed by a freeze()+failure or just failure that the file
7 # is correct.  We remount the file system after the failure so that the file
8 # system can do whatever cleanup it needs to and md5sum the file to make sure
9 # it matches hat it was before the failure.  We also fsck to make sure the file
10 # system is consistent.
11 #
12 # The fsync tester just random writes into prealloc or not, and then fsync()s
13 # randomly or sync()'s randomly and then fsync()'s before exit.  There are a few
14 # tests that were handcrafted to reproduce bugs in btrfs, so it's also a
15 # regression test of sorts.
16 #
17 #-----------------------------------------------------------------------
18 # Copyright (c) 2013 Fusion IO. All Rights Reserved.
19 #
20 # This program is free software; you can redistribute it and/or
21 # modify it under the terms of the GNU General Public License as
22 # published by the Free Software Foundation.
23 #
24 # This program is distributed in the hope that it would be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27 # GNU General Public License for more details.
28 #
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write the Free Software Foundation,
31 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
32 #-----------------------------------------------------------------------
33 #
34
35 seq=`basename $0`
36 seqres=$RESULT_DIR/$seq
37 echo "QA output created by $seq"
38
39 here=`pwd`
40 status=1        # failure is the default!
41
42 _cleanup()
43 {
44         _cleanup_flakey
45 }
46 trap "_cleanup; exit \$status" 0 1 2 3 15
47
48 # get standard environment, filters and checks
49 . ./common/rc
50 . ./common/filter
51 . ./common/dmflakey
52
53 # real QA test starts here
54 _supported_fs generic
55 _supported_os Linux
56 _need_to_be_root
57 _require_scratch
58 _require_dm_flakey
59
60 [ -x $here/src/fsync-tester ] || _notrun "fsync-tester not build"
61
62 rm -f $seqres.full
63 SEED=1
64 testfile=$SCRATCH_MNT/$seq.fsync
65
66 _run_test()
67 {
68         # _run_test <testnum> <0 - buffered | 1 - O_DIRECT>
69         test_num=$1
70
71         direct_opt=""
72         [ $2 -eq 1 ] && direct_opt="-d"
73
74         $here/src/fsync-tester -s $SEED -t $test_num $direct_opt $testfile
75         [ $? -ne 0 ] && _fatal "fsync tester exited abnormally"
76
77         _md5_checksum $testfile
78         _load_flakey_table $FLAKEY_DROP_WRITES $lockfs
79         _unmount_flakey
80
81         #Ok mount so that any recovery that needs to happen is done
82         _load_flakey_table $FLAKEY_ALLOW_WRITES
83         _mount_flakey
84         _md5_checksum $testfile
85
86         #Unmount and fsck to make sure we got a valid fs after replay
87         _unmount_flakey
88         _check_scratch_fs $FLAKEY_DEV
89         [ $? -ne 0 ] && _fatal "fsck failed"
90
91         _mount_flakey
92 }
93
94 _scratch_mkfs >> $seqres.full 2>&1
95
96 # Create a basic flakey device that will never error out
97 _init_flakey
98 _mount_flakey
99
100 buffered=0
101 direct=1
102
103 for i in $(seq 1 20); do
104         lockfs=1
105         SEED=$i
106         echo "Running test $i buffered, normal suspend"
107         _run_test $i $buffered
108         echo "Running test $i direct, normal suspend"
109         _run_test $i $direct
110
111         lockfs=0
112         echo "Running test $i buffered, nolockfs"
113         _run_test $i $buffered
114         echo "Running test $i direct, nolockfs"
115         _run_test $i $direct
116 done
117
118 status=0
119 exit