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 rm -rf ${TMPDIR}/log ${TMPDIR}/alog
198 mkdir ${TMPDIR}/log ${TMPDIR}/alog
205 rm -rf "${TMPDIR}/log" "${TMPDIR}/alog" newsyslog.conf
211 newsyslog -f ../newsyslog.conf -F -r "$@"
214 tests_normal_rotate() {
215 local dir ext name_postfix newsyslog_args
220 if [ -n "$dir" ]; then
221 newsyslog_args=" -a ${dir}"
222 name_postfix="${ext} archive dir"
225 name_postfix="${ext}"
230 begin "create file ${name_postfix}" -newdir
233 cknt ${dir}${LOGFNAME}.0${ext}
236 begin "rotate normal 1 ${name_postfix}"
237 run_newsyslog $newsyslog_args
239 ckfe ${dir}${LOGFNAME}.0${ext}
240 cknt ${dir}${LOGFNAME}.1${ext}
243 begin "rotate normal 2 ${name_postfix}"
244 run_newsyslog $newsyslog_args
246 ckfe ${dir}${LOGFNAME}.0${ext}
247 ckfe ${dir}${LOGFNAME}.1${ext}
248 cknt ${dir}${LOGFNAME}.2${ext}
251 begin "rotate normal 3 ${name_postfix}"
252 run_newsyslog $newsyslog_args
254 ckfe ${dir}${LOGFNAME}.0${ext}
255 ckfe ${dir}${LOGFNAME}.1${ext}
256 ckfe ${dir}${LOGFNAME}.2${ext}
257 cknt ${dir}${LOGFNAME}.3${ext}
260 begin "rotate normal 4 ${name_postfix}"
261 run_newsyslog $newsyslog_args
263 ckfe ${dir}${LOGFNAME}.0${ext}
264 ckfe ${dir}${LOGFNAME}.1${ext}
265 ckfe ${dir}${LOGFNAME}.2${ext}
266 cknt ${dir}${LOGFNAME}.4${ext}
269 begin "rotate normal 5 ${name_postfix}"
270 run_newsyslog $newsyslog_args
272 ckfe ${dir}${LOGFNAME}.0${ext}
273 ckfe ${dir}${LOGFNAME}.1${ext}
274 ckfe ${dir}${LOGFNAME}.2${ext}
275 cknt ${dir}${LOGFNAME}.4${ext}
278 # Wait a bit so we can see if the noaction test rotates files
281 begin "noaction ${name_postfix}"
282 ofiles=`ls -Tl ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`
283 run_newsyslog ${newsyslog_args} -n >/dev/null
285 ckstr "$ofiles" "`ls -lT ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`"
291 tests_normal_rotate_keepn() {
292 local cnt dir ext name_postfix newsyslog_args
298 if [ -n "$dir" ]; then
299 newsyslog_args=" -a ${dir}"
300 name_postfix="${ext} archive dir"
303 name_postfix="${ext}"
308 begin "create file ${name_postfix}" -newdir
311 cknt ${dir}${LOGFNAME}.0${ext}
314 begin "rotate normal 1 cnt=$cnt ${name_postfix}"
315 run_newsyslog $newsyslog_args
317 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
318 cknt ${dir}${LOGFNAME}.1${ext}
321 begin "rotate normal 2 cnt=$cnt ${name_postfix}"
322 run_newsyslog $newsyslog_args
324 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
325 ckntfe 2 $cnt ${dir}${LOGFNAME}.1${ext}
326 cknt ${dir}${LOGFNAME}.2${ext}
329 begin "rotate normal 3 cnt=$cnt ${name_postfix}"
330 run_newsyslog $newsyslog_args
332 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
333 ckntfe 2 $cnt ${dir}${LOGFNAME}.1${ext}
334 ckntfe 3 $cnt ${dir}${LOGFNAME}.2${ext}
335 cknt ${dir}${LOGFNAME}.3${ext}
338 begin "rotate normal 3 cnt=$cnt ${name_postfix}"
339 run_newsyslog $newsyslog_args
341 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
342 ckntfe 2 $cnt ${dir}${LOGFNAME}.1${ext}
343 ckntfe 3 $cnt ${dir}${LOGFNAME}.2${ext}
344 ckntfe 4 $cnt ${dir}${LOGFNAME}.3${ext}
345 cknt ${dir}${LOGFNAME}.4${ext}
348 # Wait a bit so we can see if the noaction test rotates files
351 begin "noaction ${name_postfix}"
352 osum=`md5 ${dir}${LOGFNAME} | tr -d '\n'`
353 run_newsyslog ${newsyslog_args} -n >/dev/null
355 ckstr "$osum" "`md5 ${dir}${LOGFNAME} | tr -d '\n'`"
361 tests_time_rotate() {
362 local dir ext name_postfix newsyslog_args
367 if [ -n "$dir" ]; then
368 newsyslog_args="-t DEFAULT -a ${dir}"
369 name_postfix="${ext} archive dir"
371 newsyslog_args="-t DEFAULT"
372 name_postfix="${ext}"
377 begin "create file ${name_postfix}" -newdir
378 run_newsyslog -C ${newsyslog_args}
382 begin "rotate time 1 ${name_postfix}"
383 run_newsyslog ${newsyslog_args}
385 chkfcnt 1 ${dir}${LOGFNAME}.*${ext}
390 begin "rotate time 2 ${name_postfix}"
391 run_newsyslog ${newsyslog_args}
393 chkfcnt 2 ${dir}${LOGFNAME}.*${ext}
398 begin "rotate time 3 ${name_postfix}"
399 run_newsyslog ${newsyslog_args}
401 chkfcnt 3 ${dir}${LOGFNAME}.*${ext}
406 begin "rotate time 4 ${name_postfix}"
407 run_newsyslog ${newsyslog_args}
409 chkfcnt 3 ${dir}${LOGFNAME}.*${ext}
412 begin "noaction ${name_postfix}"
413 ofiles=`ls -1 ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`
414 run_newsyslog ${newsyslog_args} -n >/dev/null
416 ckstr "$ofiles" "`ls -1 ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`"
423 local dir ext name_postfix newsyslog_args
428 if [ -n "$dir" ]; then
429 newsyslog_args=" -a ${dir}"
430 name_postfix="${ext} archive dir"
433 name_postfix="${ext}"
438 begin "RFC-5424 - create file ${name_postfix}" -newdir
441 cknt ${dir}${LOGFNAME}.0${ext}
443 cknt ${dir}${LOGFNAME5424}.0${ext}
444 ckrfc3164 ${LOGFNAME}
445 ckrfc5424 ${LOGFNAME5424}
448 begin "RFC-5424 - rotate normal 1 ${name_postfix}"
449 run_newsyslog $newsyslog_args
451 ckfe ${dir}${LOGFNAME}.0${ext}
453 ckfe ${dir}${LOGFNAME5424}.0${ext}
454 ckrfc3164 ${LOGFNAME}
455 ckrfc3164 ${dir}${LOGFNAME}.0${ext}
456 ckrfc5424 ${LOGFNAME5424}
457 ckrfc5424 ${dir}${LOGFNAME5424}.0${ext}
463 tests_p_flag_rotate() {
474 cknt ${LOGFNAME}.0${ext}
477 begin "rotate p flag 1 ${ext}"
481 cknt ${LOGFNAME}.0${ext}
485 cknt ${LOGFNAME}.0${ext}
486 ckfe ${LOGFNAME}.1${ext}
490 cknt ${LOGFNAME}.0${ext}
491 ckfe ${LOGFNAME}.1${ext}
492 ckfe ${LOGFNAME}.2${ext}
498 tests_normal_rotate_recompress() {
505 begin "create file recompress"
508 cknt ${LOGFNAME}.0${ext}
511 begin "rotate normal 1"
514 ckfe ${LOGFNAME}.0${ext}
515 cknt ${LOGFNAME}.1${ext}
518 begin "rotate recompress 1"
519 gunzip ${LOGFNAME}.0${ext}
521 cknt ${LOGFNAME}.0${ext}
524 ckfe ${LOGFNAME}.0${ext}
525 ckfe ${LOGFNAME}.1${ext}
534 LOGFPATH=${TMPDIR}/log/${LOGFNAME}
536 # Log file for RFC-5424 testing
537 LOGFNAME5424=foo5424.log
538 LOGFPATH5424=${TMPDIR}/log/${LOGFNAME5424}
540 # Normal, no archive dir, keep X files
541 echo "$LOGFPATH 640 0 * @T00 NC" > newsyslog.conf
542 tests_normal_rotate_keepn 0
544 echo "$LOGFPATH 640 1 * @T00 NC" > newsyslog.conf
545 tests_normal_rotate_keepn 1
547 echo "$LOGFPATH 640 2 * @T00 NC" > newsyslog.conf
548 tests_normal_rotate_keepn 2
550 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
551 tests_normal_rotate_keepn 3
553 # Normal, no archive dir, keep X files, gz
554 echo "$LOGFPATH 640 0 * @T00 NCZ" > newsyslog.conf
555 tests_normal_rotate_keepn 0 ".gz"
557 echo "$LOGFPATH 640 1 * @T00 NCZ" > newsyslog.conf
558 tests_normal_rotate_keepn 1 ".gz"
560 echo "$LOGFPATH 640 2 * @T00 NCZ" > newsyslog.conf
561 tests_normal_rotate_keepn 2 ".gz"
563 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
564 tests_normal_rotate_keepn 3 ".gz"
566 # Normal, no archive dir
567 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
570 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
571 tests_normal_rotate ".gz"
573 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
574 tests_normal_rotate ".bz2"
576 echo "$LOGFPATH 640 3 * @T00 NCX" > newsyslog.conf
577 tests_normal_rotate ".xz"
579 echo "$LOGFPATH 640 3 * @T00 NCY" > newsyslog.conf
580 tests_normal_rotate ".zst"
582 # Normal, archive dir
583 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
584 tests_normal_rotate "" "${TMPDIR}/alog/"
586 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
587 tests_normal_rotate ".gz" "${TMPDIR}/alog/"
589 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
590 tests_normal_rotate ".bz2" "${TMPDIR}/alog/"
592 echo "$LOGFPATH 640 3 * @T00 NCX" > newsyslog.conf
593 tests_normal_rotate ".xz" "${TMPDIR}/alog/"
595 echo "$LOGFPATH 640 3 * @T00 NCY" > newsyslog.conf
596 tests_normal_rotate ".zst" "${TMPDIR}/alog/"
598 # Time based, no archive dir
599 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
602 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
603 tests_time_rotate "gz" ""
605 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
606 tests_time_rotate "bz2" ""
608 echo "$LOGFPATH 640 3 * @T00 NCX" > newsyslog.conf
609 tests_time_rotate "xz" ""
611 echo "$LOGFPATH 640 3 * @T00 NCY" > newsyslog.conf
612 tests_time_rotate "zst" ""
614 # Time based, archive dir
615 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
616 tests_time_rotate "" "${TMPDIR}/alog/"
618 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
619 tests_time_rotate "gz" "${TMPDIR}/alog/"
621 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
622 tests_time_rotate "bz2" "${TMPDIR}/alog/"
624 echo "$LOGFPATH 640 3 * @T00 NCX" > newsyslog.conf
625 tests_time_rotate "xz" "${TMPDIR}/alog/"
627 echo "$LOGFPATH 640 3 * @T00 NCY" > newsyslog.conf
628 tests_time_rotate "zst" "${TMPDIR}/alog/"
630 # RFC-5424; Normal, no archive dir
631 echo "$LOGFPATH5424 640 3 * @T00 NCT" > newsyslog.conf
632 echo "$LOGFPATH 640 3 * @T00 NC" >> newsyslog.conf
635 echo "$LOGFPATH 640 3 * @T00 NCpZ" > newsyslog.conf
636 tests_p_flag_rotate ".gz"
638 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
639 tests_normal_rotate_recompress