225942f429f7025ec721a8b1f211aad272adc913
[xfstests-dev.git] / common
1 ##/bin/sh 
2 #
3 # Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
4
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of version 2 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, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 # Further, this software is distributed without any warranty that it is
14 # free of the rightful claim of any third person regarding infringement
15 # or the like.  Any license provided herein, whether implied or
16 # otherwise, applies only to this software file.  Patent licenses, if
17 # any, provided herein do not apply to combinations of this program with
18 # other software, or any other product whatsoever.
19
20 # You should have received a copy of the GNU General Public License along
21 # with this program; if not, write the Free Software Foundation, Inc., 59
22 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
23
24 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
25 # Mountain View, CA  94043, or:
26
27 # http://www.sgi.com 
28
29 # For further information regarding this notice, see: 
30
31 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
32 #
33 # common procedures for QA scripts
34 #
35 # $Header: /disk7/depot/linux/pcp/dev/qa/RCS/common,v 2.52 2000/04/05 18:24:51 kenmcd Exp $
36 #
37
38 _setenvironment()
39 {
40     MSGVERB="text:action"
41     export MSGVERB
42 }
43
44 here=`pwd`
45 rm -f $here/$iam.out
46 _setenvironment
47
48 check=${check-true}
49
50 if $check
51 then
52     if $MAKE_PROG >/tmp/$$.gmake 2>&1
53     then
54         :
55     else
56         cat /tmp/$$.gmake
57         echo "Warning: $MAKE_PROG failed -- some tests may be missing"
58         warn=1
59     fi
60     rm -f /tmp/$$.gmake
61 fi
62
63 diff=diff
64 if [ ! -z "$DISPLAY" ]
65 then
66     which xdiff >/dev/null 2>&1 && diff=xdiff
67     which gdiff >/dev/null 2>&1 && diff=gdiff
68     which tkdiff >/dev/null 2>&1 && diff=tkdiff
69     which xxdiff >/dev/null 2>&1 && diff=xxdiff
70 fi
71 verbose=false
72 quick=${quick-false}
73 group=false
74 xgroup=false
75 showme=false
76 sortme=false
77 expunge=true
78 have_test_arg=false
79 rm -f $tmp.list $tmp.tmp $tmp.sed
80
81 export FSTYP=xfs
82
83 for r
84 do
85
86     if $group
87     then
88         # arg after -g
89         group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
90 s/ .*//p
91 }'`
92         if [ -z "$group_list" ]
93         then
94             echo "Group \"$r\" is empty or not defined?"
95             exit 1
96         fi
97         [ ! -s $tmp.list ] && touch $tmp.list
98         for t in $group_list
99         do
100             if grep -s "^$t\$" $tmp.list >/dev/null
101             then
102                 :
103             else
104                 echo "$t" >>$tmp.list
105             fi
106         done
107         group=false
108         continue
109
110     elif $xgroup
111     then
112         # arg after -x
113         [ ! -s $tmp.list ] && ls [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] >$tmp.list 2>/dev/null
114         group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
115 s/ .*//p
116 }'`
117         if [ -z "$group_list" ]
118         then
119             echo "Group \"$r\" is empty or not defined?"
120             exit 1
121         fi
122         numsed=0
123         rm -f $tmp.sed
124         for t in $group_list
125         do
126             if [ $numsed -gt 100 ]
127             then
128                 sed -f $tmp.sed <$tmp.list >$tmp.tmp
129                 mv $tmp.tmp $tmp.list
130                 numsed=0
131                 rm -f $tmp.sed
132             fi
133             echo "/^$t\$/d" >>$tmp.sed
134             numsed=`expr $numsed + 1`
135         done
136         sed -f $tmp.sed <$tmp.list >$tmp.tmp
137         mv $tmp.tmp $tmp.list
138         xgroup=false
139         continue
140     fi
141
142     xpand=true
143     case "$r"
144     in
145
146         -\?)    # usage
147             echo "Usage: $0 [options] [testlist]"'
148
149 common options
150     -v                  verbose
151
152 check options
153     -xfs                test XFS
154     -udf                test UDF
155     -nfs                test NFS
156     -g group[,group...] include tests from these groups
157     -l                  line mode diff [xdiff]
158     -n                  show me, do not run tests
159     -q                  quick, no checks (you are on your own)
160     -T                  output timestamps
161     -x group[,group...] exclude tests from these groups
162     -r                  randomize order
163 '
164             exit 0
165             ;;
166
167         -udf)   # -udf ... set FSTYP to udf
168             FSTYP=udf
169             xpand=false
170             ;;
171
172         -xfs)   # -xfs ... set FSTYP to xfs
173             FSTYP=xfs
174             xpand=false
175             ;;
176
177         -nfs)   # -nfs ... set FSTYP to nfs
178             FSTYP=nfs
179             xpand=false
180             ;;
181
182         -g)     # -g group ... pick from group file
183             group=true
184             xpand=false
185             ;;
186
187         -l)     # line mode for diff, not gdiff over modems
188             diff=diff
189             xpand=false
190             ;;
191
192         -q)     # "quick", no checks (you are on your own)
193             quick=true
194             xpand=false
195             ;;
196
197         -n)     # show me, don't do it
198             showme=true
199             xpand=false
200             ;;
201
202         -T)     # turn on timestamp output
203             timestamp=true
204             xpand=false
205             ;;
206
207         -v)
208             verbose=true
209             xpand=false
210             ;;
211         -x)     # -x group ... exclude from group file
212             xgroup=true
213             xpand=false
214             ;;
215         '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
216             echo "No tests?"
217             status=1
218             exit $status
219             ;;
220
221         [0-9]*-[0-9]*)
222             eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
223             ;;
224
225         [0-9]*-)
226             eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
227             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/.* //'`
228             if [ -z "$end" ]
229             then
230                 echo "No tests in range \"$r\"?"
231                 status=1
232                 exit $status
233             fi
234             ;;
235
236         *)
237             start=$r
238             end=$r
239             ;;
240
241     esac
242
243     # get rid of leading 0s as can be interpreted as octal
244     start=`echo $start | sed 's/^0*//'`
245     end=`echo $end | sed 's/^0*//'`
246
247     if $xpand
248     then
249         have_test_arg=true
250         $AWK_PROG </dev/null '
251 BEGIN   { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
252         | while read id
253         do
254             if grep -s "^$id " group >/dev/null
255             then
256                 # in group file ... OK
257                 echo $id >>$tmp.list
258             else
259                 if [ -f expunged ] && $expunge && egrep "^$id([         ]|\$)" expunged >/dev/null
260                 then
261                     # expunged ... will be reported, but not run, later
262                     echo $id >>$tmp.list
263                 else
264                     # oops
265                     echo "$id - unknown test, ignored"
266                 fi
267             fi
268         done
269     fi
270
271 done
272
273 if [ -s $tmp.list ]
274 then
275     # found some valid test numbers ... this is good
276     :
277 else
278     if $have_test_arg
279     then
280         # had test numbers, but none in group file ... do nothing
281         touch $tmp.list
282     else
283         # no test numbers, do everything from group file
284         sed -n -e '/^[0-9][0-9][0-9]*/s/[       ].*//p' <group >$tmp.list
285     fi
286 fi
287
288 # should be sort -n, but this did not work for Linux when this
289 # was ported from IRIX
290 #
291 list=`sort $tmp.list`
292 rm -f $tmp.list $tmp.tmp $tmp.sed
293
294 if $quick
295 then
296     :
297 else
298     
299     if ( cd src; $MAKE_PROG -is)
300     then
301         :
302     else
303         echo
304         echo ":----------------------------------------------"
305         echo ": Warning: $MAKE_PROG failed in src -- some tests may fail as a result"
306         echo ":----------------------------------------------"
307         echo
308         warn=1
309     fi
310
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     nfs)
325          ;;
326 esac