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