xfstests: add test 185, Dmapi Punch/Probe Alignment compared to xfsctl(FREESPACE),
[xfstests-dev.git] / common
1 ##/bin/sh 
2 #
3 # Copyright (c) 2000-2005 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # common procedures for QA scripts
6 #
7 # $Header: /disk7/depot/linux/pcp/dev/qa/RCS/common,v 2.52 2000/04/05 18:24:51 kenmcd Exp $
8 #
9
10 _setenvironment()
11 {
12     MSGVERB="text:action"
13     export MSGVERB
14 }
15
16 here=`pwd`
17 rm -f $here/$iam.out
18 _setenvironment
19
20 check=${check-true}
21
22 diff=diff
23 verbose=false
24 group=false
25 xgroup=false
26 showme=false
27 sortme=false
28 expunge=true
29 have_test_arg=false
30 randomize=false
31 rm -f $tmp.list $tmp.tmp $tmp.sed
32
33 export FSTYP=xfs
34
35 for r
36 do
37
38     if $group
39     then
40         # arg after -g
41         group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
42 s/ .*//p
43 }'`
44         if [ -z "$group_list" ]
45         then
46             echo "Group \"$r\" is empty or not defined?"
47             exit 1
48         fi
49         [ ! -s $tmp.list ] && touch $tmp.list
50         for t in $group_list
51         do
52             if grep -s "^$t\$" $tmp.list >/dev/null
53             then
54                 :
55             else
56                 echo "$t" >>$tmp.list
57             fi
58         done
59         group=false
60         continue
61
62     elif $xgroup
63     then
64         # arg after -x
65         [ ! -s $tmp.list ] && ls [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] >$tmp.list 2>/dev/null
66         group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
67 s/ .*//p
68 }'`
69         if [ -z "$group_list" ]
70         then
71             echo "Group \"$r\" is empty or not defined?"
72             exit 1
73         fi
74         numsed=0
75         rm -f $tmp.sed
76         for t in $group_list
77         do
78             if [ $numsed -gt 100 ]
79             then
80                 sed -f $tmp.sed <$tmp.list >$tmp.tmp
81                 mv $tmp.tmp $tmp.list
82                 numsed=0
83                 rm -f $tmp.sed
84             fi
85             echo "/^$t\$/d" >>$tmp.sed
86             numsed=`expr $numsed + 1`
87         done
88         sed -f $tmp.sed <$tmp.list >$tmp.tmp
89         mv $tmp.tmp $tmp.list
90         xgroup=false
91         continue
92     fi
93
94     xpand=true
95     case "$r"
96     in
97
98         -\? | -h | --help)      # usage
99             echo "Usage: $0 [options] [testlist]"'
100
101 common options
102     -v                  verbose
103
104 check options
105     -xfs                test XFS (default)
106     -udf                test UDF
107     -nfs                test NFS
108     -l                  line mode diff (default)
109     -xdiff              graphical mode diff
110     -n                  show me, do not run tests
111     -q                  quick [deprecated]
112     -T                  output timestamps
113     -r                  randomize test order
114     
115 testlist options
116     -g group[,group...] include tests from these groups
117     -x group[,group...] exclude tests from these groups
118     NNN                 include test NNN
119     NNN-NNN             include test range (eg. 012-021)
120 '
121             exit 0
122             ;;
123
124         -udf)   # -udf ... set FSTYP to udf
125             FSTYP=udf
126             xpand=false
127             ;;
128
129         -xfs)   # -xfs ... set FSTYP to xfs
130             FSTYP=xfs
131             xpand=false
132             ;;
133
134         -nfs)   # -nfs ... set FSTYP to nfs
135             FSTYP=nfs
136             xpand=false
137             ;;
138
139         -g)     # -g group ... pick from group file
140             group=true
141             xpand=false
142             ;;
143
144         -l)     # line mode for diff, default now, keep for backward compat
145             xpand=false
146             ;;
147
148         -xdiff) # graphical diff mode
149             xpand=false
150
151             if [ ! -z "$DISPLAY" ]
152             then
153                 which xdiff >/dev/null 2>&1 && diff=xdiff
154                 which gdiff >/dev/null 2>&1 && diff=gdiff
155                 which tkdiff >/dev/null 2>&1 && diff=tkdiff
156                 which xxdiff >/dev/null 2>&1 && diff=xxdiff
157             fi
158             ;;
159
160         -q)     # "quick", no longer used - always quick :-)
161             xpand=false
162             ;;
163
164         -n)     # show me, don't do it
165             showme=true
166             xpand=false
167             ;;
168         -r)     # randomize test order
169             randomize=true
170             xpand=false
171             ;;
172
173         -T)     # turn on timestamp output
174             timestamp=true
175             xpand=false
176             ;;
177
178         -v)
179             verbose=true
180             xpand=false
181             ;;
182         -x)     # -x group ... exclude from group file
183             xgroup=true
184             xpand=false
185             ;;
186         '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
187             echo "No tests?"
188             status=1
189             exit $status
190             ;;
191
192         [0-9]*-[0-9]*)
193             eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
194             ;;
195
196         [0-9]*-)
197             eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
198             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/.* //'`
199             if [ -z "$end" ]
200             then
201                 echo "No tests in range \"$r\"?"
202                 status=1
203                 exit $status
204             fi
205             ;;
206
207         *)
208             start=$r
209             end=$r
210             ;;
211
212     esac
213
214     # get rid of leading 0s as can be interpreted as octal
215     start=`echo $start | sed 's/^0*//'`
216     end=`echo $end | sed 's/^0*//'`
217
218     if $xpand
219     then
220         have_test_arg=true
221         $AWK_PROG </dev/null '
222 BEGIN   { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
223         | while read id
224         do
225             if grep -s "^$id " group >/dev/null
226             then
227                 # in group file ... OK
228                 echo $id >>$tmp.list
229             else
230                 if [ -f expunged ] && $expunge && egrep "^$id([         ]|\$)" expunged >/dev/null
231                 then
232                     # expunged ... will be reported, but not run, later
233                     echo $id >>$tmp.list
234                 else
235                     # oops
236                     echo "$id - unknown test, ignored"
237                 fi
238             fi
239         done
240     fi
241
242 done
243
244 if [ -s $tmp.list ]
245 then
246     # found some valid test numbers ... this is good
247     :
248 else
249     if $have_test_arg
250     then
251         # had test numbers, but none in group file ... do nothing
252         touch $tmp.list
253     else
254         # no test numbers, do everything from group file
255         sed -n -e '/^[0-9][0-9][0-9]*/s/[       ].*//p' <group >$tmp.list
256     fi
257 fi
258
259 # should be sort -n, but this did not work for Linux when this
260 # was ported from IRIX
261 #
262 list=`sort $tmp.list`
263 rm -f $tmp.list $tmp.tmp $tmp.sed
264
265 if $randomize
266 then
267     list=`echo $list | awk -f randomize.awk`
268 fi
269
270 case "$FSTYP" in
271     xfs)
272          [ "$XFS_LOGPRINT_PROG" = "" ] && _fatal "xfs_logprint not found"
273          [ "$XFS_REPAIR_PROG" = "" ] && _fatal "xfs_repair not found"
274          [ "$XFS_CHECK_PROG" = "" ] && _fatal "xfs_check not found"
275          [ "$XFS_DB_PROG" = "" ] && _fatal "xfs_db not found"
276          [ "$MKFS_XFS_PROG" = "" ] && _fatal "mkfs_xfs not found" 
277          ;;
278     udf)
279          [ "$MKFS_UDF_PROG" = "" ] && _fatal "mkfs_udf/mkudffs not found"
280          ;;
281     nfs)
282          ;;
283 esac