pmrep: fix archive end time reporting
[pcp.git] / qa / new
blobaa77fde3412b4c158b8292f2ee6220fdf03fab57
1 #!/bin/sh
3 # Make a new PCP QA test
5 # Copyright (c) 1997-2002 Silicon Graphics, Inc. All Rights Reserved.
7 # Usage: new [base-seq-no group ...]
9 # base-seq-no defaults to some random place in the range $min-$max
12 # generic initialization
13 . ./common.rc
15 min=700
16 max=1099
18 tmp=/tmp/$$
19 trap "rm -f $tmp.*; exit" 0 1 2 3 15
21 _cleanup()
26 if [ "$USER" = "pcpqa" ]
27 then
28 if [ ! -z "$REMOTEUSER" -a "$REMOTEUSER" != UNKNOWN ]
29 then
30 USER=$REMOTEUSER
31 else
32 echo "Error: user \"pcpqa\" cannot create tests ... who are you?"
33 $PCP_ECHO_PROG $PCP_ECHO_N "Enter login: ""$PCP_ECHO_C"
34 read USER
35 if [ ! -z "$USER" ]
36 then
37 grep "^$USER:" /etc/passwd >/dev/null || USER=''
39 if [ -z "$USER" ]
40 then
41 echo "If you're not going to be serious, then I won't play"
42 exit 1
47 if [ ! -f group ]
48 then
49 echo "Creating the group index ..."
50 cat <<'End-of-File' >group
51 ## QA groups control
53 ## define groups
55 ## Do not start group name with a digit, expect alphabetic
57 ## Last comment starting with a single # before a group name is the
58 ## one-line summary that "new" will report when asked to list groups
60 ## Comments starting with a ## (or #<anything_other_than_whitesspace>
61 ## are ignored for the purposes of one-line summaries.
63 # catch-all
64 other
66 ## test-group association ... one line per test
67 ## add :retired or :reserved as a tag immediately after the test number
68 ## to keep the test number allocated, but prevent the test from being run
70 ## ... use sort -n from here on down to tidy up this mess
72 End-of-File
75 if [ ! -w group ]
76 then
77 echo "Error: cannot write index file \"group\""
78 _cleanup
79 exit 1
82 if [ -f GNUmakefile.install ]
83 then
84 # running QA in the tree
85 ${MAKE:-make} -f GNUmakefile.install >$tmp.out 2>&1
86 else
87 ${MAKE:-make} >$tmp.out 2>&1
89 if [ $? -ne 0 ]
90 then
91 cat $tmp.out
92 echo "Warning: ${MAKE:-make} failed -- some tests may be missing"
95 if [ $# -gt 0 ]
96 then
97 try=$1
98 shift
99 else
100 # random in the range $min-$max based on user name convered from alpha
101 # to numeric, prefixed by current clock seconds
103 sec=`date +%S`
104 try=`echo "$USER" \
105 | tr 'a-z' '0-90-90-9' \
106 | awk '{ srand('"$sec"'+$1); print int('$min'+rand()*('$max'-'$min')) }'`
108 # pick first hole after $try, provided the test does not already exist
110 wrap=0
111 while true
113 id=`sed -n -e 's/:\(retired\|reserved\) / /' -e '/^[0-9]/s/[ ].*//p' <group \
114 | LC_COLLATE=POSIX sort -n \
115 | $PCP_AWK_PROG '
116 BEGIN { last = '$try' }
117 $1 > '$try' { if ($1 != last+1) {
118 exit
120 last = $1
122 END { printf "%03d\n",last+1 }'`
123 [ ! -f $id ] && break
124 # already exists, move on ...
126 try=`expr $id + 1`
127 if [ "$try" -gt "$max" ]
128 then
129 wrap=`expr $wrap + 1`
130 if [ "$wrap" -eq 2 ]
131 then
132 echo "Sorry, no unassigned tests in the range $min ... $max. Time to increase \$max"
133 exit 1
135 try=$min
137 done
139 echo "Next test is $id"
141 if [ -f $id ]
142 then
143 echo "Error: test $id already exists!"
144 _cleanup
145 exit 1
148 $PCP_ECHO_PROG $PCP_ECHO_N "Creating skeletal script for you to edit ...""$PCP_ECHO_C"
150 cat <<End-of-File >$id
151 #!/bin/sh
152 # PCP QA Test No. $id
153 # [what am I here for?]
155 # Copyright (c) `date +%Y` [who are you?]. All Rights Reserved.
158 seq=\`basename \$0\`
159 echo "QA output created by \$seq"
161 # get standard environment, filters and checks
162 . ./common.product
163 . ./common.filter
164 . ./common.check
166 # test for-some-thing || _notrun No support for some-thing
168 status=1 # failure is the default!
169 \$sudo rm -rf \$tmp \$tmp.* \$seq.full
170 trap "cd \$here; rm -rf \$tmp \$tmp.*; exit \\\$status" 0 1 2 3 15
172 # real QA test starts here
174 # if error
175 exit
177 # optional stuff if your test has verbose output to help resolve problems
178 #echo
179 #echo "If failure, check \$seq.full"
181 # success, all done
182 status=0
184 exit
185 End-of-File
187 sleep 2 # latency to read messages to this point
188 echo ""
190 chmod 755 $id
191 ${EDITOR-vi} $id
193 if [ $# -eq 0 ]
194 then
195 while true
197 $PCP_ECHO_PROG $PCP_ECHO_N "Add to group(s) [other] (? for list): ""$PCP_ECHO_C"
198 read ans
199 [ -z "$ans" ] && ans=other
200 if [ "X$ans" = "X?" ]
201 then
202 $PCP_AWK_PROG <group '
203 BEGIN { text = "# ???" }
204 /^[a-zA-Z]/ { printf "%-16.16s %s\n",$1,text; text = "# ???"; next }
205 NF < 2 { next }
206 $1 == "#" { text = $0 }' \
207 | LC_COLLATE=POSIX sort
208 else
209 break
211 done
212 $PCP_ECHO_PROG $PCP_ECHO_N "Runs on QA machine alone? (local pmcd, local pmlogger, no ssh, ...) [y] ""$PCP_ECHO_C"
213 read _ans
214 if [ -z "$_ans" -o "$_ans" = "y" ]
215 then
216 ans="$ans local"
217 else
218 ans="$ans remote"
220 else
221 # expert mode, groups are on the command line
223 for g in $*
225 if grep "^$g[ ]" group >/dev/null
226 then
228 else
229 echo "Warning: group \"$g\" not defined in ./group"
231 done
232 ans="$*"
235 $PCP_ECHO_PROG $PCP_ECHO_N "Adding $id to group index ...""$PCP_ECHO_C"
236 echo "$id $ans" >>group
237 echo " done."
239 # sort the tests numerically
241 $PCP_AWK_PROG <group '
242 BEGIN { state = "head" }
243 state == "head" && /^[0-9]/ { state = "list" }
244 { print >"'$tmp'." state }'
245 sort -n $tmp.list >>$tmp.head
246 cp $tmp.head group
248 exit 0