5 # A regular expression matching the format of an RFC-5424 log line header,
6 # including the timestamp up through the seconds indicator; it does not include
7 # the (optional) timezone offset.
8 RFC5424_FMT='^<[0-9][0-9]*>1 [0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}'
10 # A regular expression matching the format of an RFC-3164 (traditional syslog)
11 # log line header, including the timestamp.
12 RFC3164_FMT='^[A-Z][a-z]{2} [ 0-9][0-9] [0-9]{2}:[0-9]{2}:[0-9]{2}'
17 echo "$0: Can't create temp dir, exiting..."
21 # Begin an individual test
24 COUNT=`expr $COUNT + 1`
29 # End an individual test
41 message="$message $COUNT - $NAME"
44 message="$message # TODO $TODO"
50 # Make a file that can later be verified
57 # Verify that the file specified is correct
60 if [ -f $2 ] && echo "$1-$1" | diff - $2 >/dev/null
68 # Check that a file exists
79 # Verify that the specified file does not exist
91 # Check if a file is there, depending of if it's supposed to or not -
92 # basically how many log files we are supposed to keep vs. how many we
100 if [ $curcnt -le $keepcnt ]
102 #echo Assuming file there
105 #echo Assuming file NOT there
110 # Verify that the specified file has RFC-5424 rotation messages.
113 local lc=$(wc -l $1 | cut -w -f2)
114 local rc=$(grep -cE "${RFC5424_FMT}" $1)
115 if [ "$lc" -eq 0 -o "$rc" -eq 0 -o "$lc" -ne "$rc" ]
124 # Verify that the specified file has RFC-3164 rotation messages.
127 local lc=$(wc -l $1 | cut -w -f2)
128 local rc=$(grep -cE "${RFC3164_FMT}" $1)
129 if [ "$lc" -eq 0 -o "$rc" -eq 0 -o "$lc" -ne "$rc" ]
138 # A part of a test succeeds
144 # A part of a test fails
150 # Verify that the exit code passed is for unsuccessful termination
161 # Verify that the exit code passed is for successful termination
172 # Check that there are X files which match expr
176 if [ $cnt -eq `echo "$@" | wc -w` ]
184 # Check that two strings are alike
197 mkdir -p ${TMPDIR}/log ${TMPDIR}/alog
204 rm -rf "${TMPDIR}/log" "${TMPDIR}/alog" newsyslog.conf
210 newsyslog -f ../newsyslog.conf -F -r "$@"
213 tests_normal_rotate() {
217 if [ -n "$dir" ]; then
218 newsyslog_args=" -a ${dir}"
219 name_postfix="${ext} archive dir"
222 name_postfix="${ext}"
227 begin "create file ${name_postfix}" -newdir
230 cknt ${dir}${LOGFNAME}.0${ext}
233 begin "rotate normal 1 ${name_postfix}"
234 run_newsyslog $newsyslog_args
236 ckfe ${dir}${LOGFNAME}.0${ext}
237 cknt ${dir}${LOGFNAME}.1${ext}
240 begin "rotate normal 2 ${name_postfix}"
241 run_newsyslog $newsyslog_args
243 ckfe ${dir}${LOGFNAME}.0${ext}
244 ckfe ${dir}${LOGFNAME}.1${ext}
245 cknt ${dir}${LOGFNAME}.2${ext}
248 begin "rotate normal 3 ${name_postfix}"
249 run_newsyslog $newsyslog_args
251 ckfe ${dir}${LOGFNAME}.0${ext}
252 ckfe ${dir}${LOGFNAME}.1${ext}
253 ckfe ${dir}${LOGFNAME}.2${ext}
254 cknt ${dir}${LOGFNAME}.3${ext}
257 begin "rotate normal 4 ${name_postfix}"
258 run_newsyslog $newsyslog_args
260 ckfe ${dir}${LOGFNAME}.0${ext}
261 ckfe ${dir}${LOGFNAME}.1${ext}
262 ckfe ${dir}${LOGFNAME}.2${ext}
263 cknt ${dir}${LOGFNAME}.4${ext}
266 begin "rotate normal 5 ${name_postfix}"
267 run_newsyslog $newsyslog_args
269 ckfe ${dir}${LOGFNAME}.0${ext}
270 ckfe ${dir}${LOGFNAME}.1${ext}
271 ckfe ${dir}${LOGFNAME}.2${ext}
272 cknt ${dir}${LOGFNAME}.4${ext}
275 # Wait a bit so we can see if the noaction test rotates files
278 begin "noaction ${name_postfix}"
279 ofiles=`ls -Tl ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`
280 run_newsyslog ${newsyslog_args} -n >/dev/null
282 ckstr "$ofiles" "`ls -lT ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`"
288 tests_normal_rotate_keepn() {
293 if [ -n "$dir" ]; then
294 newsyslog_args=" -a ${dir}"
295 name_postfix="${ext} archive dir"
298 name_postfix="${ext}"
303 begin "create file ${name_postfix}" -newdir
306 cknt ${dir}${LOGFNAME}.0${ext}
309 begin "rotate normal 1 cnt=$cnt ${name_postfix}"
310 run_newsyslog $newsyslog_args
312 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
313 cknt ${dir}${LOGFNAME}.1${ext}
316 begin "rotate normal 2 cnt=$cnt ${name_postfix}"
317 run_newsyslog $newsyslog_args
319 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
320 ckntfe 2 $cnt ${dir}${LOGFNAME}.1${ext}
321 cknt ${dir}${LOGFNAME}.2${ext}
324 begin "rotate normal 3 cnt=$cnt ${name_postfix}"
325 run_newsyslog $newsyslog_args
327 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
328 ckntfe 2 $cnt ${dir}${LOGFNAME}.1${ext}
329 ckntfe 3 $cnt ${dir}${LOGFNAME}.2${ext}
330 cknt ${dir}${LOGFNAME}.3${ext}
333 begin "rotate normal 3 cnt=$cnt ${name_postfix}"
334 run_newsyslog $newsyslog_args
336 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
337 ckntfe 2 $cnt ${dir}${LOGFNAME}.1${ext}
338 ckntfe 3 $cnt ${dir}${LOGFNAME}.2${ext}
339 ckntfe 4 $cnt ${dir}${LOGFNAME}.3${ext}
340 cknt ${dir}${LOGFNAME}.4${ext}
343 # Wait a bit so we can see if the noaction test rotates files
346 begin "noaction ${name_postfix}"
347 osum=`md5 ${dir}${LOGFNAME} | tr -d '\n'`
348 run_newsyslog ${newsyslog_args} -n >/dev/null
350 ckstr "$osum" "`md5 ${dir}${LOGFNAME} | tr -d '\n'`"
356 tests_time_rotate() {
360 if [ -n "$dir" ]; then
361 newsyslog_args="-t DEFAULT -a ${dir}"
362 name_postfix="${ext} archive dir"
364 newsyslog_args="-t DEFAULT"
365 name_postfix="${ext}"
370 begin "create file ${name_postfix}" -newdir
371 run_newsyslog -C ${newsyslog_args}
375 begin "rotate time 1 ${name_postfix}"
376 run_newsyslog ${newsyslog_args}
378 chkfcnt 1 ${dir}${LOGFNAME}.*${ext}
383 begin "rotate time 2 ${name_postfix}"
384 run_newsyslog ${newsyslog_args}
386 chkfcnt 2 ${dir}${LOGFNAME}.*${ext}
391 begin "rotate time 3 ${name_postfix}"
392 run_newsyslog ${newsyslog_args}
394 chkfcnt 3 ${dir}${LOGFNAME}.*${ext}
399 begin "rotate time 4 ${name_postfix}"
400 run_newsyslog ${newsyslog_args}
402 chkfcnt 3 ${dir}${LOGFNAME}.*${ext}
405 begin "noaction ${name_postfix}"
406 ofiles=`ls -1 ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`
407 run_newsyslog ${newsyslog_args} -n >/dev/null
409 ckstr "$ofiles" "`ls -1 ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`"
419 if [ -n "$dir" ]; then
420 newsyslog_args=" -a ${dir}"
421 name_postfix="${ext} archive dir"
424 name_postfix="${ext}"
429 begin "RFC-5424 - create file ${name_postfix}" -newdir
432 cknt ${dir}${LOGFNAME}.0${ext}
434 cknt ${dir}${LOGFNAME5424}.0${ext}
435 ckrfc3164 ${LOGFNAME}
436 ckrfc5424 ${LOGFNAME5424}
439 begin "RFC-5424 - rotate normal 1 ${name_postfix}"
440 run_newsyslog $newsyslog_args
442 ckfe ${dir}${LOGFNAME}.0${ext}
444 ckfe ${dir}${LOGFNAME5424}.0${ext}
445 ckrfc3164 ${LOGFNAME}
446 ckrfc3164 ${dir}${LOGFNAME}.0${ext}
447 ckrfc5424 ${LOGFNAME5424}
448 ckrfc5424 ${dir}${LOGFNAME5424}.0${ext}
459 LOGFPATH=${TMPDIR}/log/${LOGFNAME}
461 # Log file for RFC-5424 testing
462 LOGFNAME5424=foo5424.log
463 LOGFPATH5424=${TMPDIR}/log/${LOGFNAME5424}
465 # Normal, no archive dir, keep X files
466 echo "$LOGFPATH 640 0 * @T00 NC" > newsyslog.conf
467 tests_normal_rotate_keepn 0
469 echo "$LOGFPATH 640 1 * @T00 NC" > newsyslog.conf
470 tests_normal_rotate_keepn 1
472 echo "$LOGFPATH 640 2 * @T00 NC" > newsyslog.conf
473 tests_normal_rotate_keepn 2
475 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
476 tests_normal_rotate_keepn 3
478 # Normal, no archive dir, keep X files, gz
479 echo "$LOGFPATH 640 0 * @T00 NCZ" > newsyslog.conf
480 tests_normal_rotate_keepn 0 ".gz"
482 echo "$LOGFPATH 640 1 * @T00 NCZ" > newsyslog.conf
483 tests_normal_rotate_keepn 1 ".gz"
485 echo "$LOGFPATH 640 2 * @T00 NCZ" > newsyslog.conf
486 tests_normal_rotate_keepn 2 ".gz"
488 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
489 tests_normal_rotate_keepn 3 ".gz"
491 # Normal, no archive dir
492 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
495 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
496 tests_normal_rotate ".gz"
498 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
499 tests_normal_rotate ".bz2"
501 echo "$LOGFPATH 640 3 * @T00 NCX" > newsyslog.conf
502 tests_normal_rotate ".xz"
504 echo "$LOGFPATH 640 3 * @T00 NCY" > newsyslog.conf
505 tests_normal_rotate ".zst"
507 # Normal, archive dir
508 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
509 tests_normal_rotate "" "${TMPDIR}/alog/"
511 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
512 tests_normal_rotate ".gz" "${TMPDIR}/alog/"
514 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
515 tests_normal_rotate ".bz2" "${TMPDIR}/alog/"
517 echo "$LOGFPATH 640 3 * @T00 NCX" > newsyslog.conf
518 tests_normal_rotate ".xz" "${TMPDIR}/alog/"
520 echo "$LOGFPATH 640 3 * @T00 NCY" > newsyslog.conf
521 tests_normal_rotate ".zst" "${TMPDIR}/alog/"
523 # Time based, no archive dir
524 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
527 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
528 tests_time_rotate "gz" ""
530 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
531 tests_time_rotate "bz2" ""
533 echo "$LOGFPATH 640 3 * @T00 NCX" > newsyslog.conf
534 tests_time_rotate "xz" ""
536 echo "$LOGFPATH 640 3 * @T00 NCY" > newsyslog.conf
537 tests_time_rotate "zst" ""
539 # Time based, archive dir
540 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
541 tests_time_rotate "" "${TMPDIR}/alog/"
543 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
544 tests_time_rotate "gz" "${TMPDIR}/alog/"
546 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
547 tests_time_rotate "bz2" "${TMPDIR}/alog/"
549 echo "$LOGFPATH 640 3 * @T00 NCX" > newsyslog.conf
550 tests_time_rotate "xz" "${TMPDIR}/alog/"
552 echo "$LOGFPATH 640 3 * @T00 NCY" > newsyslog.conf
553 tests_time_rotate "zst" "${TMPDIR}/alog/"
555 # RFC-5424; Normal, no archive dir
556 echo "$LOGFPATH5424 640 3 * @T00 NCT" > newsyslog.conf
557 echo "$LOGFPATH 640 3 * @T00 NC" >> newsyslog.conf