@@ -416,6 +416,61 @@ tests_time_rotate() {
416
416
tmpdir_clean
417
417
}
418
418
419
+ tests_size_rotate () {
420
+ local dir ext name_postfix newsyslog_args
421
+
422
+ ext=" $1 "
423
+ dir=" $2 "
424
+
425
+ if [ -n " $dir " ]; then
426
+ newsyslog_args=" -a ${dir} "
427
+ name_postfix=" ${ext} archive dir"
428
+ else
429
+ newsyslog_args=" "
430
+ name_postfix=" ${ext} "
431
+ fi
432
+
433
+ tmpdir_create
434
+
435
+ begin " when rotating by size, an empty file should not be rotated ${name_postfix} "
436
+ touch ${LOGFNAME}
437
+ run_newsyslog ${newsyslog_args}
438
+ ckfe ${LOGFNAME}
439
+ cknt ${dir}${LOGFNAME} .0${ext}
440
+ cknt ${dir}${LOGFNAME} .1${ext}
441
+ cknt ${dir}${LOGFNAME} .2${ext}
442
+ end
443
+
444
+ begin " when the size limit is 4 KB, a 3072 B file should not be rotated ${name_postfix} "
445
+ head -c 3072 < /dev/zero > " ${LOGFNAME} "
446
+ run_newsyslog ${newsyslog_args}
447
+ ckfe ${LOGFNAME}
448
+ cknt ${dir}${LOGFNAME} .0${ext}
449
+ cknt ${dir}${LOGFNAME} .1${ext}
450
+ cknt ${dir}${LOGFNAME} .2${ext}
451
+ end
452
+
453
+ begin " when the size limit is 4 KB, a 3073 B file should be rotated ${name_postfix} "
454
+ head -c 3073 < /dev/zero > " ${LOGFNAME} "
455
+ run_newsyslog ${newsyslog_args}
456
+ ckfe ${LOGFNAME}
457
+ ckfe ${dir}${LOGFNAME} .0${ext}
458
+ cknt ${dir}${LOGFNAME} .1${ext}
459
+ cknt ${dir}${LOGFNAME} .2${ext}
460
+ end
461
+
462
+ begin " when the size limit is 4 KB, a 4097 B file should be rotated ${name_postfix} "
463
+ head -c 4097 < /dev/zero > " ${LOGFNAME} "
464
+ run_newsyslog ${newsyslog_args}
465
+ ckfe ${LOGFNAME}
466
+ ckfe ${dir}${LOGFNAME} .0${ext}
467
+ ckfe ${dir}${LOGFNAME} .1${ext}
468
+ cknt ${dir}${LOGFNAME} .2${ext}
469
+ end
470
+
471
+ tmpdir_clean
472
+ }
473
+
419
474
tests_rfc5424 () {
420
475
local dir ext name_postfix newsyslog_args
421
476
@@ -521,9 +576,11 @@ tests_normal_rotate_recompress() {
521
576
ckfe ${LOGFNAME} .0${ext}
522
577
ckfe ${LOGFNAME} .1${ext}
523
578
end
579
+
580
+ tmpdir_clean
524
581
}
525
582
526
- echo 1..185
583
+ echo 1..225
527
584
mkdir -p ${TMPDIR}
528
585
cd ${TMPDIR}
529
586
@@ -635,4 +692,36 @@ tests_p_flag_rotate ".gz"
635
692
echo " $LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
636
693
tests_normal_rotate_recompress
637
694
695
+ # Size based, no archive dir
696
+ echo " $LOGFPATH 640 3 4 * BNC" > newsyslog.conf
697
+ tests_size_rotate
698
+
699
+ echo " $LOGFPATH 640 3 4 * BNCZ" > newsyslog.conf
700
+ tests_size_rotate " .gz" " "
701
+
702
+ echo " $LOGFPATH 640 3 4 * BNCJ" > newsyslog.conf
703
+ tests_size_rotate " .bz2" " "
704
+
705
+ echo " $LOGFPATH 640 3 4 * BNCX" > newsyslog.conf
706
+ tests_size_rotate " .xz" " "
707
+
708
+ echo " $LOGFPATH 640 3 4 * BNCY" > newsyslog.conf
709
+ tests_size_rotate " .zst" " "
710
+
711
+ # Size based, archive dir
712
+ echo " $LOGFPATH 640 3 4 * BNC" > newsyslog.conf
713
+ tests_size_rotate " " " ${TMPDIR} /alog/"
714
+
715
+ echo " $LOGFPATH 640 3 4 * BNCZ" > newsyslog.conf
716
+ tests_size_rotate " .gz" " ${TMPDIR} /alog/"
717
+
718
+ echo " $LOGFPATH 640 3 4 * BNCJ" > newsyslog.conf
719
+ tests_size_rotate " .bz2" " ${TMPDIR} /alog/"
720
+
721
+ echo " $LOGFPATH 640 3 4 * BNCX" > newsyslog.conf
722
+ tests_size_rotate " .xz" " ${TMPDIR} /alog/"
723
+
724
+ echo " $LOGFPATH 640 3 4 * BNCY" > newsyslog.conf
725
+ tests_size_rotate " .zst" " ${TMPDIR} /alog/"
726
+
638
727
rm -rf " ${TMPDIR} "
0 commit comments