common/xfs: Initialise OPTIND for getopts calls
[xfstests-dev.git] / tests / generic / 074
1 #! /bin/bash
2 # FS QA Test No. 074
3 #
4 # fstest
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 fstest_dir=$TEST_DIR/fstest
32 status=0        # success is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37     rm -rf $fstest_dir.* $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43
44 _supported_fs generic
45 _supported_os Linux
46 _require_test
47
48 rm -f $seqres.full
49
50 _do_test()
51 {
52     _n="$1"
53     _param="$2"
54
55     out=$fstest_dir.$_n
56     rm -rf $out
57     if ! mkdir $out
58     then
59         echo "    failed to mkdir $out"
60         status=1
61         exit
62     fi
63
64     _filter_param=`echo "$_param" | sed\
65         -e 's/-n [0-9][0-9]*/-n children/' \
66         -e 's/-l [0-9][0-9]*/-l loops/' \
67         -e 's/-f [0-9][0-9]*/-f files/'`
68
69     echo ""
70     echo "-----------------------------------------------"
71     echo "fstest.$_n : $_filter_param"
72     echo "-----------------------------------------------"
73     if ! $here/src/fstest $_param -p $out >>$seqres.full
74     then
75         echo "    fstest ($_param) returned $? - see $seqres.full"
76         status=1
77         exit
78     fi
79
80     _check_test_fs
81 }
82
83 _usage()
84 {
85     echo "$0: [-f files] [-l loops] [-n children]"
86 }
87
88 _process_args()
89 {
90     OPTIND=1
91     while getopts "f:l:n:?" c $@
92     do
93         case $c
94         in
95             f)
96                 numfiles=$OPTARG
97                 param_type="$param_type, overidde -f"
98                 ;;
99             l)
100                 numloops=$OPTARG
101                 param_type="$param_type, overidde -l"
102                 ;;
103             n)
104                 numchildren=$OPTARG
105                 param_type="$param_type, overidde -n"
106                 ;;
107             ?)
108                 _usage
109                 exit    
110                 ;;
111         esac
112     done
113 }
114
115 #
116 # set params
117 # These params can take a while on different CPUs/OSs
118 # so we set them differently for different machines
119 #
120 if uname -a | grep -q SMP; then
121         numloops=10
122         numfiles=5
123         numchildren=3
124         param_type="Linux SMP"
125 else
126         numloops=2
127         numfiles=3
128         numchildren=3
129         param_type="Linux UP"
130 fi
131
132 # can override the params here
133 _process_args "$@"
134
135 echo "Params are for $param_type" >>$seqres.full
136 echo "Params: n = $numchildren l = $numloops f = $numfiles" >>$seqres.full
137
138 _check_test_fs
139
140 # Options:
141 # -F                    generate files with holes  (default=no)
142 # -n num_children       set number of child processes (default=1)
143 # -f num_files          set number of files (default=1)
144 # -s file_size          set file sizes (default=1MiB)
145 # -b block_size         set block (IO) size (default=1024)
146 # -l loops              set loop count (default=100)
147 # -m                    use mmap (default=no)
148 # -S                    use synchronous IO (default=no)
149 # -P                    preallocate space (default=no)
150
151 size10=`expr 10 \* 1024 \* 1024`        # 10 megabytes
152 size30=`expr 30 \* 1024 \* 1024`        # 30 megabytes
153
154 _do_test 0 "-l $numloops"
155
156 _do_test 1 "-l $numloops -s $size10 -b 8192 -m"
157
158 _do_test 2 "-n $numchildren -F -l $numloops -f $numfiles -s $size30 -b 512"
159
160 _do_test 3 "-n $numchildren -F -l $numloops -f $numfiles -s $size30 -b 512 -m"
161
162 _do_test 4 "-n $numchildren -F -l $numloops -f $numfiles -s $size10 -b 512 -mS"