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