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