ftool_test (version 2.0)

You can also look at:
#! /usr/bin/perl

##############################################################################
#
# SYNTAX: ftool_test tool code caller level stdout stderr [filtered]
#          
#         where tool= the name of the FTOOL which was just run
#               code= the exit code returned by the FTOOL
#               caller= the name of the routine which called the FTOOL
#               level=  the level of the error to be generated on failure
#               stdout= the name of a file containing the standard output
#                       from the FTOOL
#               stderr= the name of a file containing the standard error
#                       output from the FTOOL
#               filtered= stderr with acceptable errors removed
#                          
# DESCRIPTION: This is a generic post-FTOOL error checking and cleanup routine.
#
# VERSION: 2.0
#
# HISTORY: 0.0 -> 1.0 6/13/97
# HISTORY: Changed so that it will exit with status 1 if there was an error.
# HISTORY: Before, it would exit with the exit code of the ftool run, but
# HISTORY: this was changed, since it is more useful to be able to check if
# HISTORY: any error occurred. This was prompted by a change in the linearize
# HISTORY: subroutine to remove unfiltered event files after an ascalin error.
# HISTORY: 
# HISTORY: 1.0 -> 2.0 1999-05-07
# HISTORY: Converted from ksh to perl
#
# CALLS: $UTIL/log_entry
# CALLS: $UTIL/file_to_log
# CALLS: $UTIL/exception
#
##############################################################################

use File::Basename;

#$DEBUG = 1;

($tool, $code, $caller, $level, $stdout, $stderr, $filtered) = @ARGV;

$UTIL = $ENV{"UTIL"};

$scriptname = basename($0);

$was_error = 0;

###################
# Debugging output
###################
if ( "$DEBUG" ) {
    print "$scriptname: tool=$tool\n";
    print "$scriptname: code=$code\n";
    print "$scriptname: caller=$caller\n";
    print "$scriptname: level=$level\n";
    print "$scriptname: stdout=$stdout\n";
    print "$scriptname: stderr=$stderr\n";
    print "$scriptname: filtered=$filtered\n";
}

##########################
# Log the standard output
##########################
if ( -r "$stdout" ) {
    chomp($outlines = `wc -l <$stdout`);
}
else {
    $outlines = 0;
}

if ( $outlines > 0 ) {
    ################################
    # There is some standard output
    ################################
    `$UTIL/log_entry "Standard Output From FTOOL ${tool}:"`;
    `$UTIL/file_to_log $stdout`;
}

######################################################
# Check the number of words in the standard error log
######################################################
$errorlines = 0;
if ( -r "$stderr" ) {
    chomp($errorlines = `wc -w <$stderr`);
}

###########################################################
# Check the number of words in the filtered standard error
###########################################################
$filteredlines = $errorlines;
if ( -r "$filtered" ) {
    chomp($filteredlines = `wc -w <$filtered`);
}

###################
# Debugging output
###################
if ( $DEBUG ) {
    print "$scriptname: errorlines=$errorlines\n";
    print "$scriptname: filteredlines=$filteredlines\n";
}

###############################
# Throw an exception if needed
###############################
if ( $filteredlines > 0 or $code != 0 ) {
    `$UTIL/exception $caller $level "Error from ${tool}. Exit code=${code}"`;
    $was_error = 1;
}

###########################
# Dump stderr if not empty
###########################
if ( $errorlines > 0 ) {
    `$UTIL/log_entry "Standard Error Output From FTOOL ${tool}"`;
    `$UTIL/file_to_log $stderr`;
}

#############################################
# Dump par file to log if there was an error
#############################################
if ( $filteredlines > 0 or $code != 0 ) {
    if ( -r "${tool}.par" ) {
	`$UTIL/log_entry "Par file from FTOOL ${tool}"`;
	`$UTIL/file_to_log ${tool}.par`;
    }
}

#########################################
# Remove logs and par file if they exist
#########################################
if ( -e "${tool}.par" ) {
    unlink "${tool}.par";
}

if ( -e "$stderr" ) {
    unlink $stderr;
}

if ( -e "$stdout" ) {
    unlink $stdout;
}

if ( -e "$filtered" ) {
    unlink $filtered;
}

exit $was_error;