6 TMPDIR=`mktemp -d -t regress_newsyslog`
8 echo "$0: Can't create temp dir, exiting..."
12 # Begin an individual test
15 COUNT=`expr $COUNT + 1`
20 # End an individual test
32 # Make a file that can later be verified
39 # Verify that the file specified is correct
42 if [ -f $2 ] && echo "$1-$1" | diff - $2 >/dev/null
50 # Check that a file exists
61 # Verify that the specified file does not exist
73 # Check if a file is there, depending of if it's supposed to or not -
74 # basically how many log files we are supposed to keep vs. how many we
82 if [ $curcnt -le $keepcnt ]
84 #echo Assuming file there
87 #echo Assuming file NOT there
94 # A part of a test succeeds
100 # A part of a test fails
106 # Verify that the exit code passed is for unsuccessful termination
117 # Verify that the exit code passed is for successful termination
128 # Check that there are X files which match expr
132 if [ $cnt -eq `echo "$@" | wc -w` ]
140 # Check that two strings are alike
153 mkdir -p ${TMPDIR}/log ${TMPDIR}/alog
160 rm -rf "${TMPDIR}/log" "${TMPDIR}/alog" newsyslog.conf
166 newsyslog -f ../newsyslog.conf -F -r "$@"
169 tests_normal_rotate() {
173 if [ -n "$dir" ]; then
174 newsyslog_args=" -a ${dir}"
175 name_postfix="${ext} archive dir"
178 name_postfix="${ext}"
183 begin "create file ${name_postfix}" -newdir
186 cknt ${dir}${LOGFNAME}.0${ext}
189 begin "rotate normal 1 ${name_postfix}"
190 run_newsyslog $newsyslog_args
192 ckfe ${dir}${LOGFNAME}.0${ext}
193 cknt ${dir}${LOGFNAME}.1${ext}
196 begin "rotate normal 2 ${name_postfix}"
197 run_newsyslog $newsyslog_args
199 ckfe ${dir}${LOGFNAME}.0${ext}
200 ckfe ${dir}${LOGFNAME}.1${ext}
201 cknt ${dir}${LOGFNAME}.2${ext}
204 begin "rotate normal 3 ${name_postfix}"
205 run_newsyslog $newsyslog_args
207 ckfe ${dir}${LOGFNAME}.0${ext}
208 ckfe ${dir}${LOGFNAME}.1${ext}
209 ckfe ${dir}${LOGFNAME}.2${ext}
210 cknt ${dir}${LOGFNAME}.3${ext}
213 begin "rotate normal 4 ${name_postfix}"
214 run_newsyslog $newsyslog_args
216 ckfe ${dir}${LOGFNAME}.0${ext}
217 ckfe ${dir}${LOGFNAME}.1${ext}
218 ckfe ${dir}${LOGFNAME}.2${ext}
219 cknt ${dir}${LOGFNAME}.4${ext}
222 begin "rotate normal 5 ${name_postfix}"
223 run_newsyslog $newsyslog_args
225 ckfe ${dir}${LOGFNAME}.0${ext}
226 ckfe ${dir}${LOGFNAME}.1${ext}
227 ckfe ${dir}${LOGFNAME}.2${ext}
228 cknt ${dir}${LOGFNAME}.4${ext}
231 # Wait a bit so we can see if the noaction test rotates files
234 begin "noaction ${name_postfix}"
235 ofiles=`ls -Tl ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`
236 run_newsyslog ${newsyslog_args} -n >/dev/null
238 ckstr "$ofiles" "`ls -lT ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`"
244 tests_normal_rotate_keepn() {
249 if [ -n "$dir" ]; then
250 newsyslog_args=" -a ${dir}"
251 name_postfix="${ext} archive dir"
254 name_postfix="${ext}"
259 begin "create file ${name_postfix}" -newdir
262 cknt ${dir}${LOGFNAME}.0${ext}
265 begin "rotate normal 1 cnt=$cnt ${name_postfix}"
266 run_newsyslog $newsyslog_args
268 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
269 cknt ${dir}${LOGFNAME}.1${ext}
272 begin "rotate normal 2 cnt=$cnt ${name_postfix}"
273 run_newsyslog $newsyslog_args
275 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
276 ckntfe 2 $cnt ${dir}${LOGFNAME}.1${ext}
277 cknt ${dir}${LOGFNAME}.2${ext}
280 begin "rotate normal 3 cnt=$cnt ${name_postfix}"
281 run_newsyslog $newsyslog_args
283 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
284 ckntfe 2 $cnt ${dir}${LOGFNAME}.1${ext}
285 ckntfe 3 $cnt ${dir}${LOGFNAME}.2${ext}
286 cknt ${dir}${LOGFNAME}.3${ext}
289 begin "rotate normal 3 cnt=$cnt ${name_postfix}"
290 run_newsyslog $newsyslog_args
292 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
293 ckntfe 2 $cnt ${dir}${LOGFNAME}.1${ext}
294 ckntfe 3 $cnt ${dir}${LOGFNAME}.2${ext}
295 ckntfe 4 $cnt ${dir}${LOGFNAME}.3${ext}
296 cknt ${dir}${LOGFNAME}.4${ext}
299 # Wait a bit so we can see if the noaction test rotates files
302 begin "noaction ${name_postfix}"
303 osum=`md5 ${dir}${LOGFNAME} | tr -d '\n'`
304 run_newsyslog ${newsyslog_args} -n >/dev/null
306 ckstr "$osum" "`md5 ${dir}${LOGFNAME} | tr -d '\n'`"
312 tests_time_rotate() {
316 if [ -n "$dir" ]; then
317 newsyslog_args="-t DEFAULT -a ${dir}"
318 name_postfix="${ext} archive dir"
320 newsyslog_args="-t DEFAULT"
321 name_postfix="${ext}"
326 begin "create file ${name_postfix}" -newdir
327 run_newsyslog -C ${newsyslog_args}
331 begin "rotate time 1 ${name_postfix}"
332 run_newsyslog ${newsyslog_args}
334 chkfcnt 1 ${dir}${LOGFNAME}.*${ext}
339 begin "rotate time 2 ${name_postfix}"
340 run_newsyslog ${newsyslog_args}
342 chkfcnt 2 ${dir}${LOGFNAME}.*${ext}
347 begin "rotate time 3 ${name_postfix}"
348 run_newsyslog ${newsyslog_args}
350 chkfcnt 3 ${dir}${LOGFNAME}.*${ext}
355 begin "rotate time 4 ${name_postfix}"
356 run_newsyslog ${newsyslog_args}
358 chkfcnt 3 ${dir}${LOGFNAME}.*${ext}
361 begin "noaction ${name_postfix}"
362 ofiles=`ls -1 ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`
363 run_newsyslog ${newsyslog_args} -n >/dev/null
365 ckstr "$ofiles" "`ls -1 ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`"
376 LOGFPATH=${TMPDIR}/log/${LOGFNAME}
378 # Normal, no archive dir, keep X files
379 echo "$LOGFPATH 640 0 * @T00 NC" > newsyslog.conf
380 tests_normal_rotate_keepn 0
382 echo "$LOGFPATH 640 1 * @T00 NC" > newsyslog.conf
383 tests_normal_rotate_keepn 1
385 echo "$LOGFPATH 640 2 * @T00 NC" > newsyslog.conf
386 tests_normal_rotate_keepn 2
388 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
389 tests_normal_rotate_keepn 3
391 # Normal, no archive dir, keep X files, gz
392 echo "$LOGFPATH 640 0 * @T00 NCZ" > newsyslog.conf
393 tests_normal_rotate_keepn 0 ".gz"
395 echo "$LOGFPATH 640 1 * @T00 NCZ" > newsyslog.conf
396 tests_normal_rotate_keepn 1 ".gz"
398 echo "$LOGFPATH 640 2 * @T00 NCZ" > newsyslog.conf
399 tests_normal_rotate_keepn 2 ".gz"
401 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
402 tests_normal_rotate_keepn 3 ".gz"
404 # Normal, no archive dir
405 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
408 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
409 tests_normal_rotate ".gz"
411 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
412 tests_normal_rotate ".bz2"
414 # Normal, archive dir
415 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
416 tests_normal_rotate "" "${TMPDIR}/alog/"
418 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
419 tests_normal_rotate ".gz" "${TMPDIR}/alog/"
421 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
422 tests_normal_rotate ".bz2" "${TMPDIR}/alog/"
424 # Time based, no archive dir
425 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
428 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
429 tests_time_rotate "gz" ""
431 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
432 tests_time_rotate "bz2" ""
434 # Time based, archive dir
435 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
436 tests_time_rotate "" "${TMPDIR}/alog/"
438 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
439 tests_time_rotate "gz" "${TMPDIR}/alog/"
441 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
442 tests_time_rotate "bz2" "${TMPDIR}/alog/"