pmrep: fix archive end time reporting
[pcp.git] / qa / 440
blob6c5a8ed8ea40adcbeb0c230a93ab0618d02591a0
1 #!/bin/sh
2 # PCP QA Test No. 440
3 # pmlogger -v conditions
4 # Based on QA 252.
6 # Copyright (c) 1995-2002 Silicon Graphics, Inc. All Rights Reserved.
7 # Copyright (c) 2011 Ken McDonell. All Rights Reserved.
10 seq=`basename $0`
11 echo "QA output created by $seq"
13 # get standard environment, filters and checks
14 . ./common.product
15 . ./common.filter
16 . ./common.check
18 status=0 # success is the default!
19 $sudo rm -rf $tmp $tmp.* $seq.full
20 trap "rm -f $tmp $tmp.*; exit \$status" 0 1 2 3 15
22 # real QA test starts here
24 pmdumplog='pmdumplog'
25 pmlogger='pmlogger'
26 SECS_TOL=2 # number of seconds tolerance
29 _clean_archive()
31 rm -f $tmp.log $tmp.[0-9]* $tmp.index $tmp.meta
34 # Is given value within tolerance of expected value
35 _tolerance()
37 expected=$1
38 given=$2
39 tolerance=$3
40 upper_limit=`expr $expected + $tolerance`
41 lower_limit=`expr $expected - $tolerance`
42 [ $lower_limit -le $given -a $given -le $upper_limit ]
45 _num_recs()
47 num_recs=`$pmdumplog $tmp | egrep -c '^[0-9][0-9]:[0-9][0-9]:'`
48 # subtract 1 for the preamble
49 num_recs=`expr $num_recs - 1`
50 echo "found $num_recs samples after the preamble" >>$seq.full
53 _test_sample_size()
55 vol_arg=$1
56 size_arg=$2
57 num_vol=$3 # volumes expected
58 echo "_test_sample_size $@" >>$seq.full
59 $pmlogger -v $vol_arg -s $size_arg -c $tmp.config -l $tmp.log $tmp
60 cat $tmp.log >>$seq.full
61 ls -l $tmp.* >>$seq.full
62 if [ -f $tmp.0 ]
63 then
64 vol=`ls $tmp.[0-9]* | wc -l | sed -e 's/ //g'`
65 else
66 vol=0
68 echo "vol=$vol num_vol=$num_vol" >>$seq.full
69 if [ "$vol" != "$num_vol" ]
70 then
71 echo "Error: Number of volumes is $vol, expected $num_vol" | tee -a $seq.full
72 ls -l $tmp.[0-9]*
73 cat $tmp.log
74 $pmdumplog -a $tmp >>$seq.full
77 _num_recs
78 if [ "$size_arg" = "$num_recs" ]
79 then
80 echo "Log size for $size_arg and volume size for $vol_arg is correct" | tee -a $seq.full
81 else
82 echo "Error: Log contains $num_recs samples, expected $size_arg" | tee -a $seq.full
83 ls -l $tmp.*
84 cat $tmp.log
85 $pmdumplog -a $tmp >>$seq.full
87 _clean_archive
90 # Find out number of records, n, for given size
91 # Then make sure for (n-1) records that the size is smaller
92 _test_file_size()
94 vol_arg=$1
95 size_arg=$2
96 num_vol=$3 # volumes expected
97 num_bytes=$4 # bytes expected
98 echo "_test_file_size $@" >>$seq.full
99 $pmlogger -v $vol_arg -s $size_arg -c $tmp.config -l $tmp.log $tmp
100 cat $tmp.log >>$seq.full
101 ls -l $tmp.* >>$seq.full
102 if [ -f $tmp.0 ]
103 then
104 vol=`ls $tmp.[0-9]* | wc -l | sed -e 's/ //g'`
105 bigger_size=`ls -l $tmp.[0-9]* | $PCP_AWK_PROG '{t += $5} END {print t}'`
106 else
107 vol=0
108 bigger_size=-1
110 echo "bigger_size=$bigger_size" >>$seq.full
111 echo "vol=$vol num_vol=$num_vol" >>$seq.full
112 if [ "$vol" != "$num_vol" ]
113 then
114 echo "Error: Number of volumes is $vol, expected $num_vol" | tee -a $seq.full
115 ls -l $tmp.[0-9]*
116 cat $tmp.log
117 $pmdumplog -a $tmp >>$seq.full
119 _num_recs
120 echo "num_recs=$num_recs" >>$seq.full
121 num_recs=`expr $num_recs - 1`
122 if [ $num_recs -gt 0 ]
123 then
124 _clean_archive
125 $pmlogger -v $vol_arg -s $num_recs -c $tmp.config -l $tmp.log $tmp
126 cat $tmp.log >>$seq.full
127 ls -l $tmp.* >>$seq.full
128 if [ -f $tmp.0 ]
129 then
130 smaller_size=`ls -l $tmp.[0-9]* | $PCP_AWK_PROG ' {t += $5} END {print t}'`
131 else
132 smaller_size=-1
134 else
135 smaller_size=-1
137 echo "smaller_size=$smaller_size" >>$seq.full
138 if [ $smaller_size -le $num_bytes -a $num_bytes -le $bigger_size ]
139 then
140 echo "Log size for $size_arg and volume size for $vol_arg is correct" | tee -a $seq.full
141 else
142 echo "Error: Log size $num_bytes is not within range $smaller_size - $bigger_size" | tee -a $seq.full
143 ls -l $tmp.*
144 cat $tmp.log
145 $pmdumplog -a $tmp >>$seq.full
147 _clean_archive
150 _time_me ()
152 # return time in seconds
154 # /usr/bin/time IS bloody important - dont port-sh it. EVER!
155 /usr/bin/time $* 2>&1 >/dev/null | \
156 if [ $PCP_PLATFORM = linux ]
157 then
158 # 0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 2752maxresident)k
159 tr ' ' "\n" | $PCP_AWK_PROG '/elapsed$/ { sub("elapsed", "", $1);
160 split ($1,tt,"[:.]");
161 print (tt[1]*60)+tt[2];}'
162 elif [ $PCP_PLATFORM = darwin ]
163 then
164 # 0.00 real 0.00 user 0.00 sys
165 $PCP_AWK_PROG '{print $1}' | sed -e 's/\..*//'
166 else
167 # real 0.0
168 # user 0.0
169 # sys 0.0
170 $PCP_AWK_PROG '/^real/ {print $2}' | sed -e 's/\..*//'
174 # Note: size arg should be given in secs for comparison with /usr/bin/time
175 _test_time_size()
177 vol_arg=$1
178 size_arg=$2
179 num_vol=$3 # volumes expected
180 num_sec=$4 # elapsed seconds expected
181 echo "_test_time_size $@" >>$seq.full
182 time=`_time_me $pmlogger -v $vol_arg -s $size_arg -c $tmp.config -l $tmp.log $tmp`
183 [ -z "$time" ] && time=-1
184 cat $tmp.log >>$seq.full
185 ls -l $tmp.* >>$seq.full
186 if [ -f $tmp.0 ]
187 then
188 vol=`ls $tmp.[0-9]* | wc -l | sed -e 's/ //g'`
189 else
190 vol=0
192 echo "vol=$vol num_vol=$num_vol" >>$seq.full
193 if [ "$vol" != "$num_vol" ]
194 then
195 echo "Error: Number of volumes is $vol, expected $num_vol" | tee -a $seq.full
196 ls -l $tmp.[0-9]*
197 cat $tmp.log
198 $pmdumplog -a $tmp >>$seq.full
200 if _tolerance $num_sec $time $SECS_TOL
201 then
202 echo "Log time for $num_sec and volume time for $vol_arg is correct" | tee -a $seq.full
203 else
204 echo "Error: Log time $time, expected $num_sec +/- $SECS_TOL" | tee -a $seq.full
205 ls -l $tmp.*
206 cat $tmp.log
207 $pmdumplog -a $tmp >>$seq.full
209 _clean_archive
212 # Create a simple configuration file for testing
213 cat <<EOF >$tmp.config
214 # pmlogger(1) configuration file for doing QA tests
216 log mandatory on 10 msec {
217 sample.control
218 sample.milliseconds
219 sample.load
220 sample.colour
221 sample.bin
222 sample.bucket
223 sample.drift
224 sample.step
225 sample.write_me
226 sample.lights
227 sample.magnitude
228 sample.pdu
229 sample.recv_pdu
230 sample.xmit_pdu
231 sample.noinst
235 # real QA test starts here
237 # Test out -v and -s
238 _test_file_size 2000BYTE "4000bytes" 2 4000
239 _test_file_size 1024b "4K" 4 4096
240 _test_file_size 10Mbyte "4kilobytes" 1 4096
241 _test_file_size 3K 4194B 2 4194
242 _test_sample_size 3 8 3
243 _test_time_size 3.5secs 5secs 2 5
245 # Some error conditions
246 $pmlogger -v 3bozobyte -s 10 -c /dev/null $tmp 2>&1 | sed -e '/Usage/q'
247 $pmlogger -v 5 -s 3bozobyte -c /dev/null $tmp 2>&1 | sed -e '/Usage/q'
248 $pmlogger -v-1 -s 10 -c /dev/null $tmp 2>&1 | sed -e '/Usage/q'
249 $pmlogger -v 5 -s-1 -c /dev/null $tmp 2>&1 | sed -e '/Usage/q'
250 $pmlogger -v 0.5Mbyte -s 10 -c /dev/null $tmp 2>&1 | sed -e '/Usage/q'
251 $pmlogger -v 5 -s 0.5K -c /dev/null $tmp 2>&1 | sed -e '/Usage/q'
252 $pmlogger -v 0.03 -s 10 -c /dev/null $tmp 2>&1 | sed -e '/Usage/q'
253 $pmlogger -v 5 -s 0.03 -c /dev/null $tmp 2>&1 | sed -e '/Usage/q'
255 # success, all done
256 exit