logcheck.pl 1.65 KB
#!/usr/bin/perl
#
# script to parse output log and determine presence
# and/or absence of output to TRACE address.
#
# when all specified conditions are met, exits normally.
# Otherwise, exits with return value of 1.
#
# usage:
#
#  logcheck.pl [-p <output[,<times>]] [-n <output>] <logfile> <trace_reg>
#
# where:
#
#  -p <output[,<times>[+]]>
#     Will insure the TRACE output value <output> has occurred.
#     Optionally, will verify <output> occurs exactly <times> times.
#     If the + is present (i.e., -p 2+), will verify instead that
#     <output> occurs at least <times> times.
#
#  -n <output>
#     Insure the TRACE output value <output> does NOT occur.
#
#  <logfile>
#     Name of log file to parse.
#
#  <trace_reg>
#     Address used for TRACE output
#

use Getopt::Std;
getopts("p:n:");
if ($opt_p != 0){
    ($present_string, $present_times) = split(/,/, $opt_p);
}

$plus = 0;
$temp = $present_times;
if (chop($temp) eq "+") {
    $plus = 1;
    $present_times = $temp;
}

$present_count = 0;
open(logfile, "@ARGV[0]") || die "Cannot open log file @ARGV[0].\n";
while ($line = <logfile>) {
    if (($line =~ /@ARGV[1]/) && ($line =~ /cbus/)) {
	$checkline = 1;
    }
    elsif ($checkline == 1){
	if ($present_string ne "" &&  $line =~ /$present_string/) {
            $present_count += 1;
	}
        elsif ($opt_n ne "" && $line =~ /$opt_n/) {
	    exit(1);
        }
	$checkline = 0;
    }
}
close(logfile);

if ($present_times ne "") {
    if ($plus == 0) {
	if ($present_count != $present_times){
	    exit(1);
	}
    }
    else {
	if ($present_count < $present_times){
	    exit(1);
	}
    }
}
elsif ($opt_p != 0 && $present_count < 1){
    exit(1);
}

exit(0);