update dev300-m58
[ooovba.git] / smoketestoo_native / testlog.pl
blobedeef8c70600d51e2b606bae71edf3a1d399e1f2
2 eval 'exec perl -wS $0 ${1+"$@"}'
3 if 0;
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 #
8 # Copyright 2008 by Sun Microsystems, Inc.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # $RCSfile: testlog.pl,v $
14 # $Revision: 1.6 $
16 # This file is part of OpenOffice.org.
18 # OpenOffice.org is free software: you can redistribute it and/or modify
19 # it under the terms of the GNU Lesser General Public License version 3
20 # only, as published by the Free Software Foundation.
22 # OpenOffice.org is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU Lesser General Public License version 3 for more details
26 # (a copy is included in the LICENSE file that accompanied this code).
28 # You should have received a copy of the GNU Lesser General Public License
29 # version 3 along with OpenOffice.org. If not, see
30 # <http://www.openoffice.org/license.html>
31 # for a copy of the LGPLv3 License.
33 #*************************************************************************
35 ### globals ###
37 $is_debug = 0;
39 $global_log = "log.dat";
41 %logfiles_list = ("writer", "swlog.dat",
42 "math", "smalog.dat",
43 "HTML", "shptlog.dat",
44 "draw", "sdrwlog.dat",
45 "impress", "sdlog.dat",
46 "calc", "sclog.dat",
47 "chart", "schlog.dat",
48 "Java", "javalog.dat",
49 "Database", "dblog.dat",
50 "Extension", "extlog.dat"
53 %log = ();
54 @ApplicationLog = ();
55 $dont_kill ="dont_deinstall";
56 $error_str = "error";
57 $tests_complete = "---";
58 $gui = $ENV{GUI};
59 $inpath = $ENV{INPATH};
60 $cygwin = "cygwin";
62 if ($^O =~ /cygwin/) {
63 $gui = $cygwin;
66 if (($gui eq "UNX") or ($gui eq $cygwin)) {
67 $pathslash = "/";
69 else
71 $pathslash = "\\";
74 $misc = $inpath . $pathslash . "misc" . $pathslash;
75 $okfile = $misc . "ok.bat";
76 umask (02);
78 ### sub routines ###
80 sub test_logfile {
81 my ($file, $testname) = @_;
82 my ($line, $failed, $complete, $linecount, $LastLineError);
84 $failed = 0;
85 $complete = 0;
86 $linecount = -1;
87 $LastLineError = 0;
89 if (! -e $file) {
90 print "error: $testname failed! Logfile is missing.\n" if $is_debug;
92 return (0,0);
95 open TABLE, "<$file" or die "Error: can´t open log file $file]";
97 while(<TABLE>) {
98 $line = $_;
99 chomp $line;
100 $linecount++;
101 if ( $line =~ /$error_str/ ) {
102 print "error: $testname: $line\n";
103 $failed = 1;
104 $LastLineError = 1;
106 elsif ( $line =~ /$tests_complete/ ) {
107 $complete = 1;
108 print "$file: $line\n" if $is_debug;
110 else
112 print "$testname: $line\n" if $is_debug;
113 $LastLineError = 0;
117 close TABLE;
119 print "$failed $complete $LastLineError $linecount\n" if $is_debug;
121 if (!$complete) {
122 my $message = "error: $testname: the test was not complete!";
123 if ((!$failed) || (($failed) && (!$LastLineError))) {
124 my $errormessage = getLog ($testname, $linecount+1);
125 if ($errormessage ne "") {
126 $message .= " $errormessage possibly failed!";
129 if (!$failed && !$is_testerror) {
130 print "$message\n";
134 if (!$failed && $complete) {
135 print "true\n" if $is_debug;
136 return (1,1);
138 else
140 print "false\n" if $is_debug;
141 return (0,1);
145 sub readGlobalLog {
146 my ($line);
147 my $logfilename = $logfiledir . $pathslash . $global_log;
148 if (! -e $logfilename) {
149 print "$logfilename: file is missing\n" if $is_debug;
150 return 0;
153 open TABLE, "<$logfilename" or die "Error: can´t open log file $logfilename]";
155 my $failed = 0;
156 my $complete = 0;
157 my $FirstLine = 1;
158 while(defined($line = <TABLE>) and !$complete) {
159 chomp $line;
160 if ($FirstLine) {
161 if ( $line =~ /Sequence of testing/ ) {
162 $FirstLine = 0;
163 next;
165 else {
166 print "$logfilename: $line\n" if $is_debug;
167 $failed = 1;
168 return 0;
171 else {
172 if ( $line eq "" ) {
173 $complete = 1;
174 next;
176 my @splitedLine = split(/:/,$line);
177 my $testApplication = $splitedLine [0];
178 $testApplication =~ s/^ *(.*?) *$/$1/g; #truncate
179 my $testAction = $splitedLine [1];
180 @splitedLine = split(/,/,$testAction);
181 my @log_array = ();
182 foreach my $action (@splitedLine) {
183 $action =~ s/^ *(.*?) *$/$1/g; #truncate
184 if ($action =~ /\//) {
185 my @splitAction = split(/\//,$action);
186 my @specialAction;
187 foreach my $doubleaction (@splitAction) {
188 $doubleaction =~ s/^ *(.*?) *$/$1/g; #truncate
189 push (@specialAction, $doubleaction);
191 $action = join (' or ', @specialAction);
192 foreach my $doubleaction (@splitAction) {
193 push (@log_array, $action);
196 else {
197 push (@log_array, $action);
200 push (@ApplicationLog, $testApplication);
201 $log{$testApplication} = \@log_array;
205 close TABLE;
207 return 1;
210 sub getLog {
211 my ($testname, $linecount) = @_;
212 if ($linecount <= $#{@{$log{$testname}}}) {
213 return $log{$testname}[$linecount];
215 else {
216 return "";
220 ### main ###
222 $idStr = ' $Revision: 1.6 $ ';
223 $idStr =~ /Revision:\s+(\S+)\s+\$/
224 ? ($cpflat2minor_rev = $1) : ($cpflat2minor_rev = "-");
226 print "TestLog -- Version: $cpflat2minor_rev\n";
228 if (-e $okfile) {
229 unlink ($okfile);
232 if ( ($#ARGV >-1) && ($#ARGV < 1) ) {
233 $ARGV[0] =~ s/\"//g;
236 if ( ! ( ($#ARGV < 1) && $ARGV[0] && (-d $ARGV[0]) ) ) {
237 print "Error! Usage: testlog <log_directory>\n" ;
238 exit(1);
241 $logfiledir = $ARGV[0];
242 $is_testerror = 0;
243 $is_OneTestAvailable = 0;
245 print "%logfiles_list\n" if $is_debug;
247 readGlobalLog();
249 foreach my $applog (@ApplicationLog) {
250 if (!exists($logfiles_list{$applog})) {
251 next;
253 my $logname = $logfiles_list{$applog};
254 $current_file = $logfiledir . $pathslash . $logname;
255 my ($error, $logfile) = test_logfile ($current_file, $applog);
257 if ($logfile) {
258 $is_OneTestAvailable = 1;
260 elsif (!$is_testerror) {
261 print "error: $applog failed! Logfile is missing.\n";
264 if (!$error) {
265 $is_testerror = 1;
270 # write file to prevent deinstallation of office
271 if ($is_testerror) {
272 $dont_del_file = $logfiledir . $pathslash . $dont_kill;
273 open (ERRFILE, ">$dont_del_file");
274 print ERRFILE "dont delete flag";
275 close (ERRFILE);
277 else {
278 print "$okfile\n" if $is_debug;
279 open( OKFILE, ">$okfile");
280 print OKFILE "echo ok!\n";
281 close( OKFILE );
282 chmod (0775, "$okfile");
285 if (!$is_OneTestAvailable) {
286 print "error: no test succeeded! Maybe Office crashed during starting!\n";
287 $is_testerror = 1;
290 exit($is_testerror);