From owner-svn-src-all@FreeBSD.ORG Thu Apr 21 16:40:34 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C12661065670; Thu, 21 Apr 2011 16:40:34 +0000 (UTC) (envelope-from simon@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AE8D88FC0A; Thu, 21 Apr 2011 16:40:34 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p3LGeYfb004181; Thu, 21 Apr 2011 16:40:34 GMT (envelope-from simon@svn.freebsd.org) Received: (from simon@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p3LGeYkc004179; Thu, 21 Apr 2011 16:40:34 GMT (envelope-from simon@svn.freebsd.org) Message-Id: <201104211640.p3LGeYkc004179@svn.freebsd.org> From: "Simon L. Nielsen" Date: Thu, 21 Apr 2011 16:40:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r220927 - head/tools/regression/usr.sbin/newsyslog X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Apr 2011 16:40:34 -0000 Author: simon Date: Thu Apr 21 16:40:34 2011 New Revision: 220927 URL: http://svn.freebsd.org/changeset/base/220927 Log: Expand / correct newsyslog regression tests: - Test newslog with clasic naming of rotates files to actually test the correct number of log files as newsyslog now does the correct thing post r220926. - Add some more newsyslog tests which tests keeping 0, 1, and 2 logfiles. Modified: head/tools/regression/usr.sbin/newsyslog/regress.sh Modified: head/tools/regression/usr.sbin/newsyslog/regress.sh ============================================================================== --- head/tools/regression/usr.sbin/newsyslog/regress.sh Thu Apr 21 16:31:05 2011 (r220926) +++ head/tools/regression/usr.sbin/newsyslog/regress.sh Thu Apr 21 16:40:34 2011 (r220927) @@ -70,6 +70,27 @@ cknt() fi } +# Check if a file is there, depending of if it's suposed to or not - +# basically how many log files we are suposed to keep vs. how many we +# actually keep. +ckntfe() +{ + curcnt=$1 + keepcnt=$2 + f=$3 + + if [ $curcnt -le $keepcnt ] + then + #echo Assuming file there + ckfe $f + else + #echo Assuming file NOT there + cknt $f + fi +} + + + # A part of a test succeeds ok() { @@ -220,6 +241,74 @@ tests_normal_rotate() { tmpdir_clean } +tests_normal_rotate_keepn() { + cnt="$1" + ext="$2" + dir="$3" + + if [ -n "$dir" ]; then + newsyslog_args=" -a ${dir}" + name_postfix="${ext} archive dir" + else + newsyslog_args="" + name_postfix="${ext}" + fi + + tmpdir_create + + begin "create file ${name_postfix}" -newdir + run_newsyslog -C + ckfe $LOGFNAME + cknt ${dir}${LOGFNAME}.0${ext} + end + + begin "rotate normal 1 cnt=$cnt ${name_postfix}" + run_newsyslog $newsyslog_args + ckfe ${LOGFNAME} + ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext} + cknt ${dir}${LOGFNAME}.1${ext} + end + + begin "rotate normal 2 cnt=$cnt ${name_postfix}" + run_newsyslog $newsyslog_args + ckfe ${LOGFNAME} + ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext} + ckntfe 2 $cnt ${dir}${LOGFNAME}.1${ext} + cknt ${dir}${LOGFNAME}.2${ext} + end + + begin "rotate normal 3 cnt=$cnt ${name_postfix}" + run_newsyslog $newsyslog_args + ckfe ${LOGFNAME} + ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext} + ckntfe 2 $cnt ${dir}${LOGFNAME}.1${ext} + ckntfe 3 $cnt ${dir}${LOGFNAME}.2${ext} + cknt ${dir}${LOGFNAME}.3${ext} + end + + begin "rotate normal 3 cnt=$cnt ${name_postfix}" + run_newsyslog $newsyslog_args + ckfe ${LOGFNAME} + ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext} + ckntfe 2 $cnt ${dir}${LOGFNAME}.1${ext} + ckntfe 3 $cnt ${dir}${LOGFNAME}.2${ext} + ckntfe 4 $cnt ${dir}${LOGFNAME}.3${ext} + cknt ${dir}${LOGFNAME}.4${ext} + end + + # Wait a bit so we can see if the noaction test rotates files + sleep 1.1 + + begin "noaction ${name_postfix}" + osum=`md5 ${dir}${LOGFNAME} | tr -d '\n'` + run_newsyslog ${newsyslog_args} -n >/dev/null + ckfe ${LOGFNAME} + ckstr "$osum" "`md5 ${dir}${LOGFNAME} | tr -d '\n'`" + end + + tmpdir_clean +} + tests_time_rotate() { ext="$1" dir="$2" @@ -279,35 +368,57 @@ tests_time_rotate() { tmpdir_clean } -echo 1..78 +echo 1..126 mkdir -p ${TMPDIR} cd ${TMPDIR} LOGFNAME=foo.log LOGFPATH=${TMPDIR}/log/${LOGFNAME} +# Normal, no archive dir, keep X files +echo "$LOGFPATH 640 0 * @T00 NC" > newsyslog.conf +tests_normal_rotate_keepn 0 -# XXX for tests_normal_rotate it should be 3 instead of 2 count - but -# that's currently broken! +echo "$LOGFPATH 640 1 * @T00 NC" > newsyslog.conf +tests_normal_rotate_keepn 1 -# Normal, no archive dir echo "$LOGFPATH 640 2 * @T00 NC" > newsyslog.conf -tests_normal_rotate +tests_normal_rotate_keepn 2 + +echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf +tests_normal_rotate_keepn 3 + +# Normal, no archive dir, keep X files, gz +echo "$LOGFPATH 640 0 * @T00 NCZ" > newsyslog.conf +tests_normal_rotate_keepn 0 ".gz" + +echo "$LOGFPATH 640 1 * @T00 NCZ" > newsyslog.conf +tests_normal_rotate_keepn 1 ".gz" echo "$LOGFPATH 640 2 * @T00 NCZ" > newsyslog.conf +tests_normal_rotate_keepn 2 ".gz" + +echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf +tests_normal_rotate_keepn 3 ".gz" + +# Normal, no archive dir +echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf +tests_normal_rotate + +echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf tests_normal_rotate ".gz" -echo "$LOGFPATH 640 2 * @T00 NCJ" > newsyslog.conf +echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf tests_normal_rotate ".bz2" # Normal, archive dir -echo "$LOGFPATH 640 2 * @T00 NC" > newsyslog.conf +echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf tests_normal_rotate "" "${TMPDIR}/alog/" -echo "$LOGFPATH 640 2 * @T00 NCZ" > newsyslog.conf +echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf tests_normal_rotate ".gz" "${TMPDIR}/alog/" -echo "$LOGFPATH 640 2 * @T00 NCJ" > newsyslog.conf +echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf tests_normal_rotate ".bz2" "${TMPDIR}/alog/" # Time based, no archive dir