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