Changeset 252

Show
Ignore:
Timestamp:
02/18/08 10:40:26 (9 months ago)
Author:
mbr
Message:

added setup() routine, added --Prepare-results argument

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gpgdir/trunk/test/gpgdir_test.pl

    r251 r252  
    3030 
    3131use File::Find; 
     32use Getopt::Long; 
    3233use strict; 
    3334 
     
    4445#==================== end config ================== 
    4546 
     47my $help = 0; 
    4648my $test_num  = 0; 
    4749my $PRINT_LEN = 68; 
    4850my $failed_tests = 0; 
     51my $prepare_results = 0; 
    4952my $successful_tests = 0; 
     53 
     54exit 1 unless GetOptions( 
     55    'Prepare-results' => \$prepare_results, 
     56    'help'            => \$help 
     57); 
     58 
     59exit &prepare_results() if $prepare_results; 
    5060 
    5161### execute the tests 
     
    106116} 
    107117 
     118sub prepare_results() { 
     119    my $rv = 0; 
     120    die "[*] $output_dir does not exist" unless -d $output_dir; 
     121    die "[*] $logfile does not exist, has fwknop_test.pl been executed?" 
     122        unless -e $logfile; 
     123    if (-e $tarfile) { 
     124        unlink $tarfile or die "[*] Could not unlink $tarfile: $!"; 
     125    } 
     126 
     127    ### create tarball 
     128    system "tar cvfz $tarfile $logfile $output_dir"; 
     129    print "[+] Test results file: $tarfile\n"; 
     130    if (-e $tarfile) { 
     131        $rv = 1; 
     132    } 
     133    return $rv; 
     134} 
     135 
     136sub setup() { 
     137 
     138    $|++; ### turn off buffering 
     139 
     140    die "[*] $conf_dir directory does not exist." unless -d $conf_dir; 
     141    unless (-d $output_dir) { 
     142        mkdir $output_dir or die "[*] Could not mkdir $output_dir: $!"; 
     143    } 
     144 
     145    for my $file (glob("$output_dir/cmd*")) { 
     146        unlink $file or die "[*] Could not unlink($file)"; 
     147    } 
     148 
     149    for my $file (glob("$output_dir/*.warn")) { 
     150        unlink $file or die "[*] Could not unlink($file)"; 
     151    } 
     152 
     153    for my $file (glob("$output_dir/*.die")) { 
     154        unlink $file or die "[*] Could not unlink($file)"; 
     155    } 
     156 
     157    die "[*] $gpgdirCmd does not exist" unless -e $gpgdirCmd; 
     158    die "[*] $gpgdirCmd not executable" unless -x $gpgdirCmd; 
     159 
     160    if (-e $logfile) { 
     161        unlink $logfile or die $!; 
     162    } 
     163    return; 
     164} 
     165 
    108166sub pass() { 
    109167    &logr("pass ($test_num)\n");