src: include <sys/sysmacros.h> for major() and minor()
[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 # remove previous \$seqres.full before test
204 rm -f \$seqres.full
205
206 # real QA test starts here
207
208 # Modify as appropriate.
209 _supported_fs generic
210 _supported_os Linux
211 _require_test
212
213 # if error
214 exit
215
216 # optional stuff if your test has verbose output to help resolve problems
217 #echo
218 #echo "If failure, check \$seqres.full (this) and \$seqres.full.ok (reference)"
219
220 # success, all done
221 status=0
222 exit
223 End-of-File
224
225 sleep 2         # latency to read messages to this point
226 echo ""
227
228 chmod 755 $tdir/$id
229 ${EDITOR-vi} $tdir/$id
230
231 # Create default .out file
232 cat <<End-of-File >$tdir/$id.out
233 QA output created by $id
234 Silence is golden
235 End-of-File
236
237 if [ $# -eq 0 ]
238 then
239
240     while true
241     do
242         echo -n "Add to group(s) [other] (? for list): "
243         read ans
244         [ -z "$ans" ] && ans=other
245         if [ "X$ans" = "X?" ]
246         then
247             for d in $SRC_GROUPS; do
248                 l=$(sed -n < tests/$d/group \
249                     -e 's/#.*//' \
250                     -e 's/$/ /' \
251                     -e 's;\(^[0-9][0-9][0-9]\)\(.*$\);\2;p')
252                 grpl="$grpl $l"
253             done
254             lst=`for word in $grpl; do echo $word; done | sort| uniq `
255             echo $lst
256         else
257             break
258         fi
259     done
260 else
261     # expert mode, groups are on the command line
262     #
263     for g in $*
264     do
265         if grep "^$g[   ]" $tdir/group >/dev/null
266         then
267             :
268         else
269             echo "Warning: group \"$g\" not defined in $tdir/group"
270         fi
271     done
272     ans="$*"
273 fi
274
275 echo -n "Adding $id to group index ..."
276 head -n $(($line-1)) $tdir/group > /tmp/$$.group
277 echo "$id $ans" >> /tmp/$$.group
278 tail -n +$((line)) $tdir/group >> /tmp/$$.group
279 mv /tmp/$$.group $tdir/group
280 echo " done."
281
282 exit 0