generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / xfs / 012
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 012
6 #
7 # holes
8 #
9 . ./common/preamble
10 _begin_fstest rw auto quick
11
12 status=0        # success is the default!
13
14 # Override the default cleanup function.
15 _cleanup()
16 {
17     cd /
18     rm -f $tmp.*
19     rm -rf $TEST_DIR/holes.$$.*
20 }
21
22 _filesize()
23 {
24     ls -l $1 | $AWK_PROG '{print "    filesize = " $5}'
25 }
26
27 # Import common functions.
28 . ./common/filter
29
30 _do_test()
31 {
32     _n="$1"
33     _param="$2"
34     _count="$3"
35     
36     failed=0
37     
38     out=$TEST_DIR/holes.$$.$_n
39     echo ""
40     echo "holes.$_n : $_param"
41     echo "-----------------------------------------------"
42     if  ! $here/src/holes $_param $out >$tmp.out
43     then
44         echo "    holes returned $? - see $seqres.full"
45         failed=1
46         status=1
47     fi
48         
49
50     if [ $failed -eq 0 ]
51     then        
52         # quick check - how many holes did we get?
53         count=`xfs_bmap $out | egrep -c ': hole'`
54         echo "    $count hole(s) detected"
55         # and how big was the file?
56         _filesize $out
57         
58         if [ $count -ne $_count ]
59         then
60             echo "    unexpected number of holes - see $seqres.full"
61             status=1
62             failed=1
63         fi
64     fi
65         
66     if [ $failed -eq 1 ]
67     then
68         echo "--------------------------------------"       >>$seqres.full
69         echo "$_n - output from holes:"                     >>$seqres.full
70         echo "--------------------------------------"       >>$seqres.full
71         cat $tmp.out                                        >>$seqres.full
72         echo "--------------------------------------"       >>$seqres.full
73         echo "$_n - output from bmap:"                      >>$seqres.full
74         echo "--------------------------------------"       >>$seqres.full
75         xfs_bmap -vvv $out                                  >>$seqres.full
76         echo "--------------------------------------"       >>$seqres.full
77         echo "$_n - output from ls -li:"                    >>$seqres.full
78         echo "--------------------------------------"       >>$seqres.full
79         ls -li $out                                         >>$seqres.full
80         status=1
81     fi
82 }
83
84 # real QA test starts here
85 _supported_fs xfs
86 _require_test
87
88 # small & fairly dense
89 _do_test 1 "-l 40960000 -b 40960 -i 10 -c 1" 100
90
91 # big & sparse
92 _do_test 2 "-l 409600000 -b 40960 -i 1000 -c 1" 10
93
94 # no holes, but a very nasty way to write a file (lots of extents)
95 _do_test 3 "-l 40960000 -b 40960 -i 10 -c 10" 0
96
97 exit