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 message="$message $COUNT - $NAME"
35 message="$message # TODO $TODO"
41 # Make a file that can later be verified
48 # Verify that the file specified is correct
51 if [ -f $2 ] && echo "$1-$1" | diff - $2 >/dev/null
59 # Check that a file exists
70 # Verify that the specified file does not exist
82 # Check if a file is there, depending of if it's supposed to or not -
83 # basically how many log files we are supposed to keep vs. how many we
91 if [ $curcnt -le $keepcnt ]
93 #echo Assuming file there
96 #echo Assuming file NOT there
103 # A part of a test succeeds
109 # A part of a test fails
115 # Verify that the exit code passed is for unsuccessful termination
126 # Verify that the exit code passed is for successful termination
137 # Check that there are X files which match expr
141 if [ $cnt -eq `echo "$@" | wc -w` ]
149 # Check that two strings are alike
162 mkdir -p ${TMPDIR}/log ${TMPDIR}/alog
169 rm -rf "${TMPDIR}/log" "${TMPDIR}/alog" newsyslog.conf
175 newsyslog -f ../newsyslog.conf -F -r "$@"
178 tests_normal_rotate() {
182 if [ -n "$dir" ]; then
183 newsyslog_args=" -a ${dir}"
184 name_postfix="${ext} archive dir"
187 name_postfix="${ext}"
192 begin "create file ${name_postfix}" -newdir
195 cknt ${dir}${LOGFNAME}.0${ext}
198 begin "rotate normal 1 ${name_postfix}"
199 run_newsyslog $newsyslog_args
201 ckfe ${dir}${LOGFNAME}.0${ext}
202 cknt ${dir}${LOGFNAME}.1${ext}
205 begin "rotate normal 2 ${name_postfix}"
206 run_newsyslog $newsyslog_args
208 ckfe ${dir}${LOGFNAME}.0${ext}
209 ckfe ${dir}${LOGFNAME}.1${ext}
210 cknt ${dir}${LOGFNAME}.2${ext}
213 begin "rotate normal 3 ${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}.3${ext}
222 begin "rotate normal 4 ${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 begin "rotate normal 5 ${name_postfix}"
232 run_newsyslog $newsyslog_args
234 ckfe ${dir}${LOGFNAME}.0${ext}
235 ckfe ${dir}${LOGFNAME}.1${ext}
236 ckfe ${dir}${LOGFNAME}.2${ext}
237 cknt ${dir}${LOGFNAME}.4${ext}
240 # Wait a bit so we can see if the noaction test rotates files
243 begin "noaction ${name_postfix}"
244 ofiles=`ls -Tl ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`
245 run_newsyslog ${newsyslog_args} -n >/dev/null
247 ckstr "$ofiles" "`ls -lT ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`"
253 tests_normal_rotate_keepn() {
258 if [ -n "$dir" ]; then
259 newsyslog_args=" -a ${dir}"
260 name_postfix="${ext} archive dir"
263 name_postfix="${ext}"
268 begin "create file ${name_postfix}" -newdir
271 cknt ${dir}${LOGFNAME}.0${ext}
274 begin "rotate normal 1 cnt=$cnt ${name_postfix}"
275 run_newsyslog $newsyslog_args
277 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
278 cknt ${dir}${LOGFNAME}.1${ext}
281 begin "rotate normal 2 cnt=$cnt ${name_postfix}"
282 run_newsyslog $newsyslog_args
284 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
285 ckntfe 2 $cnt ${dir}${LOGFNAME}.1${ext}
286 cknt ${dir}${LOGFNAME}.2${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 cknt ${dir}${LOGFNAME}.3${ext}
298 begin "rotate normal 3 cnt=$cnt ${name_postfix}"
299 run_newsyslog $newsyslog_args
301 ckntfe 1 $cnt ${dir}${LOGFNAME}.0${ext}
302 ckntfe 2 $cnt ${dir}${LOGFNAME}.1${ext}
303 ckntfe 3 $cnt ${dir}${LOGFNAME}.2${ext}
304 ckntfe 4 $cnt ${dir}${LOGFNAME}.3${ext}
305 cknt ${dir}${LOGFNAME}.4${ext}
308 # Wait a bit so we can see if the noaction test rotates files
311 begin "noaction ${name_postfix}"
312 osum=`md5 ${dir}${LOGFNAME} | tr -d '\n'`
313 run_newsyslog ${newsyslog_args} -n >/dev/null
315 ckstr "$osum" "`md5 ${dir}${LOGFNAME} | tr -d '\n'`"
321 tests_time_rotate() {
325 if [ -n "$dir" ]; then
326 newsyslog_args="-t DEFAULT -a ${dir}"
327 name_postfix="${ext} archive dir"
329 newsyslog_args="-t DEFAULT"
330 name_postfix="${ext}"
335 begin "create file ${name_postfix}" -newdir
336 run_newsyslog -C ${newsyslog_args}
340 begin "rotate time 1 ${name_postfix}"
341 run_newsyslog ${newsyslog_args}
343 chkfcnt 1 ${dir}${LOGFNAME}.*${ext}
349 TODO="rotate time 2-4 fail today; bug 212160"
351 begin "rotate time 2 ${name_postfix}"
352 run_newsyslog ${newsyslog_args}
354 chkfcnt 2 ${dir}${LOGFNAME}.*${ext}
359 begin "rotate time 3 ${name_postfix}"
360 run_newsyslog ${newsyslog_args}
362 chkfcnt 3 ${dir}${LOGFNAME}.*${ext}
367 begin "rotate time 4 ${name_postfix}"
368 run_newsyslog ${newsyslog_args}
370 chkfcnt 3 ${dir}${LOGFNAME}.*${ext}
374 begin "noaction ${name_postfix}"
375 ofiles=`ls -1 ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`
376 run_newsyslog ${newsyslog_args} -n >/dev/null
378 ckstr "$ofiles" "`ls -1 ${dir}${LOGFNAME}.*${ext} | tr -d '\n'`"
389 LOGFPATH=${TMPDIR}/log/${LOGFNAME}
391 # Normal, no archive dir, keep X files
392 echo "$LOGFPATH 640 0 * @T00 NC" > newsyslog.conf
393 tests_normal_rotate_keepn 0
395 echo "$LOGFPATH 640 1 * @T00 NC" > newsyslog.conf
396 tests_normal_rotate_keepn 1
398 echo "$LOGFPATH 640 2 * @T00 NC" > newsyslog.conf
399 tests_normal_rotate_keepn 2
401 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
402 tests_normal_rotate_keepn 3
404 # Normal, no archive dir, keep X files, gz
405 echo "$LOGFPATH 640 0 * @T00 NCZ" > newsyslog.conf
406 tests_normal_rotate_keepn 0 ".gz"
408 echo "$LOGFPATH 640 1 * @T00 NCZ" > newsyslog.conf
409 tests_normal_rotate_keepn 1 ".gz"
411 echo "$LOGFPATH 640 2 * @T00 NCZ" > newsyslog.conf
412 tests_normal_rotate_keepn 2 ".gz"
414 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
415 tests_normal_rotate_keepn 3 ".gz"
417 # Normal, no archive dir
418 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
421 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
422 tests_normal_rotate ".gz"
424 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
425 tests_normal_rotate ".bz2"
427 # Normal, archive dir
428 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
429 tests_normal_rotate "" "${TMPDIR}/alog/"
431 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
432 tests_normal_rotate ".gz" "${TMPDIR}/alog/"
434 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
435 tests_normal_rotate ".bz2" "${TMPDIR}/alog/"
437 # Time based, no archive dir
438 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
441 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
442 tests_time_rotate "gz" ""
444 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
445 tests_time_rotate "bz2" ""
447 # Time based, archive dir
448 echo "$LOGFPATH 640 3 * @T00 NC" > newsyslog.conf
449 tests_time_rotate "" "${TMPDIR}/alog/"
451 echo "$LOGFPATH 640 3 * @T00 NCZ" > newsyslog.conf
452 tests_time_rotate "gz" "${TMPDIR}/alog/"
454 echo "$LOGFPATH 640 3 * @T00 NCJ" > newsyslog.conf
455 tests_time_rotate "bz2" "${TMPDIR}/alog/"