xfs/220: avoid failure when disabling quota accounting is not supported
[xfstests-dev.git] / new
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2005 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # Make a new test
6 #
7
8 # generic initialization
9 iam=new
10 . ./common/test_names
11
12 tmpfile="/tmp/$$."
13 trap "rm -f $tmpfile; exit" 0 1 2 3 15
14
15 _cleanup()
16 {
17     :
18 }
19
20 SRC_GROUPS=`find tests -not -path tests -type d -printf "%f "`
21 usage()
22 {
23     echo "Usage $0 test_dir|test_dir_and_name"
24     echo "Available dirs are: $SRC_GROUPS"
25     exit
26 }
27
28 [ $# -eq 0 ] && usage
29
30 if echo "$1" | grep -q '/'; then
31         if [ -e "tests/$1" ]; then
32                 echo "$1: test already exists."
33                 exit 1
34         fi
35         tdir="tests/$(echo "$1" | cut -d '/' -f 1)"
36         id="$(echo "$1" | cut -d '/' -f 2)"
37 else
38         tdir=tests/$1
39         id="$(basename "$(./tools/nextid "$1")")"
40 fi
41
42 i=0
43 line=0
44 eof=1
45 [ -d "$tdir/" ] || usage
46
47 export AWK_PROG="$(type -P awk)"
48 [ "$AWK_PROG" = "" ] && { echo "awk not found"; exit; }
49
50 echo "Next test id is $id"
51 shift
52
53 read -p "Append a name to the ID? Test name will be $id-\$name. y,[n]: " -r
54 if [[ $REPLY = [Yy] ]]; then
55         # get the new name from user
56         name=""
57         while [ "$name" = "" ]; do
58                 read -p "Enter the name: "
59                 if [ "$REPLY" = "" ]; then
60                         echo "For canceling, use ctrl+c."
61                 elif echo "$id-$REPLY" | grep -q "^$VALID_TEST_NAME$"; then
62                         if [ -e "$tdir/$id-$REPLY" ]; then
63                                 echo "File '$id-$REPLY' already exists, use another one."
64                                 echo
65                         else
66                                 name="$REPLY"
67                         fi
68                 else
69                         echo "A name can contain only alphanumeric symbols and dash!"
70                         echo
71                 fi
72         done
73
74         id="$id-$name"
75 fi
76
77 echo "Creating test file '$id'"
78
79 if [ -f $tdir/$id ]
80 then
81     echo "Error: test $id already exists!"
82     _cleanup
83     exit 1
84 fi
85
86 if [ $# -eq 0 ]
87 then
88
89     while true
90     do
91         echo -n "Add to group(s) [other] (separate by space, ? for list): "
92         read ans
93         [ -z "$ans" ] && ans=other
94         if [ "X$ans" = "X?" ]
95         then
96             for d in $SRC_GROUPS; do
97                 (cd "tests/$d/" ; ../../tools/mkgroupfile "$tmpfile")
98                 l=$(sed -n < "$tmpfile" \
99                     -e 's/#.*//' \
100                     -e 's/$/ /' \
101                     -e 's;\(^[0-9][0-9][0-9]\)\(.*$\);\2;p')
102                 grpl="$grpl $l"
103             done
104             lst=`for word in $grpl; do echo $word; done | sort| uniq `
105             echo $lst
106         else
107             # only allow lower cases, spaces, digits and underscore in group
108             inval=`echo $ans | tr -d '[:lower:][:space:][:digit:]_'`
109             if [ "$inval" != "" ]; then
110                 echo "Invalid characters in group(s): $inval"
111                 echo "Only lower cases, digits and underscore are allowed in groups, separated by space"
112                 continue
113             else
114                 # remove redundant spaces/tabs
115                 ans=`echo "$ans" | sed 's/\s\+/ /g'`
116                 break
117             fi
118         fi
119     done
120 else
121     # expert mode, groups are on the command line
122     #
123     (cd "$tdir" ; ../../tools/mkgroupfile "$tmpfile")
124     for g in $*
125     do
126         if ! grep -q "[[:space:]]$g" "$tmpfile"; then
127             echo "Warning: group \"$g\" not defined in $tdir tests"
128         fi
129     done
130     ans="$*"
131 fi
132
133 echo -n "Creating skeletal script for you to edit ..."
134
135 year=`date +%Y`
136
137 cat <<End-of-File >$tdir/$id
138 #! /bin/bash
139 # SPDX-License-Identifier: GPL-2.0
140 # Copyright (c) $year YOUR NAME HERE.  All Rights Reserved.
141 #
142 # FS QA Test $id
143 #
144 # what am I here for?
145 #
146 . ./common/preamble
147 _begin_fstest $ans
148
149 # Override the default cleanup function.
150 # _cleanup()
151 # {
152 #       cd /
153 #       rm -r -f \$tmp.*
154 # }
155
156 # Import common functions.
157 # . ./common/filter
158
159 # real QA test starts here
160
161 # Modify as appropriate.
162 _supported_fs generic
163 _require_test
164
165 # if error
166 exit
167
168 # optional stuff if your test has verbose output to help resolve problems
169 #echo
170 #echo "If failure, check \$seqres.full (this) and \$seqres.full.ok (reference)"
171
172 # success, all done
173 status=0
174 exit
175 End-of-File
176
177 sleep 2         # latency to read messages to this point
178 echo ""
179
180 chmod 755 $tdir/$id
181 ${EDITOR-vi} $tdir/$id
182
183 # Create default .out file
184 cat <<End-of-File >$tdir/$id.out
185 QA output created by $id
186 Silence is golden
187 End-of-File
188
189 echo " done."
190 exit 0