c734bdc562bed49deddf2586aea48c122bd98513
[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 | tr - ' ' | $AWK_PROG '{ print $1 }'`
85 do
86     line=$((line+1))
87     if [ -z "$found" ] || [ "$found" == "#" ]; then
88         continue
89     elif ! echo "$found" | grep -q "^$VALID_TEST_NAME$"; then
90         # this one is for tests not named by a number
91         continue
92     fi
93     i=$((i+1))
94     id=`printf "%03d" $i`
95     if [ "$id" != "$found" ];then
96         eof=0
97         break
98     fi
99 done
100 if [ $eof -eq 1 ]; then
101    line=$((line+1))
102    i=$((i+1))
103    id=`printf "%03d" $i`
104 fi
105
106 echo "Next test id is $id"
107
108 read -p "Append a name to the ID? Test name will be $id-\$name. y,[n]: " -r
109 if [[ $REPLY = [Yy] ]]; then
110         # get the new name from user
111         name=""
112         while [ "$name" = "" ]; do
113                 read -p "Enter the name: "
114                 if [ "$REPLY" = "" ]; then
115                         echo "For canceling, use ctrl+c."
116                 elif echo "$id-$REPLY" | grep -q "^$VALID_TEST_NAME$"; then
117                         if [ -e "$tdir/$id-$REPLY" ]; then
118                                 echo "File '$id-$REPLY' already exists, use another one."
119                                 echo
120                         else
121                                 name="$REPLY"
122                         fi
123                 else
124                         echo "A name can contain only alphanumeric symbols and dash!"
125                         echo
126                 fi
127         done
128
129         # now find where to insert this name
130         eof=1
131         for found in `tail -n +$line $tdir/group | $AWK_PROG '{ print $1 }'`; do
132                 found_id=$(echo "$found" | cut -d "-" -f 1 - )
133                 line=$((line+1))
134                 if [ -z "$found" ] || [ "$found" == "#" ]; then
135                         continue
136                 elif [ $found_id -gt $id ]; then
137                         eof=0
138                         break
139                 fi
140         done
141         if [ $eof -eq 0 ]; then
142                 # If place wasn't found, let $line be the end of the file
143                 line=$((line-1))
144         fi
145         id="$id-$name"
146 fi
147 echo "Creating test file '$id'"
148
149 if [ -f $tdir/$id ]
150 then
151     echo "Error: test $id already exists!"
152     _cleanup
153     exit 1
154 fi
155
156 echo -n "Creating skeletal script for you to edit ..."
157
158 year=`date +%Y`
159
160 cat <<End-of-File >$tdir/$id
161 #! /bin/bash
162 # FS QA Test $id
163 #
164 # what am I here for?
165 #
166 #-----------------------------------------------------------------------
167 # Copyright (c) $year YOUR NAME HERE.  All Rights Reserved.
168 #
169 # This program is free software; you can redistribute it and/or
170 # modify it under the terms of the GNU General Public License as
171 # published by the Free Software Foundation.
172 #
173 # This program is distributed in the hope that it would be useful,
174 # but WITHOUT ANY WARRANTY; without even the implied warranty of
175 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
176 # GNU General Public License for more details.
177 #
178 # You should have received a copy of the GNU General Public License
179 # along with this program; if not, write the Free Software Foundation,
180 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
181 #-----------------------------------------------------------------------
182 #
183
184 seq=\`basename \$0\`
185 seqres=\$RESULT_DIR/\$seq
186 echo "QA output created by \$seq"
187
188 here=\`pwd\`
189 tmp=/tmp/\$\$
190 status=1        # failure is the default!
191 trap "_cleanup; exit \\\$status" 0 1 2 3 15
192
193 _cleanup()
194 {
195         cd /
196         rm -f \$tmp.*
197 }
198
199 # get standard environment, filters and checks
200 . ./common/rc
201 . ./common/filter
202
203 # real QA test starts here
204
205 # Modify as appropriate.
206 _supported_fs generic
207 _supported_os IRIX Linux
208 _require_test
209
210 # if error
211 exit
212
213 # optional stuff if your test has verbose output to help resolve problems
214 #echo
215 #echo "If failure, check \$seqres.full (this) and \$seqres.full.ok (reference)"
216
217 # success, all done
218 status=0
219 exit
220 End-of-File
221
222 sleep 2         # latency to read messages to this point
223 echo ""
224
225 chmod 755 $tdir/$id
226 ${EDITOR-vi} $tdir/$id
227
228 if [ $# -eq 0 ]
229 then
230
231     while true
232     do
233         echo -n "Add to group(s) [other] (? for list): "
234         read ans
235         [ -z "$ans" ] && ans=other
236         if [ "X$ans" = "X?" ]
237         then
238             for d in $SRC_GROUPS; do
239                 l=$(sed -n < tests/$d/group \
240                     -e 's/#.*//' \
241                     -e 's/$/ /' \
242                     -e 's;\(^[0-9][0-9][0-9]\)\(.*$\);\2;p')
243                 grpl="$grpl $l"
244             done
245             lst=`for word in $grpl; do echo $word; done | sort| uniq `
246             echo $lst
247         else
248             break
249         fi
250     done
251 else
252     # expert mode, groups are on the command line
253     #
254     for g in $*
255     do
256         if grep "^$g[   ]" $tdir/group >/dev/null
257         then
258             :
259         else
260             echo "Warning: group \"$g\" not defined in $tdir/group"
261         fi
262     done
263     ans="$*"
264 fi
265
266 echo -n "Adding $id to group index ..."
267 head -n $(($line-1)) $tdir/group > /tmp/$$.group
268 echo "$id $ans" >> /tmp/$$.group
269 tail -n +$((line)) $tdir/group >> /tmp/$$.group
270 mv /tmp/$$.group $tdir/group
271 echo " done."
272
273 exit 0