Changeset 2588 in /cluster/svnroot


Ignore:
Timestamp:
Aug 26, 2010 4:04:03 PM (10 years ago)
Author:
leemasa
Message:

Made bccd_test_suite a little easier to read

Location:
bccd-ng/branches/leemasa-devel/trees/home/bccd/tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • bccd-ng/branches/leemasa-devel/trees/home/bccd/tests/bccd_test_suite.pl

    r2580 r2588  
    1 #Automagic BCCD test suite!
     1#!/usr/bin/perl
     2#**********************************************************#
     3#BCCD test suite
     4#Written by Samuel Leeman-Munk
    25#Runs test scripts and compares with control output in BCCD.
    36#Emails differences to bccd-developers@bccd.net
     7#**********************************************************#
    48
    59use strict;
    6 use File::Path;
    7 use Getopt::Long;
    8 use MIME::Lite;
     10use File::Path;         #for rmtree
     11use Getopt::Long;       #for argument parsing
     12use MIME::Lite;         #for mailing results
    913
    1014use bccd_test_suite;
    1115
    1216#Constants
    13 my $TRUE = 1;
    14 my $FALSE = 0;
    15 my $DEFAULSE = -1;
    16 my $SEPARATOR_STRING = "|";
     17use constant TRUE => 1;
     18use constant FALSE => 0;
     19my $DEFAULSE = -1; #The default false value. Overridden by any user input
     20my $SEPARATOR_STRING = "|"; #the string by which to separate one type of tests from another
    1721my $DEFAULT_TEST_DIR = "test";
     22my $DEFAULT_DIFF_DIR = "tmp";
    1823my $DEFAULT_CONTROL_DIR = "control";
    19 my $DEFAULT_MAILTO = '<sleemanmunk@gmail.com>';
     24my $DEFAULT_MAILTO = '<sleemanmunk@gmail.com>'; #the recipient of the summary email
    2025
    2126#Global Arguments and Defaults
    22 my $diffdir = "tmp";
     27my $diffdir = $DEFAULT_DIFF_DIR;        #the directory in which to keep the
     28                                        #files of differences between test and control
    2329my $testdir = $DEFAULT_TEST_DIR;
    2430my $controldir = $DEFAULT_CONTROL_DIR;
    2531my $listfile = "test_lists/std";
    26 my $buildcontrol = $FALSE;
     32my $buildcontrol = FALSE;
    2733my $verbose = $DEFAULSE;
    28 my $mail = $TRUE;
     34my $mail = TRUE;
    2935my $mailto = $DEFAULT_MAILTO;
     36my $messy = FALSE;
    3037
    3138GetOptions(
     
    3340        'controldir|cdir|cd=s' => \$controldir,
    3441        'testdir|d=s' => \$testdir,
     42        'diffdir=s' => \$diffdir,
    3543        'file|f=s' => \$listfile,
    3644        'mail!' => \$mail,
    3745        'verbose!' => \$verbose,
    3846        'mailto|t=s' => \$mailto,
     47        'messy' => \$messy,
    3948        );
    4049
    4150#By default, verbose turns on when mail is turned off
    42 #unless --noverbose is specified
     51#unless --noverbose is specified, in which a successful
     52#run of the suite returns no output
    4353if ((not $mail) and ($verbose == $DEFAULSE)){
    44         $verbose = $TRUE;
     54        $verbose = TRUE;
    4555}
    4656if ($verbose == $DEFAULSE){
    47         $verbose = $FALSE;
     57        $verbose = FALSE;
    4858}
    4959
     
    5161my @testlist;
    5262if (-r $listfile){
    53     @testlist = bccd_test_suite::read_list($listfile); 
     63    @testlist = bccd_test_suite::read_list($SEPARATOR_STRING,$listfile);       
    5464} else {
    55     die "Could not read the list file.";
     65    die "Could not read the list file: $!";
    5666}
    5767
     
    6070    print "Using control directory: $controldir\n";
    6171    $testdir = $controldir;
     72} elsif (not -e $controldir){
     73        die "control directory \"$controldir\" does not exist. Please specify an existing control directory or, if you are using this system as the control system, use option -c to create one";
    6274}
    6375
     
    7991if ( not $buildcontrol ){ #Test comparison is unnecessary when building control
    8092    if (-e $diffdir){
    81                 rmtree $diffdir or die "Could not delete existing temporary directory: $!";
     93                rmtree $diffdir or die "Could not delete existing temporary directory $diffdir: $!";
    8294    }
    8395
     
    96108                                or die "Error creating $testdir/$test.dat or $controldir/$test.dat: $!";
    97109                        }
    98                         system ("diff $testdir/$test.dat $controldir/$test.dat > $diffdir/$test.diff"); #examine differences, output to file.
     110                        system ("diff $testdir/$test.dat $controldir/$test.dat > $diffdir/$test.diff");
     111                        #examine differences, output to file.
    99112                                my @diff_lines_raw #count lines in differences files.
    100113                                = split(/ /,`wc -l $diffdir/$test.diff`);
     
    119132    my $date = bccd_test_suite::get_timestamp();
    120133    if ($verbose){
    121             if ($report){
     134            if ($report){#if there were any mismatches
    122135                    print "$date:\n$report\n\n$details\n";
    123136            }else{
     
    175188                }
    176189
    177 ### use Net:SMTP to do the sending
     190# use Net:SMTP to do the sending
    178191                $msg->send('smtp');
    179         unlink 'test_results.tgz';
     192
     193# Clean up if not told to be messy
     194                if (not $messy){
     195                        unlink 'test_results.tgz';
     196                        rmtree $testdir;
     197                        rmtree $diffdir;
     198                }       
    180199        }
    181200}
  • bccd-ng/branches/leemasa-devel/trees/home/bccd/tests/bccd_test_suite.pm

    r2580 r2588  
    66#Trim function to remove whitespace
    77sub trim{
    8         my $string = shift;
     8        my ($string) = @_;
    99        $string =~ s/^\s+//;
    1010        $string =~ s/\s+$//;
     
    1414#Output to stdout and to data file
    1515sub output{
    16         (my $OUTPUT, my $string) = @_;
     16        my ($OUTPUT, $string) = @_;
    1717        print $string;
    1818        print $OUTPUT $string;
    1919}
    2020
    21 #Create the shell command to store output from a given test
     21#Create the shell redirection command to store output from a given test
    2222sub generate_storeOutput{
    23         (my $testdir, my $testname) = @_;
     23        my ($testdir, $testname) = @_;
    2424        my $path = `pwd`;
    2525        chop $path;
     
    2929#Collect meaningful information from the syncdir command
    3030sub get_syncdir{
    31         (my $tmpoutput) = @_;
     31        my ($tmpoutput) = @_;
    3232        open(FILE, "<$tmpoutput") or die "could not open temporary file: $!";
    3333        my $tmp = "";
     
    3939        my $syncdir = substr($tmp,$startindex,$endindex-1);
    4040        close FILE;
    41         unlink("tmpdir") or die "Could not delete temporary directory: $!";
    4241        return $syncdir;
    4342}
     
    4544#Get test list from a file
    4645sub read_list{
    47         (my $path)      =       @_;
     46        my($separator_string,$path)     =       @_;
    4847        my @testlist = ();
    4948        my @infolist = ();
     
    5251        while (!eof(FILE)){
    5352                $tmp = readline FILE;
     53               
     54                #cut out comments
    5455                my $commentbegin = index($tmp, '#');
    5556                        if ($commentbegin != -1){
    5657                                $tmp = substr($tmp,0,$commentbegin);
    5758                        }
     59                #remove trailing and leading whitespace
    5860                        $tmp = trim $tmp;
     61                #entries beginning with '*' are relegated to the info list
     62                #that is not compared with the control
    5963                        if (substr($tmp,length($tmp)-1) eq "*"){
    6064                                chop $tmp;
     
    6569                        }
    6670        }
    67         return @testlist,"|",@infolist;
     71        return @testlist,$separator_string,@infolist;
    6872}
    6973
Note: See TracChangeset for help on using the changeset viewer.