xfstests: rename USE_BIG_LOOPFS to be more generic
[xfstests-dev.git] / common
1 ##/bin/bash 
2 #
3 # Copyright (c) 2000-2005 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it would be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write the Free Software Foundation,
16 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17 #
18 #
19 # common procedures for QA scripts
20 #
21 # $Header: /disk7/depot/linux/pcp/dev/qa/RCS/common,v 2.52 2000/04/05 18:24:51 kenmcd Exp $
22 #
23
24 _setenvironment()
25 {
26     MSGVERB="text:action"
27     export MSGVERB
28 }
29
30 usage()
31 {
32     echo "Usage: $0 [options] [testlist]"'
33
34 common options
35     -v                  verbose
36
37 check options
38     -xfs                test XFS (default)
39     -udf                test UDF
40     -nfs                test NFS
41     -l                  line mode diff
42     -xdiff              graphical mode diff
43     -udiff              show unified diff (default)
44     -n                  show me, do not run tests
45     -q                  quick [deprecated]
46     -T                  output timestamps
47     -r                  randomize test order
48     --large-fs          optimise scratch device for large filesystems
49
50 testlist options
51     -g group[,group...] include tests from these groups
52     -x group[,group...] exclude tests from these groups
53     NNN                 include test NNN
54     NNN-NNN             include test range (eg. 012-021)
55 '
56             exit 0
57 }
58
59 here=`pwd`
60 rm -f $here/$iam.out
61 _setenvironment
62
63 check=${check-true}
64
65 diff="diff -u"
66 verbose=false
67 group=false
68 xgroup=false
69 showme=false
70 sortme=false
71 expunge=true
72 have_test_arg=false
73 randomize=false
74 rm -f $tmp.list $tmp.tmp $tmp.sed
75
76 # Autodetect fs type based on what's on $TEST_DEV
77 if [ "$HOSTOS" == "Linux" ]
78 then
79     export FSTYP=`blkid -c /dev/null -s TYPE -o value $TEST_DEV`
80 else
81     export FSTYP=xfs
82 fi
83
84 for r
85 do
86
87     if $group
88     then
89         # arg after -g
90        group_list=$(sed -n < group \
91                        -e 's/#.*//' \
92                        -e 's/$/ /' \
93                        -e "/^[0-9][0-9][0-9].* $r /"'{ s/ .*//p }')
94         if [ -z "$group_list" ]
95         then
96             echo "Group \"$r\" is empty or not defined?"
97             exit 1
98         fi
99         [ ! -s $tmp.list ] && touch $tmp.list
100         for t in $group_list
101         do
102             if grep -s "^$t\$" $tmp.list >/dev/null
103             then
104                 :
105             else
106                 echo "$t" >>$tmp.list
107             fi
108         done
109         group=false
110         continue
111
112     elif $xgroup
113     then
114         # arg after -x
115         [ ! -s $tmp.list ] && ls [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] >$tmp.list 2>/dev/null
116         group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
117 s/ .*//p
118 }'`
119         if [ -z "$group_list" ]
120         then
121             echo "Group \"$r\" is empty or not defined?"
122             exit 1
123         fi
124         numsed=0
125         rm -f $tmp.sed
126         for t in $group_list
127         do
128             if [ $numsed -gt 100 ]
129             then
130                 sed -f $tmp.sed <$tmp.list >$tmp.tmp
131                 mv $tmp.tmp $tmp.list
132                 numsed=0
133                 rm -f $tmp.sed
134             fi
135             echo "/^$t\$/d" >>$tmp.sed
136             numsed=`expr $numsed + 1`
137         done
138         sed -f $tmp.sed <$tmp.list >$tmp.tmp
139         mv $tmp.tmp $tmp.list
140         xgroup=false
141         continue
142     fi
143
144     xpand=true
145     case "$r"
146     in
147
148         -\? | -h | --help)      # usage
149             usage
150             ;;
151
152         -udf)   # -udf ... set FSTYP to udf
153             FSTYP=udf
154             xpand=false
155             ;;
156
157         -xfs)   # -xfs ... set FSTYP to xfs
158             FSTYP=xfs
159             xpand=false
160             ;;
161
162         -nfs)   # -nfs ... set FSTYP to nfs
163             FSTYP=nfs
164             xpand=false
165             ;;
166
167         -g)     # -g group ... pick from group file
168             group=true
169             xpand=false
170             ;;
171
172         -l)     # line mode for diff, was default before
173             diff="diff"
174             xpand=false
175             ;;
176
177         -xdiff) # graphical diff mode
178             xpand=false
179
180             if [ ! -z "$DISPLAY" ]
181             then
182                 which xdiff >/dev/null 2>&1 && diff=xdiff
183                 which gdiff >/dev/null 2>&1 && diff=gdiff
184                 which tkdiff >/dev/null 2>&1 && diff=tkdiff
185                 which xxdiff >/dev/null 2>&1 && diff=xxdiff
186             fi
187             ;;
188
189         -udiff) # show a unified diff, default now, keep for backward compat
190             xpand=false
191             diff="$diff -u"
192             ;;
193
194         -q)     # "quick", no longer used - always quick :-)
195             xpand=false
196             ;;
197
198         -n)     # show me, don't do it
199             showme=true
200             xpand=false
201             ;;
202         -r)     # randomize test order
203             randomize=true
204             xpand=false
205             ;;
206
207         -T)     # turn on timestamp output
208             timestamp=true
209             xpand=false
210             ;;
211
212         -v)
213             verbose=true
214             xpand=false
215             ;;
216         -x)     # -x group ... exclude from group file
217             xgroup=true
218             xpand=false
219             ;;
220         '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
221             echo "No tests?"
222             status=1
223             exit $status
224             ;;
225
226         [0-9]*-[0-9]*)
227             eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
228             ;;
229
230         [0-9]*-)
231             eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
232             end=`echo [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] | sed -e 's/\[0-9]//g' -e 's/  *$//' -e 's/.* //'`
233             if [ -z "$end" ]
234             then
235                 echo "No tests in range \"$r\"?"
236                 status=1
237                 exit $status
238             fi
239             ;;
240
241         --large-fs)
242             export LARGE_SCRATCH_DEV=yes
243             xpand=false
244             ;;
245
246         -*)
247             usage
248             ;;
249
250         *)
251             start=$r
252             end=$r
253             ;;
254
255     esac
256
257     # get rid of leading 0s as can be interpreted as octal
258     start=`echo $start | sed 's/^0*//'`
259     end=`echo $end | sed 's/^0*//'`
260
261     if $xpand
262     then
263         have_test_arg=true
264         $AWK_PROG </dev/null '
265 BEGIN   { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
266         | while read id
267         do
268             if grep -s "^$id " group >/dev/null
269             then
270                 # in group file ... OK
271                 echo $id >>$tmp.list
272             else
273                 if [ -f expunged ] && $expunge && egrep "^$id([         ]|\$)" expunged >/dev/null
274                 then
275                     # expunged ... will be reported, but not run, later
276                     echo $id >>$tmp.list
277                 else
278                     # oops
279                     echo "$id - unknown test, ignored"
280                 fi
281             fi
282         done
283     fi
284
285 done
286
287 if [ -s $tmp.list ]
288 then
289     # found some valid test numbers ... this is good
290     :
291 else
292     if $have_test_arg
293     then
294         # had test numbers, but none in group file ... do nothing
295         touch $tmp.list
296     else
297         # no test numbers, do everything from group file
298         sed -n -e '/^[0-9][0-9][0-9]*/s/[       ].*//p' <group >$tmp.list
299     fi
300 fi
301
302 # should be sort -n, but this did not work for Linux when this
303 # was ported from IRIX
304 #
305 list=`sort $tmp.list`
306 rm -f $tmp.list $tmp.tmp $tmp.sed
307
308 if $randomize
309 then
310     list=`echo $list | awk -f randomize.awk`
311 fi
312
313 case "$FSTYP" in
314     xfs)
315          [ "$XFS_LOGPRINT_PROG" = "" ] && _fatal "xfs_logprint not found"
316          [ "$XFS_REPAIR_PROG" = "" ] && _fatal "xfs_repair not found"
317          [ "$XFS_CHECK_PROG" = "" ] && _fatal "xfs_check not found"
318          [ "$XFS_DB_PROG" = "" ] && _fatal "xfs_db not found"
319          [ "$MKFS_XFS_PROG" = "" ] && _fatal "mkfs_xfs not found" 
320          ;;
321     udf)
322          [ "$MKFS_UDF_PROG" = "" ] && _fatal "mkfs_udf/mkudffs not found"
323          ;;
324     btrfs)
325          [ "$MKFS_BTRFS_PROG" = "" ] && _fatal "mkfs.btrfs not found"
326          ;;
327     nfs)
328          ;;
329 esac