-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
381 lines (333 loc) · 13.5 KB
/
test.sh
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#!/bin/sh
# not tested here:
# multilog handles TERM (tested manually)
# multilog handles ALRM (tested manually)
# multilog handles out-of-memory (next to impossible to do right)
# multilog t produces the right time (next to impossible to do right)
# multilog closes descriptors properly (system dependencies ahead)
PATH=".:$PATH"
mkdir test.tmp.$$ || exit 1
cd test.tmp.$$
cleanup() {
if test "$COVER" = 1 ; then
mv cover.out ..
fi
cd ..
rm -rf test.tmp.$$
}
trap cleanup EXIT
M="../multislog "
if test "$COVER" = "1" ; then
M="../multislog.test -test.coverprofile=cover1.out"
echo | $M -- --version
mv cover1.out cover.out
fi
docover() {
if test "$COVER" = 1 ; then
gocovmerge cover.out cover1.out >t.out
mv t.out cover.out
fi
}
echo '--- multilog prints nothing with no actions'
( echo one; echo two ) | $M ; echo $?
docover
echo '--- multilog e prints to stderr'
( echo one; echo two ) | $M e 2>&1; echo $?
docover
echo '--- multilog inserts newline after partial final line'
( echo one; echo two | tr -d '\012' ) | $M e 2>&1; echo $?
docover
echo '--- multilog handles multiple actions'
( echo one; echo two ) | $M e e 2>&1; echo $?
docover
echo '--- multilog handles wildcard -'
( echo one; echo two ) | $M '-*' e 2>&1; echo $?
docover
echo '--- multilog handles literal +'
( echo one; echo two ) | $M '-*' '+one' e 2>&1; echo $?
docover
echo '--- multilog handles long lines for stderr'
echo 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678 \
| $M e 2>&1; echo $?
docover
echo 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 \
| $M e 2>&1; echo $?
docover
echo 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 \
| $M e 2>&1; echo $?
docover
echo '--- multilog handles status files'
rm -f test.status
( echo one; echo two ) | $M =test.status; echo $?
docover
uniq -c < test.status | sed 's/[ ]*[ ]/_/g'
echo '--- multilog t has the right format on stderr'
( echo ONE; echo TWO ) | $M t e 2>&1 | sed 's/[0-9a-f]/x/g'
docover
echo '--- multilog t has the right format in status files'
( echo ONE; echo TWO ) | $M t =test.status ; echo $?
cat test.status | sed 's/[0-9a-f]/x/g' |head -1
docover
echo '--- multilog t ./x has the right format'
( echo ONE; echo TWO ) | $M t ./x 2>&1 ; echo $?
docover
sed 's/[0-9a-f]/x/g' < x/current
rm -rf x
echo '--- multilog ./x inserts newline after partial final line'
( echo one; echo two | tr -d '\012' ) | $M ./x ; echo $?
docover
cat x/current
rm -rf x
echo '--- multilog ./x handles overlong lines'
( echo 1234567890abcdef ; echo 123456; echo 123456123456 ; echo 123 ) | MULTISLOG_BUFLEN=6 $M ./x ; echo $?
docover
cat x/current
rm -rf x
echo '--- multilog t ./x handles overlong lines'
( echo ABCDEFGIHJKLMNOP ; echo ABCDEF; echo ABCDEFABCDEF ; echo ABC ) | MULTISLOG_BUFLEN=6 $M t ./x ; echo $?
docover
sed 's/[0-9a-f]/x/g' < x/current
rm -rf x
echo '--- multilog t ./x handles overlong lines'
( echo ABCDEFGIHJKLMNOP ; echo ABCDEF; echo ABCDEFABCDEF ; echo ABC ) | MULTISLOG_BUFLEN=6 $M t ./x ; echo $?
docover
sed 's/[0-9a-f]/x/g' < x/current
rm -rf x
echo '--- multilog ./x s4096 works'
( for i in `seq 1 257` ; do echo 0123456789abcde ; done ) | $M s4096 ./x ; echo $?
docover
cat x/current
od -tx1 x/\@*
rm -rf x
echo '--- multilog ./x s4096 n3 works'
( for i in `seq 1 513` ; do echo 0123456789abcde ; done ) | $M n3 s4096 ./x ; echo $?
docover
cat x/current
od -tx1 x/@*
rm -rf x
echo '--- multilog ./x s4096 n2 works'
( for i in `seq 1 513` ; do echo 0123456789abcde ; done ) | $M n2 s4096 ./x ; echo $?
docover
cat x/current
od -tx1 x/@*
rm -rf x
echo '--- multilog ./x s8192 n2 works'
( for i in `seq 1 1025` ; do echo 0123456789abcde ; done ) | $M n2 s8192 ./x ; echo $?
docover
cat x/current
od -tx1 x/@*
rm -rf x
echo '--- multilog ./x s8192 n2 works'
( for i in `seq 1 1025` ; do echo 0123456789abcde ; done ) | $M n2 s8192 ./x ; echo $?
docover
cat x/current
od -tx1 x/@*
rm -rf x
echo '--- multilog ./x !sed work'
( for i in `seq 1 1025` ; do echo 0123456789abcde ; done ) | $M n2 s4096 "!sed s/e/f/g" ./x ; echo $?
docover
cat x/current
od -tx1 x/@*
# deliberate change from multilog behaviour: multilog deletes state at start, which at least is
# undocumentated behaviour, but most likely a bug.
echo '--- multilog ./x !sed works with state'
rm x/@* x/current
echo 'eeeeee' >x/state
( for i in `seq 1 256` ; do echo 0123456789abcde ; done ) | \
$M n2 s4096 "!cat ; sed s/e/f/g <&4 >&5" ./x ; echo $?
docover
echo
echo -n current: ; cat x/current ; echo
echo -n state: ; cat x/state ; echo
echo "od:"
od -tx1 x/@*
rm -rf x
echo '--- multilog ./x ! repeats if processor fails'
( for i in `seq 1 257` ; do echo 0123456789abcde ; done ) | \
$M n2 s4096 "!if test -f testflag ; then echo done ; exit 0; else echo failed; touch testflag ; exit 1; fi " ./x 2>/dev/null ; echo $?
docover
cat x/current
cat x/@*
test -f x/testflag && echo "testflag set"
od -tx1 x/@*
rm -rf x
echo '--- multilog ./x continues cleanly after stop'
( for i in `seq 1 1` ; do echo 0123456789abcde ; done ) | $M n2 s4096 ./x ; echo $?
docover
test -x x/current || echo "current has no x bit"
test -x x/current && echo "current has x bit"
( for i in `seq 1 1` ; do echo 0123456789abcde ; done ) | $M n2 s4096 ./x ; echo $?
docover
od -tx1 x/current
rm -rf x
echo '--- multilog ./x continues cleanly after crash'
( for i in `seq 1 1` ; do echo 0123456789abcde ; done ) | $M n2 s4096 ./x ; echo $?
docover
chmod -x x/current
( for i in `seq 1 1` ; do echo 0123456789abcde ; done ) | $M n2 s4096 ./x ; echo $?
docover
test -x x/current || echo "current has no x bit"
test -x x/current && echo "current has x bit"
echo current:; od -tx1 x/current
echo .u: ; od -tx1 x/\@*.u
rm -rf x
echo '--- multilog n1 is corrected to 2'
( echo 111111111111111; echo aaaaaaaaaaaaa ; echo ZZZZZZZZZZZZZZZ ) | \
MULTISLOG_BUFSIZE=15 $M n1 s10 ./x 2>&1 ; echo $?
docover
echo current:; od -tx1 x/current
echo .s: ; od -tx1 x/\@*.s
# all options.
echo '--- multilog -a* deselects'
echo 'anything' | $M '-a*' e 2>&1
docover
echo '--- multilog +* selects everything'
echo 'anything' | $M '-*' '+*' e 2>&1
docover
echo '--- multilog handles negative size or number'
echo 'anything' | $M s-999 2>&1 ; echo $?
docover
echo 'anything' | $M n-999 2>&1 ; echo $?
docover
echo '--- multilog parses facility.severity'
echo 'anything' | $M pkern.emerg 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.emer 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.emergx 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.alert 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.aler 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.alertx 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.crit 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.cri 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.critx 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.err 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.er 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.errx 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.warning 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.warnin 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.warningx 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.info 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.inf 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.infox 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.debu 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.debugx 2>&1 ; echo $? ; docover
echo 'anything' | $M pkern.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pker.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pkernx.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M puser.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M puse.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M puserx.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pmail.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pmai.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pmailx.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pdaemon.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pdaemo.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pdaemonx.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pauth.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M paut.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pauthx.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M psyslog.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M psyslo.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M psyslogx.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M plpr.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M plp.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M plprx.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pnews.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pnew.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pnewsx.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M puucp.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M puuc.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M puucpx.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pcron.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pcro.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pcronx.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pauthpriv.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pauthpri.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pauthprivx.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pftp.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pft.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pftpx.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pntp.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pnt.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pntpx.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M paudit.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M paudi.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M pauditx.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M plpr.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M plp.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M plprx.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M plocal0.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M plocal.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M plocal0x.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M plocal8.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M p.debug 2>&1 ; echo $? ; docover
echo 'anything' | $M p.debu 2>&1 ; echo $? ; docover
echo 'anything' | $M puser 2>&1 ; echo $? ; docover
echo 'anything' | $M puse 2>&1 ; echo $? ; docover
echo '--- multilog t t- works'
echo 0123456789abcde | $M t e 2>&1 | sed 's/[0-9a-f]/x/g' ; echo $?
echo 0123456789abcde | $M t t- e 2>&1 ; echo $?
docover
echo '--- multilog tbad fails'
echo 0123456789abcde | $M tbad e 2>&1 ; echo $?
docover
echo '--- multilog i is known'
echo 0123456789abcde | $M imsgid e 2>&1 ; echo $?
docover
echo '--- multilog $ is unknown'
echo 0123456789abcde | $M \$ e 2>&1 ; echo $?
docover
echo '--- multilog d(one) works'
echo 0123456789abcde | $M d e 2>&1 ; echo $?
docover
echo '--- multilog d(one) works if selected'
echo oldstuff, must not change >test.status
echo 0123456789abcde | $M "-*" +0* e d =test.status 2>&1 ; echo $?
cat test.status | head -1
docover
echo '--- multilog d(one) does not break loop if unselected'
echo oldstuff, must change >test.status
echo 0123456789abcde | $M "-*" e d +0* =test.status 2>&1 ; echo $?
cat test.status | head -1
docover
# this checks the d bug where d did lead to not clearing the selected flag on later things.
echo '--- multilog longer match'
echo oldstuff, must change >test.status
echo oldstuff, must change2 >test2.status
(
echo "delivery 7850: failure: Sorry,_I_couldn't_find_a_mail_exchanger_or_IP_address._(#5.4.4)/"
echo "starting delivery 7850: msg ..."
echo "delivery 7851: failure: Sorry,_I_couldn't_find_a_mail_exchanger_or_IP_address._(#5.4.4)/"
) | \
$M "-*" "+delivery *: failure:*" =test.status d \
"+*" =test2.status \
2>&1 ; echo $?
cat test.status | head -1
cat test2.status | head -1
docover
echo '--- multilog tUnix: timestamp in seconds since epoch'
echo "content" | $M tUnix e 2>&1 | sed 's/[0-9]/d/g' |awk '{print length($0)" "$0}'
docover
echo '--- multilog tUnixMs: timestamp in seconds since epoch with ms'
echo "content" | $M tUnixMs e 2>&1 | sed 's/[0-9]/d/g' |awk '{print length($0)" "$0}'
docover
echo '--- multilog tUnixUs: timestamp in seconds since epoch with us'
echo "content" | $M tUnixUs e 2>&1 | sed 's/[0-9]/d/g' |awk '{print length($0)" "$0}'
docover
echo '--- multilog tUnixNs: timestamp in seconds since epoch with ns'
echo "content" | $M tUnixNs e 2>&1 | sed 's/[0-9]/d/g' |awk '{print length($0)" "$0}'
docover
echo '--- multilog tRFC3339: timestamp in RFC3339 format'
echo "content" | TZ=MET $M tRFC3339 e 2>&1 | sed 's/[0-9]/d/g' |awk '{print length($0)" "$0}'
docover
echo '--- multilog tRFC3339Nano: timestamp in RFC3339 format with ns'
# trailing zeros are omitted in 339Nano...
echo "content" | TZ=MET $M tRFC3339Nano e 2>&1 | sed 's/[0-9]/d/g' | sed 's/d*+/DXX+/' |awk '{print length($0)" "$0}'
docover
echo '--- multilog tT: timestamp in RFC3339 format with ns'
# trailing zeros are omitted in 339Nano...
echo "content" | TZ=MET $M tT e 2>&1 | sed 's/[0-9]/d/g' | sed 's/d*+/DXX+/' |awk '{print length($0)" "$0}'
docover
if test "$COVER" = "1" ; then
exit 0
fi