update dev300-m57
[ooovba.git] / sal / qa / buildall.pl
blob5e13de786b8f1adc06e1d42c87218e002ba4efc0
1 eval 'exec perl -wS $0 ${1+"$@"}'
2 if 0;
3 #*************************************************************************
4 #
5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 #
7 # Copyright 2008 by Sun Microsystems, Inc.
9 # OpenOffice.org - a multi-platform office productivity suite
11 # $RCSfile: buildall.pl,v $
13 # $Revision: 1.7 $
15 # This file is part of OpenOffice.org.
17 # OpenOffice.org is free software: you can redistribute it and/or modify
18 # it under the terms of the GNU Lesser General Public License version 3
19 # only, as published by the Free Software Foundation.
21 # OpenOffice.org is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU Lesser General Public License version 3 for more details
25 # (a copy is included in the LICENSE file that accompanied this code).
27 # You should have received a copy of the GNU Lesser General Public License
28 # version 3 along with OpenOffice.org. If not, see
29 # <http://www.openoffice.org/license.html>
30 # for a copy of the LGPLv3 License.
32 #************************************************************************
34 # #!/usr/bin/perl -w
36 use strict;
37 use POSIX;
38 use Cwd;
39 use File::Path;
40 use English;
41 use Cwd 'chdir';
43 my $cwd = getcwd();
45 # Prototypes
46 sub initEnvironment();
47 sub main($);
48 sub checkForKillobj();
49 sub checkARGVFor($);
51 my $g_sTempDir = "";
52 my $FS = "";
54 my $nGlobalFailures = 0;
56 my %libraryRunThrough;
57 my $bBuildAll = 0;
59 # LLA: this does not exist, ... use a little bit simpler method.
60 # use File::Temp qw/ :POSIX /;
62 my $params;
63 my $param;
65 if ($#ARGV < 0)
67 $params = "test "; # debug=t TESTOPTADD=\"-boom\" TESTOPTADD=\"-noerroronexit\"
69 # my $nNumber = 55;
70 # my $sLocalParams = $params;
71 # $sLocalParams =~ s/test\s/test$nNumber /;
72 # print "Testparams: $sLocalParams\n";
73 # exit 1;
74 print "Default ";
76 else
78 # special hack!
79 if (checkForKillobj() == 1)
81 $params = "killobj";
83 elsif (checkARGVFor("buildall") == 1)
85 $bBuildAll = 1;
86 $params = "test";
88 else
90 # always run test, but envelope the other in 'TESTOPT="..."'
91 $params = "test TESTOPT=\"";
93 foreach $param (@ARGV)
95 $params = $params . " " . $param;
97 $params = $params . "\"";
99 print "User defined ";
102 print "parameters for dmake: $params\n";
104 initEnvironment();
105 main($params);
107 # ------------------------------------------------------------------------------
108 sub checkARGVFor($)
110 my $sCheckValue = shift;
111 my $sLocalParam;
112 my $nBackValue = 0;
113 foreach $sLocalParam (@ARGV)
115 if ($sLocalParam =~ /^${sCheckValue}$/)
117 $nBackValue = 1;
118 last;
121 return $nBackValue;
123 # ------------------------------------------------------------------------------
124 sub checkForKillobj()
126 my $sLocalParam;
127 my $nBackValue = 0;
128 foreach $sLocalParam (@ARGV)
130 if ($sLocalParam =~ /^killobj$/)
132 $nBackValue = 1;
133 last;
136 return $nBackValue;
139 # ------------------------------------------------------------------------------
140 sub initEnvironment()
142 my $gui = $ENV{GUI};
143 # no error output in forms of message boxes
144 $ENV{'DISABLE_SAL_DBGBOX'}="t";
146 SWITCH: {
147 if ( $gui eq "WNT" ) {
148 $FS = "\\";
149 $g_sTempDir = $ENV{TMP} ? "$ENV{TMP}${FS}" : "c:${FS}tmp${FS}";
150 last SWITCH;
152 if ( $gui eq "WIN" ) {
153 $FS = "\\";
154 $g_sTempDir = $ENV{TMP} ? "$ENV{TMP}${FS}" : "c:${FS}tmp${FS}";
155 last SWITCH;
157 if ( $gui eq "OS2" ) {
158 $FS = "\\";
159 $g_sTempDir = $ENV{TMP} ? "$ENV{TMP}${FS}" : "c:${FS}tmp${FS}";
160 last SWITCH;
162 if ( $gui eq "UNX" ) {
163 $FS = "/";
164 $g_sTempDir = $ENV{TMP} ? "$ENV{TMP}${FS}" : "${FS}tmp${FS}";
165 last SWITCH;
167 print STDERR "buildall.pl: unkown platform\n";
168 exit(1);
171 # ------------------------------------------------------------------------------
173 sub trim($)
175 my $oldstr = shift;
176 $oldstr =~ s/^\s*(.*?)\s*$/$1/;
177 return $oldstr;
180 # ------------------------------------------------------------------------------
181 sub getLibName($)
183 my $sFile = shift;
184 if ($OSNAME eq "linux" || $OSNAME eq "solaris")
186 return "lib" . $sFile . ".so";
188 if ($OSNAME eq "MSWin32" || $OSNAME eq "OS2")
190 return $sFile . ".dll";
192 return $sFile;
194 # ------------------------------------------------------------------------------
195 sub giveOutAll($)
197 my $sFailureFile = shift;
198 local *IN;
199 if (! open(IN, $sFailureFile))
201 print "ERROR: Can't open output file $sFailureFile\n";
202 return;
204 my $line;
205 while ($line = <IN>)
207 chomp($line);
208 print "$line\n";
210 close(IN);
212 # ------------------------------------------------------------------------------
213 sub giveOutFailures($$)
215 my $sTest = shift;
216 my $sFailureFile = shift;
218 my $bBegin = 0;
219 my $nFailures = 0;
221 my $line;
222 local *IN;
223 if (! open(IN, $sFailureFile))
225 print "ERROR: Can't open output file $sFailureFile\n";
226 return;
229 my $bStartUnitTest = 0;
230 while ($line = <IN>)
232 chomp($line);
233 if ( $line =~ /^- start unit test/)
235 $bStartUnitTest = 1;
238 close(IN);
240 if ($bStartUnitTest == 0)
242 print "\nFailure: Unit test not started. Maybe compiler error.\n";
243 giveOutAll($sFailureFile);
244 $nFailures++;
245 # exit(1);
247 else
249 open(IN, $sFailureFile);
250 # check if testshl2 was started
251 while ($line = <IN>)
253 chomp($line);
255 # handling of the states
256 if ( $line =~ /^\# -- BEGIN:/)
258 $bBegin = 1;
260 elsif ( $line =~ /^\# -- END:/)
262 $bBegin = 0;
264 else
266 if ($bBegin == 1)
268 print "$line\n";
269 $nFailures++;
273 close(IN);
276 if ($nFailures > 0)
278 # extra return for a better output
279 print "\nFailures occured: $nFailures\n";
280 print "The whole output can be found in $sFailureFile\n";
281 print "\n";
283 # Statistics
284 $nGlobalFailures += $nFailures;
287 # ------------------------------------------------------------------------------
288 sub printOnLibrary($)
290 my $sTarget = shift;
291 print " on library: " . getLibName($sTarget);
293 # ------------------------------------------------------------------------------
294 sub runASingleTest($$)
296 my $sTarget = shift;
297 my $params = shift;
298 my $dmake = "dmake $params";
300 my $sLogPath = $g_sTempDir . "dmake_out_$$";
301 mkdir($sLogPath);
302 my $sLogFile = $sLogPath . "/" . $sTarget . ".out";
304 # due to the fact, a library name in one project is distinct, we should remember all already run through libraries and
305 # supress same libraries, if they occur one more.
307 if (exists $libraryRunThrough{getLibName($sTarget)})
309 # already done
310 return;
312 printOnLibrary($sTarget);
313 print "\n";
315 # redirect tcsh ">&" (stdout, stderr)
316 # redirect 4nt ">" (stdout), "2>" (stderr)
317 # print "OSNAME: $OSNAME\n";
318 # LLA: redirect check canceled, seems to be not work as I want.
319 # my $redirect = "";
320 # if ($OSNAME eq "linux" || $OSNAME eq "solaris")
322 # # print "UNIX, linux or solaris\n";
323 # $redirect = '>>&!' . $sLogFile;
325 # else
327 # if ($OSNAME eq "MSWin32" || $OSNAME eq "OS2")
329 # # test
330 # $redirect = ">>$sLogFile 2>>$sLogFile";
333 # print "$dmake $redirect\n";
335 # LLA: so system does also not work as I imagine
336 # system("$dmake $redirect");
338 # LLA: next check, use open with pipe
340 local *LOGFILE;
341 if (! open( LOGFILE, '>' . "$sLogFile"))
343 print "ERROR: can't open logfile: $sLogFile\n";
344 return;
347 my $line;
348 local *DMAKEOUTPUT;
349 if (! open( DMAKEOUTPUT, "$dmake 2>&1 |"))
351 print "ERROR: can't open dmake\n";
352 return;
354 while ($line = <DMAKEOUTPUT>)
356 chomp($line);
357 print LOGFILE "$line\n";
359 close(DMAKEOUTPUT);
360 close(LOGFILE);
362 giveOutFailures($sTarget, $sLogFile);
364 $libraryRunThrough{getLibName($sTarget)} = "done";
367 # ------------------------------------------------------------------------------
368 sub interpretLine($)
370 my $line = shift;
372 my $path;
373 my $file;
375 if ($line =~ /^\#/ || $line =~ /^$/)
377 # remark or empty line
379 else
381 # special format, $file == $path
382 ($path, $file) = split(/;/, $line);
383 if (! $file)
385 $file = $path;
387 $file = trim($file);
388 $path = trim($path);
390 return $path, $file;
392 # ------------------------------------------------------------------------------
393 sub runTestsOnPath($$$)
395 my $path = shift;
396 my $file = shift;
397 my $params = shift;
399 # empty values
400 if (!$path || $path eq "")
402 # DBG: print "empty path '$path'\n";
403 return;
405 if (!$file || $file eq "")
407 # DBG: print "empty file '$file'\n";
408 return;
411 # print "File: '$file', Path: '$path'\n";
412 print "Work in directory: $path\n";
413 my $newpath = $cwd . $FS . $path;
414 # print "chdir to $newpath\n";
416 my $error = chdir($newpath);
417 cwd();
419 # run through the hole makefile.mk and check if SHL<D>TARGET = ... exist, for every target call "dmake test<D>"
421 local *MAKEFILE_MK;
422 if (! open(MAKEFILE_MK, "makefile.mk"))
424 print "ERROR: can't open makefile.mk in path: $newpath\n";
425 print "please check your libs2test.txt file in qa directory.\n";
427 my $line;
428 my $nNumber;
429 my $sTarget;
430 my $sLocalParams;
432 while($line = <MAKEFILE_MK>)
434 chomp($line);
436 if ($line =~ /SHL(\d)TARGET=(.*)/)
438 $nNumber = $1;
439 $sTarget = trim($2);
441 # DBG: print "test$number is lib: $target\n";
442 $sLocalParams = $params . " "; # append a whitespace, so we can check if 'test' exist without additional digits
443 $sLocalParams =~ s/test\s/test$nNumber/;
444 # DBG: print "$sLocalParams\n";
445 if ($bBuildAll == 1 ||
446 $file eq $sTarget)
448 # print "runASingleTest on Target: $sTarget 'dmake $sLocalParams'\n";
449 runASingleTest($sTarget, $sLocalParams);
451 else
453 # printOnLibrary($sTarget);
454 # print " suppressed, not in libs2test.txt\n";
458 close(MAKEFILE_MK);
461 # ------------------------------------------------------------------------------
463 sub main($)
465 my $params = shift;
466 # my $sLogFile = shift; # "buildall_$$.out";
467 local *LIBS2TEST;
468 my $filename = "libs2test.txt";
469 my $line;
471 open(LIBS2TEST, $filename) || die "can't open $filename\n";
473 while($line = <LIBS2TEST>)
475 chomp($line);
476 # DOS Hack grrrr...
477 while ($line =~ /
480 $line = substr($line, 0, -1);
483 # print "$line\n";
484 my $path;
485 my $file;
486 ($path, $file) = interpretLine($line);
487 runTestsOnPath($path, $file, $params);
489 close(LIBS2TEST);
491 print "\nComplete logging information will be found in dir: ".$g_sTempDir."dmake_out_$$/\n";
493 if ($nGlobalFailures > 0)
495 print "\nFailures over all occured: $nGlobalFailures\n";
496 print "\nPASSED FAILED.\n";
498 else
500 print "\nPASSED OK.\n";
504 # ------------------------------------------------------------------------------
506 # TODO:
507 # -verbose
508 # -fan - \ | /
510 # END!