Changeset 254

Show
Ignore:
Timestamp:
02/18/08 19:00:21 (9 months ago)
Author:
mbr
Message:

added basic --test mode, added test stats display

Files:

Legend:

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

    r252 r254  
    4040my $logfile    = 'test.log'; 
    4141my $tarfile    = 'gpgdir_test.tar.gz'; 
     42 
     43my $gpg_dir = "$conf_dir/test-gpg"; 
     44my $pw_file = "$conf_dir/test.pw"; 
     45my $key_id  = '375D7DB9'; 
    4246 
    4347my $cmd_stdout = "$output_dir/cmd.stdout"; 
     
    5256my $successful_tests = 0; 
    5357 
    54 exit 1 unless GetOptions( 
     58die "[*] Use --help" unless GetOptions( 
    5559    'Prepare-results' => \$prepare_results, 
    5660    'help'            => \$help 
     
    5963exit &prepare_results() if $prepare_results; 
    6064 
     65&logr("\n[+] ==> Running gpgdir test suite <==\n\n"); 
     66 
    6167### execute the tests 
    6268&test_driver('(Setup) gpgdir program compilation', \&perl_compilation); 
    6369&test_driver('(Setup) Command line argument processing', \&getopt_test); 
     70&test_driver('(Test mode) gpgdir basic test mode', \&test_mode); 
     71 
     72&logr("\n"); 
     73if ($successful_tests) { 
     74    &logr("[+] ==> Passed $successful_tests/$test_num tests " . 
     75        "against gpgdir. <==\n"); 
     76} 
     77if ($failed_tests) { 
     78    &logr("[+] ==> Failed $failed_tests/$test_num tests " . 
     79        "against gpgdir. <==\n"); 
     80} 
     81&logr("[+] This console output has been stored in: $logfile\n\n"); 
    6482 
    6583exit 0; 
     
    7795    $test_num++; 
    7896    return; 
     97} 
     98 
     99sub test_mode() { 
     100    if (&run_cmd("$gpgdirCmd --test --gnupg-dir $gpg_dir " . 
     101            " --pw-file $pw_file --Key-id $key_id")) { 
     102        my $found = 0; 
     103        open F, "< ${cmd_stdout}.$test_num" 
     104            or die "[*] Could not open ${cmd_stderr}.$test_num: $!"; 
     105        while (<F>) { 
     106            if (/Decrypted\s+content\s+matches\s+original/i) { 
     107                $found = 1; 
     108                last; 
     109            } 
     110        } 
     111        close F; 
     112        return 1 if $found; 
     113    } 
     114    return &print_errors("fail ($test_num)\n[*] " . 
     115        "Encrypt/decrypt basic --test mode"); 
    79116} 
    80117 
     
    106143} 
    107144 
     145sub print_errors() { 
     146    my $msg = shift; 
     147    &logr("$msg\n"); 
     148    if (-e "${cmd_stderr}.$test_num") { 
     149        &logr("    STDOUT available in: " . 
     150            "${cmd_stdout}.$test_num file.\n"); 
     151    } 
     152    if (-e "${cmd_stderr}.$test_num") { 
     153        &logr("    STDERR available in: " . 
     154            "${cmd_stderr}.$test_num file.\n"); 
     155    } 
     156    return 0; 
     157} 
     158 
    108159sub run_cmd() { 
    109160    my $cmd = shift; 
     
    119170    my $rv = 0; 
    120171    die "[*] $output_dir does not exist" unless -d $output_dir; 
    121     die "[*] $logfile does not exist, has fwknop_test.pl been executed?" 
     172    die "[*] $logfile does not exist, has gpgdir_test.pl been executed?" 
    122173        unless -e $logfile; 
    123174    if (-e $tarfile) {