1cdf0e10cSrcweir#!/usr/bin/perl -w 2*bb113e63SAndrew Rist# ************************************************************* 3*bb113e63SAndrew Rist# 4*bb113e63SAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 5*bb113e63SAndrew Rist# or more contributor license agreements. See the NOTICE file 6*bb113e63SAndrew Rist# distributed with this work for additional information 7*bb113e63SAndrew Rist# regarding copyright ownership. The ASF licenses this file 8*bb113e63SAndrew Rist# to you under the Apache License, Version 2.0 (the 9*bb113e63SAndrew Rist# "License"); you may not use this file except in compliance 10*bb113e63SAndrew Rist# with the License. You may obtain a copy of the License at 11*bb113e63SAndrew Rist# 12*bb113e63SAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 13*bb113e63SAndrew Rist# 14*bb113e63SAndrew Rist# Unless required by applicable law or agreed to in writing, 15*bb113e63SAndrew Rist# software distributed under the License is distributed on an 16*bb113e63SAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17*bb113e63SAndrew Rist# KIND, either express or implied. See the License for the 18*bb113e63SAndrew Rist# specific language governing permissions and limitations 19*bb113e63SAndrew Rist# under the License. 20*bb113e63SAndrew Rist# 21*bb113e63SAndrew Rist# ************************************************************* 22cdf0e10cSrcweiruse File::Temp qw/ tempfile tempdir /; 23cdf0e10cSrcweiruse File::Basename; 24cdf0e10cSrcweiruse File::stat; 25cdf0e10cSrcweiruse File::Copy; 26cdf0e10cSrcweir 27cdf0e10cSrcweirmy $binDir = dirname($0); 28cdf0e10cSrcweirmy $timestampclean= "perl $binDir/timestampsClean.pl"; 29cdf0e10cSrcweir#sub gen_diff($) 30cdf0e10cSrcweir 31cdf0e10cSrcweirsub testLog 32cdf0e10cSrcweir{ 33cdf0e10cSrcweir # 2 No Log to compare against 34cdf0e10cSrcweir # 1 Log passed 35cdf0e10cSrcweir # 0 Log failed 36cdf0e10cSrcweir my $result = 0; 37cdf0e10cSrcweir my $testfile = shift; 38cdf0e10cSrcweir my $dirtocheck = shift; 39cdf0e10cSrcweir my $filename = basename($testfile); 40cdf0e10cSrcweir $filename = "$logdir/$filename"; 41cdf0e10cSrcweir print "processing $testfile $filename\n"; 42cdf0e10cSrcweir if ( -f $filename ) { 43cdf0e10cSrcweir my $tmpFile; 44cdf0e10cSrcweir $dir = tempdir( CLEANUP => 1 ); 45cdf0e10cSrcweir ($fh, $tmpFile) = tempfile( DIR => $dir ); 46cdf0e10cSrcweir close($fh); 47cdf0e10cSrcweir # 48cdf0e10cSrcweir my $status = system("diff -U 0 -p $testfile $filename | $timestampclean > $tmpFile"); 49cdf0e10cSrcweir my $info = stat($tmpFile) or die "no $tmpFile: $!"; 50cdf0e10cSrcweir if ( ($status >>=8) == 0 && ( $info->size == 0) ) { 51cdf0e10cSrcweir #print "diff worked size is 0\n"; 52cdf0e10cSrcweir $result = 1; 53cdf0e10cSrcweir } 54cdf0e10cSrcweir elsif ( ($status >>=8) == 0 && ( $info->size > 0) ) 55cdf0e10cSrcweir { 56cdf0e10cSrcweir #print "diff worked size > 0\n"; 57cdf0e10cSrcweir $result = 0; 58cdf0e10cSrcweir } 59cdf0e10cSrcweir else 60cdf0e10cSrcweir { 61cdf0e10cSrcweir #print "diff failed size > 0\n"; 62cdf0e10cSrcweir $result = 0; 63cdf0e10cSrcweir } 64cdf0e10cSrcweir } 65cdf0e10cSrcweir else 66cdf0e10cSrcweir { 67cdf0e10cSrcweir #print "not file > 0\n"; 68cdf0e10cSrcweir $result = 2; 69cdf0e10cSrcweir } 70cdf0e10cSrcweir #print "diff result = $result\n"; 71cdf0e10cSrcweir return $result; 72cdf0e10cSrcweir} 73cdf0e10cSrcweir 74cdf0e10cSrcweirif ( ! ( $logdir = shift @ARGV ) ) { 75cdf0e10cSrcweir print STDERR "No logdir specified!\n"; 76cdf0e10cSrcweir usage(); 77cdf0e10cSrcweir exit 1; 78cdf0e10cSrcweir} 79cdf0e10cSrcweir 80cdf0e10cSrcweirif ( ! ( $testlogdir = shift @ARGV ) ) { 81cdf0e10cSrcweir print STDERR "No testdocuments dir to compare against specified!\n"; 82cdf0e10cSrcweir usage(); 83cdf0e10cSrcweir exit 1; 84cdf0e10cSrcweir} 85cdf0e10cSrcweir 86cdf0e10cSrcweirif ( !(-d $logdir ) ) { 87cdf0e10cSrcweir print STDERR "No output directory $logdir exists, please create it!!!!\n"; 88cdf0e10cSrcweir exit 1; 89cdf0e10cSrcweir} 90cdf0e10cSrcweirif ( !(-d $testlogdir ) ) { 91cdf0e10cSrcweir print STDERR "the directory containing the logfiles to compare against \"$logdir\" does not exist\n"; 92cdf0e10cSrcweir usage(); 93cdf0e10cSrcweir exit 1; 94cdf0e10cSrcweir} 95cdf0e10cSrcweirprint "logdir $logdir\n"; 96cdf0e10cSrcweirprint "testlogdir $testlogdir\n"; 97cdf0e10cSrcweirsub filter_crud($) 98cdf0e10cSrcweir{ 99cdf0e10cSrcweir my $a = shift; 100cdf0e10cSrcweir 101cdf0e10cSrcweir $a =~ /~$/ && return; 102cdf0e10cSrcweir $a =~ /\#$/ && return; 103cdf0e10cSrcweir $a =~ /\.orig$/ && return; 104cdf0e10cSrcweir $a =~ /unxlng.*\.pro$/ && return; 105cdf0e10cSrcweir $a =~ /wntmsc.*\.pro$/ && return; 106cdf0e10cSrcweir $a =~ /.swp$/ && return; 107cdf0e10cSrcweir $a =~ /POSITION/ && return; 108cdf0e10cSrcweir $a =~ /ReadMe/ && return; 109cdf0e10cSrcweir $a =~ /.tmp$/ && return; 110cdf0e10cSrcweir $a =~ /\.svn/ && return; 111cdf0e10cSrcweir $a eq 'CVS' && return; 112cdf0e10cSrcweir $a eq '.' && return; 113cdf0e10cSrcweir $a eq '..' && return; 114cdf0e10cSrcweir 115cdf0e10cSrcweir return $a; 116cdf0e10cSrcweir} 117cdf0e10cSrcweirsub slurp_dir($); 118cdf0e10cSrcweir 119cdf0e10cSrcweirsub slurp_dir($) 120cdf0e10cSrcweir{ 121cdf0e10cSrcweir my $dir = shift; 122cdf0e10cSrcweir my ($dirhandle, $fname); 123cdf0e10cSrcweir my @files = (); 124cdf0e10cSrcweir 125cdf0e10cSrcweir opendir ($dirhandle, $dir) || die "Can't open $dir"; 126cdf0e10cSrcweir while ($fname = readdir ($dirhandle)) { 127cdf0e10cSrcweir $fname = filter_crud($fname); 128cdf0e10cSrcweir defined $fname || next; 129cdf0e10cSrcweir# if (-d "$dir/$fname") { 130cdf0e10cSrcweir# push @files, slurp_dir("$dir/$fname"); 131cdf0e10cSrcweir# } else 132cdf0e10cSrcweir { 133cdf0e10cSrcweir push @files, "$dir/$fname"; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir } 136cdf0e10cSrcweir closedir ($dirhandle); 137cdf0e10cSrcweir 138cdf0e10cSrcweir return @files; 139cdf0e10cSrcweir} 140cdf0e10cSrcweir 141cdf0e10cSrcweirif (-d $testlogdir) { 142cdf0e10cSrcweir push @files, slurp_dir($testlogdir); 143cdf0e10cSrcweir} 144cdf0e10cSrcweir 145cdf0e10cSrcweirmy $processed = 0; 146cdf0e10cSrcweirmy $passed = 0; 147cdf0e10cSrcweirmy @passedTests=(); 148cdf0e10cSrcweirmy @skippedTests=(); 149cdf0e10cSrcweirmy @failedTests=(); 150cdf0e10cSrcweir 151cdf0e10cSrcweirmy $failureCmd=""; 152cdf0e10cSrcweirmy $testfile = shift @ARGV; 153cdf0e10cSrcweirmy $testfilepath = "$testlogdir/$testfile"; 154cdf0e10cSrcweir$testfilepath =~ s/\.xls/\.log/; 155cdf0e10cSrcweirprint "$testfilepath\n"; 156cdf0e10cSrcweirfor $a (@files) { 157cdf0e10cSrcweir $filename = $a; 158cdf0e10cSrcweir if ( "$testfilepath" eq "$filename" ) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir $processed++; 161cdf0e10cSrcweir my $testcase = $a; 162cdf0e10cSrcweir $testcase =~ s/\.log/\.xls/; 163cdf0e10cSrcweir my $result = testLog( $a, $logdir ); 164cdf0e10cSrcweir if ( $result == 0 ) { 165cdf0e10cSrcweir push @failedTests, basename($testcase); 166cdf0e10cSrcweir if ( $failureCmd eq "" ) { $failureCmd = " diff -up $a $logdir "; } 167cdf0e10cSrcweir } 168cdf0e10cSrcweir elsif ( $result == 2 ) { 169cdf0e10cSrcweir #print "skipped $a\n"; 170cdf0e10cSrcweir push @skippedTests, $testcase; 171cdf0e10cSrcweir } 172cdf0e10cSrcweir else { 173cdf0e10cSrcweir $passed++; 174cdf0e10cSrcweir push @passedTests, $testcase; 175cdf0e10cSrcweir #print "Test document for $a \t \t passed. \n"; 176cdf0e10cSrcweir } 177cdf0e10cSrcweir } 178cdf0e10cSrcweir} 179cdf0e10cSrcweirmy $compared=@passedTests+@failedTests; 180cdf0e10cSrcweirmy $skip = @skippedTests; 181cdf0e10cSrcweirprint "skipped $skip test-cases(s)\n"; 182cdf0e10cSrcweirprint "compared $compared test-case documents\n"; 183cdf0e10cSrcweirprint "\t \t $passed tests $@passedTests\n"; 184cdf0e10cSrcweirif ( @failedTests > 0 ) { 185cdf0e10cSrcweir print "the following test-case documents failed, please examine the logs manually\n"; 186cdf0e10cSrcweir 187cdf0e10cSrcweir for $a (@failedTests) { 188cdf0e10cSrcweir print "\t$a\n"; 189cdf0e10cSrcweir } 190cdf0e10cSrcweir print "e.g. $failureCmd\n" 191cdf0e10cSrcweir} 192