tester revision 7ea027865de56bac0c639f5fe006cc752ce41413
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# CDDL HEADER START
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# The contents of this file are subject to the terms of the
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# Common Development and Distribution License (the "License").
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# You may not use this file except in compliance with the License.
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# See the License for the specific language governing permissions
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# and limitations under the License.
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# When distributing Covered Code, include this CDDL HEADER in each
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# If applicable, add the following below this CDDL HEADER, with the
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# fields enclosed by brackets "[]" replaced with your own identifying
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# information: Portions Copyright [yyyy] [name of copyright owner]
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# CDDL HEADER END
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# Copyright (c) 2013, Joyent, Inc. All rights reserved.
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# tester - run logadm tests
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# requires a <bindir> argument to say where the various logadm
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# binaries live (conftest, globtest, kwtest, luttest, optstest, and
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# logadm itself).
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# to run all the tests:
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# tester [-f] <bindir>
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# to run just a few tests, given their names:
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# tester [-f] <bindir> globtest1 luttest1
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# to setup a test and stop so you can run it by hand:
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# tester [-f] -s globtest1 <bindir>
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# tester will tell you what tmp directory it created for
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# the test. to run it, cd there and run:
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# to check the results, run:
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# sh checktest
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# -f means "fast" -- without it, watchmalloc(3MALLOC) is setup for
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# each test and they run a zillion times slower and produce core
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# dumps when malloc/free problems are detected.
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont$watchmalloc=1; # default is to use watchmalloc
b091b4bb803b830d2d5a9e71b6648b669655d7dcFrancis Dupont# list of tests we run by default
my $msg = shift;
$needrmdir = 1;
$testname = $_;
chdir $mydir;
$rc >>= 8;
my $coremsg;
$rc &= ~0x80;
my $file = shift;
my $contents = shift;
# common setup step -- create a testfile.conf
my $fname = shift;
apache -C 24 -a '/usr/apache/bin/apachectl graceful' -p 1m -t '/var/apache/old-logs/$basename.%Y-%m' '/var/apache/logs/*{access,error}_log'
# conftest1 -- minimal basic test of the conf.c code
exec /bin/diff testfile.conf sed.out
exec $bindir/conftest testfile.conf >std.out 2>std.err
# conftest2 -- error path through conf.c
exec /bin/diff std.err.expect std.err
$bindir/conftest testfile.conf >std.out 2>std.err || exit 0
# globtest1 -- minimal basic test of the glob.c code
<./dir1/dirA/fileAname4>
<./dir1/dirA/fileAname1>
<./dir1/dirA/fileAname2>
<./dir1/dirA/fileAname3>
<./dir1/dirA/fileAname5>
<./dir1/dirA/fileBname1>
<./dir1/dirA/fileBname2>
<./dir1/dirA/fileBname3>
<./dir1/dirA/fileBname4>
<./dir1/dirA/fileBname5>
oldest <./dir1/dirA/fileAname4>
oldest <./dir1/dirA/fileBname5>
oldest <./dir1/dirA/fileBname4>
oldest <./dir1/dirA/fileBname3>
oldest <./dir1/dirA/fileBname2>
oldest <./dir1/dirA/fileBname1>
oldest <./dir1/dirA/fileAname5>
oldest <./dir1/dirA/fileAname3>
oldest <./dir1/dirA/fileAname2>
oldest <./dir1/dirA/fileAname1>
<./dir1/fileAname1>
<./dir1/fileAname2>
<./dir1/fileAname3>
<./dir1/fileAname4>
<./dir1/fileAname5>
<./dir1/fileBname1>
<./dir1/fileBname2>
<./dir1/fileBname3>
<./dir1/fileBname4>
<./dir1/fileBname5>
oldest <./dir1/fileBname5>
oldest <./dir1/fileBname4>
oldest <./dir1/fileBname3>
oldest <./dir1/fileBname2>
oldest <./dir1/fileBname1>
oldest <./dir1/fileAname5>
oldest <./dir1/fileAname4>
oldest <./dir1/fileAname3>
oldest <./dir1/fileAname2>
oldest <./dir1/fileAname1>
<./dir1/dirA/fileBname2>
<./dir1/dirA/fileBname3>
<./dir1/dirA/fileBname4>
<./dir1/dirA/fileBname5>
oldest <./dir1/dirA/fileBname5>
oldest <./dir1/dirA/fileBname4>
oldest <./dir1/dirA/fileBname3>
oldest <./dir1/dirA/fileBname2>
exec /bin/diff std.out.expect std.out
$testglobs='\'file{A,B,C}name*\' \'file{A,B,C}name\' \'dir1/dirA/file*\' \'dir[13]/[e-z]*\' \'dir?/dir[AC]/fileBname[2-9]\' -r \'file[A-Z]n.*e([0-9]+)$0\'';
# globtest2 -- error path through glob.c
exec /bin/diff std.err.expect std.err
# kwtest1 -- minimal basic test of the kw.c code
$domainname = `/bin/domainname`; chomp $domainname;
expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n -1 hasn 1 result </var/logs-[0-9]+/moose-ISAporklips[0-9]+\.([0-9]+)$0>
expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 0 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.0>
expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 1 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.1>
exec /bin/diff sed.out.expect sed.out
$kwtest='kwtest /var/log/syslog \'$file.$n\' \'moose%d.$n\' \'/var/logs-%Y/moose-$isa$#porklips%d.$n\'';
# kwtest2 -- NULL environment variables test of the kw.c code
$domainname = `/bin/domainname`; chomp $domainname;
expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n -1 hasn 1 result </var/logs-[0-9]+/moose-ISAporklips[0-9]+\.([0-9]+)$0>
expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 0 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.0>
expand</var/logs-%Y/moose-$isa$#porklips%d.$n> n 1 hasn 1 result </var/logs-%Y/moose-ISAporklips%d.1>
exec /bin/diff sed.out.expect sed.out
$kwtest='kwtest /var/log/syslog \'$file.$n\' \'moose%d.$n\' \'/var/logs-%Y/moose-$isa$#porklips%d.$n\'';
# luttest1 -- minimal basic test of the lut.c code
exec /bin/diff std.out.expect std.out
# optstest1 -- minimal basic test of the opts.c code
exec /bin/diff std.out.expect std.out
# optstest2 -- error path through opts.c code
[ -s std.out ] && exit 1
exec /bin/diff std.err.expect std.err
apache -C 24 -a '/usr/apache/bin/apachectl graceful' -p 1m -t '/var/apache/old-logs/$basename.%Y-%m' '/var/apache/logs/*{access,error}_log'
exec /bin/diff std.out.expect std.out
exec $bindir/logadm -f testfile.conf -F testfile.conf -V >std.out 2>std.err
exec /bin/diff std.out.expect std.out
exec $bindir/logadm -f testfile.conf -F testfile.conf -V /var/cron/log /var/adm/pacct >std.out 2>std.err
exec /bin/diff diff.out.expect diff.out
exec $bindir/logadm -f testfile.conf -F testfile.conf -r /var/cron/log /var/adm/pacct >std.out 2>std.err
exec /bin/diff diff.out.expect diff.out
exec $bindir/logadm -f testfile.conf -F testfile.conf -w moose -C 20 -a moose_after_cmd -g pig -m 664 -o cow -p never /moose/file >std.out 2>std.err
[ -s std.out ] && exit 1
[ -s std.out ] && exit 1
[ -s std.out ] && exit 1
# logadm3 -- minimal basic test of logadm pre/post-commands
[ -s std.out ] && exit 1
[ -f pre.out ] || exit 1
[ -f post.out ] || exit 1
exec $bindir/logadm -f /dev/null -p now logfile -C2 -b 'echo pre-command-stuff > pre.out' -a 'echo post-command-stuff > post.out' >std.out 2>std.err
[ -s std.out ] && exit 1
[ -s std.out ] && exit 1
exec /bin/diff cmd.out.expect cmd.out
exec $bindir/logadm -f /dev/null -p now logfile -C1 -R 'echo just rotated: `/bin/cat \$file` >>cmd.out' -E 'echo just expired: `/bin/cat \$file` >>cmd.out' >std.out 2>std.err
[ -s std.err ] || exit 1;
[ -s std.out ] && exit 1
exec /bin/diff std.err.expect std.err
exec $bindir/logadm -f /dev/null -p now logfile -m 411 -o _nonexistentuser_ -g _nonexistentgroup_ >std.out 2>std.err
[ -s std.out ] && exit 1
[ -s logadm.timestamps ] || exit 1
[ -s std.err2 ] && exit 1
[ -s std.out2 ] && exit 1
[ -s std.err3 ] && exit 1
[ -s std.out3 ] && exit 1
[ -s std.err4 ] && exit 1
[ -s std.out4 ] && exit 1
[ -f dir2/messages.0 ] || exit 1
[ -f dir2/messages.1 ] || exit 1
[ -f dir2/messages.2 ] || exit 1
[ -f dir2/messages.3 ] || exit 1
[ -f dir2/messages.4 ] && exit 1
/bin/diff sed.out.expect sed.out || exit 1
exec /bin/diff logadm.conf.orig logadm.conf
$bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err || exit 1
$bindir/logadm -f logadm.conf -F logadm.timestamps dir1/syslog dir2/messages >std.out2 2>std.err2 || exit 1
$bindir/logadm -f logadm.conf -F logadm.timestamps >std.out3 2>std.err3 || exit 1
exec $bindir/logadm -f logadm.conf -F logadm.timestamps dir2/messages -p now -a 'echo second kill -HUP `cat /var/run/*syslog*pid` >> cmd.out' >std.out4 2>std.err4
[ -s std.out ] && exit 1
[ -f dir1/syslog.2.gz ] || exit 1
[ -f dir1/syslog.3.gz ] || exit 1
[ -f dir1/syslog.4.gz ] || exit 1
[ -f dir1/syslog.5.gz ] || exit 1
[ -f dir1/syslog.6.gz ] || exit 1
[ -f dir1/syslog.7.gz ] || exit 1
[ -f dir1/syslog.8.gz ] && exit 1
$now = time;
[ -s std.out ] && exit 1
[ -f dir2/messages.0 ] || exit 1
[ -f dir2/messages.1 ] || exit 1
[ -f dir2/messages.2 ] || exit 1
[ -f dir2/messages.3 ] || exit 1
[ -f dir2/messages.4 ] && exit 1
/bin/diff sed.out.expect sed.out || exit 1
[ -s sed.out ] && exit 1
exec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
$now = time;
[ -s std.out ] && exit 1
[ -f dir2/messages.0 ] || exit 1
[ -f dir2/messages.1 ] || exit 1
[ -f dir2/messages.2 ] || exit 1
[ -f dir2/messages.3 ] || exit 1
[ -f dir2/messages.4 ] && exit 1
exec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
[ -s std.out ] && exit 1
[ "xinitially dir1/syslogXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" = "x`/bin/cat dir1/syslog.0`" ] || exit 1
[ -f dir2/messages.0 ] || exit 1
[ -f dir2/messages.1 ] || exit 1
[ -f dir2/messages.2 ] || exit 1
[ -f dir2/messages.3 ] || exit 1
[ -f dir2/messages.4 ] && exit 1
exec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
[ -s std.out ] && exit 1
[ -f dir2/messages.0 ] || exit 1
[ -f dir2/messages.1 ] || exit 1
[ -f dir2/messages.2 ] || exit 1
[ -f dir2/messages.3 ] && exit 1
[ -f dir2/messages.4 ] && exit 1
exec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
[ -s std.out ] && exit 1
exec /bin/diff std.err.expect std.err
[ -s std.out ] && exit 1
$gid = $);
$gid =~ s/ .*//;
# loading logadm.conf
# logadm.conf and logadm.timestamps unchanged
[ -f std.out ] || exit 1
[ -f dir2/messages.0 ] || exit 1
[ -f dir2/messages.1 ] || exit 1
[ -f dir2/messages.2 ] || exit 1
[ -f dir2/messages.3 ] || exit 1
[ -f dir2/messages.4 ] && exit 1
exec /bin/diff grep.out.expect grep.out
exec $bindir/logadm -nv -f logadm.conf -F logadm.timestamps >std.out 2>std.err
[ -s std.out ] && exit 1
[ -f logfile ] || exit 1
[ -f logfile.0 ] || exit 1
[ -f logfile.1 ] || exit 1
[ -f logfile.2 ] || exit 1
[ -f logfile.3 ] && exit 1
[ -f logfile.4 ] || exit 1
[ -f logfile.5 ] && exit 1
[ -f logfile.6 ] || exit 1
[ -f logfile.7 ] && exit 1
[ -f logfile.8 ] || exit 1
[ -f logfile.9 ] && exit 1
[ -f logfile.10 ] && exit 1
-F timestamps use timestamps instead of /var/logadm/timestamps
[ -s std.out ] && exit 1
exec /bin/diff std.err.expect std.err
[ -s std.out ] && exit 1
[ -f logfile ] || exit 1
[ -s std.out ] && exit 1
exec $bindir/logadm -f logadm.conf -F logadm.timestamps >std.out 2>std.err
[ -s std.out ] && exit 1
[ -s logfile ] && exit 1
[ -f logfile.$d ] || exit 1
# logadm20 -- test of unquotables/error handling
[ -s std.err ] || exit 1
[ -s std.out ] && exit 1
[ -f logadm.conf????? ] && exit 1
[ -f logadm.timestamps????? ] && exit 1
exec /bin/diff std.err.expect std.err
$bindir/logadm -f logadm.conf -F logadm.timestamps -w /a/b/c -p 1w -l -b "/bin/echo \\"She can't take anymore, Cap'n!\\"" >std.out 2>std.err
echo exit=\$? >>std.err
[ -s std.err ] || exit 1
$bindir/logadm -f logadm.conf 2>std.err