fix dmapi test suite to work with more recent autotools
[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 >/tmp/$$.make 2>&1
53     then
54         :
55     else
56         cat /tmp/$$.make
57         echo "Warning: make failed -- some tests may be missing"
58         warn=1
59     fi
60     rm -f /tmp/$$.make
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 fi
70 verbose=false
71 quick=${quick-false}
72 group=false
73 xgroup=false
74 showme=false
75 sortme=false
76 expunge=true
77 have_test_arg=false
78 rm -f $tmp.list $tmp.tmp $tmp.sed
79
80 for r
81 do
82
83     if $group
84     then
85         # arg after -g
86         group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
87 s/ .*//p
88 }'`
89         if [ -z "$group_list" ]
90         then
91             echo "Group \"$r\" is empty or not defined?"
92             exit 1
93         fi
94         [ ! -s $tmp.list ] && touch $tmp.list
95         for t in $group_list
96         do
97             if grep -s "^$t\$" $tmp.list >/dev/null
98             then
99                 :
100             else
101                 echo "$t" >>$tmp.list
102             fi
103         done
104         group=false
105         continue
106
107     elif $xgroup
108     then
109         # arg after -x
110         [ ! -s $tmp.list ] && ls [0-9][0-9][0-9] [0-9][0-9][0-9][0-9] >$tmp.list 2>/dev/null
111         group_list=`sed -n <group -e 's/$/ /' -e "/^[0-9][0-9][0-9].* $r /"'{
112 s/ .*//p
113 }'`
114         if [ -z "$group_list" ]
115         then
116             echo "Group \"$r\" is empty or not defined?"
117             exit 1
118         fi
119         numsed=0
120         rm -f $tmp.sed
121         for t in $group_list
122         do
123             if [ $numsed -gt 100 ]
124             then
125                 sed -f $tmp.sed <$tmp.list >$tmp.tmp
126                 mv $tmp.tmp $tmp.list
127                 numsed=0
128                 rm -f $tmp.sed
129             fi
130             echo "/^$t\$/d" >>$tmp.sed
131             numsed=`expr $numsed + 1`
132         done
133         sed -f $tmp.sed <$tmp.list >$tmp.tmp
134         mv $tmp.tmp $tmp.list
135         xgroup=false
136         continue
137     fi
138
139     xpand=true
140     case "$r"
141     in
142
143         -\?)    # usage
144             echo "Usage: $0 [options] [testlist]"'
145
146 common options
147     -v                  verbose
148
149 check options
150     -g group[,group...] include tests from these groups
151     -l                  line mode diff [xdiff]
152     -n                  show me, do not run tests
153     -q                  quick, no checks (you are on your own)
154     -T                  output timestamps
155     -x group[,group...] exclude tests from these groups
156 '
157             exit 0
158             ;;
159
160         -g)     # -g group ... pick from group file
161             group=true
162             xpand=false
163             ;;
164
165         -l)     # line mode for diff, not gdiff over modems
166             diff=diff
167             xpand=false
168             ;;
169
170         -q)     # "quick", no checks (you are on your own)
171             quick=true
172             xpand=false
173             ;;
174
175         -n)     # show me, don't do it
176             showme=true
177             xpand=false
178             ;;
179
180         -T)     # turn on timestamp output
181             timestamp=true
182             xpand=false
183             ;;
184
185         -v)
186             verbose=true
187             xpand=false
188             ;;
189
190         -x)     # -x group ... exclude from group file
191             xgroup=true
192             xpand=false
193             ;;
194
195         '[0-9][0-9][0-9] [0-9][0-9][0-9][0-9]')
196             echo "No tests?"
197             status=1
198             exit $status
199             ;;
200
201         [0-9]*-[0-9]*)
202             eval `echo $r | sed -e 's/^/start=/' -e 's/-/ end=/'`
203             ;;
204
205         [0-9]*-)
206             eval `echo $r | sed -e 's/^/start=/' -e 's/-//'`
207             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/.* //'`
208             if [ -z "$end" ]
209             then
210                 echo "No tests in range \"$r\"?"
211                 status=1
212                 exit $status
213             fi
214             ;;
215
216         *)
217             start=$r
218             end=$r
219             ;;
220
221     esac
222
223     # get rid of leading 0s as can be interpreted as octal
224     start=`echo $start | sed 's/^0*//'`
225     end=`echo $end | sed 's/^0*//'`
226
227     if $xpand
228     then
229         have_test_arg=true
230         $AWK_PROG </dev/null '
231 BEGIN   { for (t='$start'; t<='$end'; t++) printf "%03d\n",t }' \
232         | while read id
233         do
234             if grep -s "^$id " group >/dev/null
235             then
236                 # in group file ... OK
237                 echo $id >>$tmp.list
238             else
239                 if [ -f expunged ] && $expunge && egrep "^$id([         ]|\$)" expunged >/dev/null
240                 then
241                     # expunged ... will be reported, but not run, later
242                     echo $id >>$tmp.list
243                 else
244                     # oops
245                     echo "$id - unknown test, ignored"
246                 fi
247             fi
248         done
249     fi
250
251 done
252
253 if [ -s $tmp.list ]
254 then
255     # found some valid test numbers ... this is good
256     :
257 else
258     if $have_test_arg
259     then
260         # had test numbers, but none in group file ... do nothing
261         touch $tmp.list
262     else
263         # no test numbers, do everything from group file
264         sed -n -e '/^[0-9][0-9][0-9]*/s/[       ].*//p' <group >$tmp.list
265     fi
266 fi
267
268 # should be sort -n, but this did not work for Linux when this
269 # was ported from IRIX
270 #
271 list=`sort $tmp.list`
272 rm -f $tmp.list $tmp.tmp $tmp.sed
273
274 if $quick
275 then
276     :
277 else
278
279     if ( cd src; make -i )
280     then
281         :
282     else
283         echo
284         echo ":----------------------------------------------"
285         echo ": Warning: make failed in src -- some tests may fail as a result"
286         echo ":----------------------------------------------"
287         echo
288         warn=1
289     fi
290
291 fi