d1f8939d963b3ca28bdcc089a0dc95b4bdf31cac
[xfstests-dev.git] / new
1 #! /bin/bash
2 #
3 #-----------------------------------------------------------------------
4 #  Copyright (c) 2000-2005 Silicon Graphics, Inc.  All Rights Reserved.
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation.
9 #
10 # This program is distributed in the hope that it would be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write the Free Software Foundation,
17 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 #
19 #-----------------------------------------------------------------------
20 #
21 # Make a new test
22 #
23
24 # generic initialization
25 iam=new
26 . ./common/rc
27
28 trap "rm -f /tmp/$$.; exit" 0 1 2 3 15
29
30 _cleanup()
31 {
32     :
33 }
34
35 SRC_GROUPS=`find tests -not -path tests -type d -printf "%f "`
36 usage()
37 {
38     echo "Usage $0 test_dir"
39     echo "Available dirs are: $SRC_GROUPS"
40     exit
41 }
42
43 [ $# -eq 0 ] && usage
44 tdir=tests/$1
45 shift
46
47 if [ ! -f $tdir/group ]
48 then
49     echo "Creating the $tdir/group index ..."
50     cat <<'End-of-File' >$tdir/group
51 # QA groups control
52 #
53 # define groups and default group owners
54 # do not start group name with a digit
55 #
56
57 # catch-all
58 #
59 other           some-user-login
60
61 # test-group association ... one line per test
62 #
63 End-of-File
64 fi
65
66 if [ ! -w $tdir/group ]
67 then
68     chmod u+w $tdir/group
69     echo "Warning: making the index file \"$tdir/group\" writeable"
70 fi
71
72 if make
73 then
74     :
75 else
76     echo "Warning: make failed -- some tests may be missing"
77 fi
78
79 i=0
80 line=0
81 eof=1
82 [ -f "$tdir/group" ] || usage
83
84 for found in `cat $tdir/group | $AWK_PROG '{ print $1 }'`
85 do
86     line=$((line+1))
87     if [ -z "$found" ] || [ "$found" == "#" ];then
88         continue
89     fi
90     i=$((i+1))
91     id=`printf "%03d" $i`
92     if [ "$id" != "$found" ];then
93         eof=0
94         break
95     fi
96 done
97 if [ $eof -eq 1 ]; then
98    line=$((line+1))
99    i=$((i+1))
100    id=`printf "%03d" $i`
101 fi
102
103 echo "Next test is $id"
104
105 if [ -f $tdir/$id ]
106 then
107     echo "Error: test $id already exists!"
108     _cleanup
109     exit 1
110 fi
111
112 echo -n "Creating skeletal script for you to edit ..."
113
114 year=`date +%Y`
115
116 cat <<End-of-File >$tdir/$id
117 #! /bin/bash
118 # FS QA Test No. $id
119 #
120 # what am I here for?
121 #
122 #-----------------------------------------------------------------------
123 # Copyright (c) $year YOUR NAME HERE.  All Rights Reserved.
124 #
125 # This program is free software; you can redistribute it and/or
126 # modify it under the terms of the GNU General Public License as
127 # published by the Free Software Foundation.
128 #
129 # This program is distributed in the hope that it would be useful,
130 # but WITHOUT ANY WARRANTY; without even the implied warranty of
131 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
132 # GNU General Public License for more details.
133 #
134 # You should have received a copy of the GNU General Public License
135 # along with this program; if not, write the Free Software Foundation,
136 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
137 #-----------------------------------------------------------------------
138 #
139
140 seq=\`basename \$0\`
141 seqres=\$RESULT_DIR/\$seq
142 echo "QA output created by \$seq"
143
144 here=\`pwd\`
145 tmp=/tmp/\$\$
146 status=1        # failure is the default!
147 trap "_cleanup; exit \\\$status" 0 1 2 3 15
148
149 _cleanup()
150 {
151         cd /
152         rm -f \$tmp.*
153 }
154
155 # get standard environment, filters and checks
156 . ./common/rc
157 . ./common/filter
158
159 # real QA test starts here
160
161 # Modify as appropriate.
162 _supported_fs generic
163 _supported_os IRIX Linux
164 _require_test
165
166 # if error
167 exit
168
169 # optional stuff if your test has verbose output to help resolve problems
170 #echo
171 #echo "If failure, check \$seqres.full (this) and \$seqres.full.ok (reference)"
172
173 # success, all done
174 status=0
175 exit
176 End-of-File
177
178 sleep 2         # latency to read messages to this point
179 echo ""
180
181 chmod 755 $tdir/$id
182 ${EDITOR-vi} $tdir/$id
183
184 if [ $# -eq 0 ]
185 then
186
187     while true
188     do
189         echo -n "Add to group(s) [other] (? for list): "
190         read ans
191         [ -z "$ans" ] && ans=other
192         if [ "X$ans" = "X?" ]
193         then
194             for d in $SRC_GROUPS; do
195                 l=$(sed -n < tests/$d/group \
196                     -e 's/#.*//' \
197                     -e 's/$/ /' \
198                     -e 's;\(^[0-9][0-9][0-9]\)\(.*$\);\2;p')
199                 grpl="$grpl $l"
200             done
201             lst=`for word in $grpl; do echo $word; done | sort| uniq `
202             echo $lst
203         else
204             break
205         fi
206     done
207 else
208     # expert mode, groups are on the command line
209     #
210     for g in $*
211     do
212         if grep "^$g[   ]" $tdir/group >/dev/null
213         then
214             :
215         else
216             echo "Warning: group \"$g\" not defined in $tdir/group"
217         fi
218     done
219     ans="$*"
220 fi
221
222 echo -n "Adding $id to group index ..."
223 head -n $(($line-1)) $tdir/group > /tmp/$$.group
224 echo "$id $ans" >> /tmp/$$.group
225 tail -n +$((line)) $tdir/group >> /tmp/$$.group
226 mv /tmp/$$.group $tdir/group
227 echo " done."
228
229 exit 0