1#!/usr/bin/perl -w 2use File::Temp qw/ tempfile tempdir /; 3use File::Basename; 4use File::stat; 5use File::Copy; 6 7my $binDir = dirname($0); 8my $timestampclean= "perl $binDir/timestampsClean.pl"; 9#sub gen_diff($) 10 11sub testLog 12{ 13 # 2 No Log to compare against 14 # 1 Log passed 15 # 0 Log failed 16 my $result = 0; 17 my $testfile = shift; 18 my $dirtocheck = shift; 19 my $filename = basename($testfile); 20 $filename = "$logdir/$filename"; 21 print "processing $testfile $filename\n"; 22 if ( -f $filename ) { 23 my $tmpFile; 24 $dir = tempdir( CLEANUP => 1 ); 25 ($fh, $tmpFile) = tempfile( DIR => $dir ); 26 close($fh); 27 # 28 my $status = system("diff -U 0 -p $testfile $filename | $timestampclean > $tmpFile"); 29 my $info = stat($tmpFile) or die "no $tmpFile: $!"; 30 if ( ($status >>=8) == 0 && ( $info->size == 0) ) { 31 #print "diff worked size is 0\n"; 32 $result = 1; 33 } 34 elsif ( ($status >>=8) == 0 && ( $info->size > 0) ) 35 { 36 #print "diff worked size > 0\n"; 37 $result = 0; 38 } 39 else 40 { 41 #print "diff failed size > 0\n"; 42 $result = 0; 43 } 44 } 45 else 46 { 47 #print "not file > 0\n"; 48 $result = 2; 49 } 50 #print "diff result = $result\n"; 51 return $result; 52} 53 54if ( ! ( $logdir = shift @ARGV ) ) { 55 print STDERR "No logdir specified!\n"; 56 usage(); 57 exit 1; 58} 59 60if ( ! ( $testlogdir = shift @ARGV ) ) { 61 print STDERR "No testdocuments dir to compare against specified!\n"; 62 usage(); 63 exit 1; 64} 65 66if ( !(-d $logdir ) ) { 67 print STDERR "No output directory $logdir exists, please create it!!!!\n"; 68 exit 1; 69} 70if ( !(-d $testlogdir ) ) { 71 print STDERR "the directory containing the logfiles to compare against \"$logdir\" does not exist\n"; 72 usage(); 73 exit 1; 74} 75print "logdir $logdir\n"; 76print "testlogdir $testlogdir\n"; 77sub filter_crud($) 78{ 79 my $a = shift; 80 81 $a =~ /~$/ && return; 82 $a =~ /\#$/ && return; 83 $a =~ /\.orig$/ && return; 84 $a =~ /unxlng.*\.pro$/ && return; 85 $a =~ /wntmsc.*\.pro$/ && return; 86 $a =~ /.swp$/ && return; 87 $a =~ /POSITION/ && return; 88 $a =~ /ReadMe/ && return; 89 $a =~ /.tmp$/ && return; 90 $a =~ /\.svn/ && return; 91 $a eq 'CVS' && return; 92 $a eq '.' && return; 93 $a eq '..' && return; 94 95 return $a; 96} 97sub slurp_dir($); 98 99sub slurp_dir($) 100{ 101 my $dir = shift; 102 my ($dirhandle, $fname); 103 my @files = (); 104 105 opendir ($dirhandle, $dir) || die "Can't open $dir"; 106 while ($fname = readdir ($dirhandle)) { 107 $fname = filter_crud($fname); 108 defined $fname || next; 109# if (-d "$dir/$fname") { 110# push @files, slurp_dir("$dir/$fname"); 111# } else 112 { 113 push @files, "$dir/$fname"; 114 } 115 } 116 closedir ($dirhandle); 117 118 return @files; 119} 120 121if (-d $testlogdir) { 122 push @files, slurp_dir($testlogdir); 123} 124 125my $processed = 0; 126my $passed = 0; 127my @passedTests=(); 128my @skippedTests=(); 129my @failedTests=(); 130 131my $failureCmd=""; 132for $a (@files) { 133 $processed++; 134 my $testcase = $a; 135 $testcase =~ s/\.log/\.xls/; 136 my $result = testLog( $a, $logdir ); 137 if ( $result == 0 ) { 138 push @failedTests, basename($testcase); 139 if ( $failureCmd eq "" ) { $failureCmd = " diff -up $a $logdir "; } 140 } 141 elsif ( $result == 2 ) { 142 #print "skipped $a\n"; 143 push @skippedTests, $testcase; 144 } 145 else { 146 $passed++; 147 push @passedTests, $testcase; 148 #print "Test document for $a \t \t passed. \n"; 149 } 150} 151my $compared=@passedTests+@failedTests; 152my $skip = @skippedTests; 153print "skipped $skip test-cases(s)\n"; 154print "compared $compared test-case documents\n"; 155print "\t \t $passed tests $@passedTests\n"; 156if ( @failedTests > 0 ) { 157 print "the following test-case documents failed, please examine the logs manually\n"; 158 159 for $a (@failedTests) { 160 print "\t$a\n"; 161 } 162 print "e.g. $failureCmd\n" 163} 164