merged tag ooo/DEV300_m102
[LibreOffice.git] / sal / qa / buildall.pl
blob03eadb1b7fc0d1d6e0089de6f06ba4ba5e5ad458
1 eval 'exec perl -wS $0 ${1+"$@"}'
2 if 0;
3 #*************************************************************************
5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 # Copyright 2000, 2010 Oracle and/or its affiliates.
9 # OpenOffice.org - a multi-platform office productivity suite
11 # This file is part of OpenOffice.org.
13 # OpenOffice.org is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU Lesser General Public License version 3
15 # only, as published by the Free Software Foundation.
17 # OpenOffice.org is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU Lesser General Public License version 3 for more details
21 # (a copy is included in the LICENSE file that accompanied this code).
23 # You should have received a copy of the GNU Lesser General Public License
24 # version 3 along with OpenOffice.org. If not, see
25 # <http://www.openoffice.org/license.html>
26 # for a copy of the LGPLv3 License.
28 #************************************************************************
30 # #!/usr/bin/perl -w
32 use strict;
33 use POSIX;
34 use Cwd;
35 use File::Path;
36 use English;
37 use Cwd 'chdir';
39 my $cwd = getcwd();
41 # Prototypes
42 sub initEnvironment();
43 sub main($);
44 sub checkForKillobj();
45 sub checkARGVFor($);
47 my $g_sTempDir = "";
48 my $FS = "";
50 my $nGlobalFailures = 0;
52 my %libraryRunThrough;
53 my $bBuildAll = 0;
55 # LLA: this does not exist, ... use a little bit simpler method.
56 # use File::Temp qw/ :POSIX /;
58 my $params;
59 my $param;
61 if ($#ARGV < 0)
63 $params = "test "; # debug=t TESTOPTADD=\"-boom\" TESTOPTADD=\"-noerroronexit\"
65 # my $nNumber = 55;
66 # my $sLocalParams = $params;
67 # $sLocalParams =~ s/test\s/test$nNumber /;
68 # print "Testparams: $sLocalParams\n";
69 # exit 1;
70 print "Default ";
72 else
74 # special hack!
75 if (checkForKillobj() == 1)
77 $params = "killobj";
79 elsif (checkARGVFor("buildall") == 1)
81 $bBuildAll = 1;
82 $params = "test";
84 else
86 # always run test, but envelope the other in 'TESTOPT="..."'
87 $params = "test TESTOPT=\"";
89 foreach $param (@ARGV)
91 $params = $params . " " . $param;
93 $params = $params . "\"";
95 print "User defined ";
98 print "parameters for dmake: $params\n";
100 initEnvironment();
101 main($params);
103 # ------------------------------------------------------------------------------
104 sub checkARGVFor($)
106 my $sCheckValue = shift;
107 my $sLocalParam;
108 my $nBackValue = 0;
109 foreach $sLocalParam (@ARGV)
111 if ($sLocalParam =~ /^${sCheckValue}$/)
113 $nBackValue = 1;
114 last;
117 return $nBackValue;
119 # ------------------------------------------------------------------------------
120 sub checkForKillobj()
122 my $sLocalParam;
123 my $nBackValue = 0;
124 foreach $sLocalParam (@ARGV)
126 if ($sLocalParam =~ /^killobj$/)
128 $nBackValue = 1;
129 last;
132 return $nBackValue;
135 # ------------------------------------------------------------------------------
136 sub initEnvironment()
138 my $gui = $ENV{GUI};
139 # no error output in forms of message boxes
140 $ENV{'DISABLE_SAL_DBGBOX'}="t";
142 SWITCH: {
143 if ( $gui eq "WNT" ) {
144 $FS = "\\";
145 $g_sTempDir = $ENV{TMP} ? "$ENV{TMP}${FS}" : "c:${FS}tmp${FS}";
146 last SWITCH;
148 if ( $gui eq "WIN" ) {
149 $FS = "\\";
150 $g_sTempDir = $ENV{TMP} ? "$ENV{TMP}${FS}" : "c:${FS}tmp${FS}";
151 last SWITCH;
153 if ( $gui eq "OS2" ) {
154 $FS = "\\";
155 $g_sTempDir = $ENV{TMP} ? "$ENV{TMP}${FS}" : "c:${FS}tmp${FS}";
156 last SWITCH;
158 if ( $gui eq "UNX" ) {
159 $FS = "/";
160 $g_sTempDir = $ENV{TMP} ? "$ENV{TMP}${FS}" : "${FS}tmp${FS}";
161 last SWITCH;
163 print STDERR "buildall.pl: unkown platform\n";
164 exit(1);
167 # ------------------------------------------------------------------------------
169 sub trim($)
171 my $oldstr = shift;
172 $oldstr =~ s/^\s*(.*?)\s*$/$1/;
173 return $oldstr;
176 # ------------------------------------------------------------------------------
177 sub getLibName($)
179 my $sFile = shift;
180 if ($OSNAME eq "linux" || $OSNAME eq "solaris")
182 return "lib" . $sFile . ".so";
184 if ($OSNAME eq "MSWin32" || $OSNAME eq "OS2")
186 return $sFile . ".dll";
188 return $sFile;
190 # ------------------------------------------------------------------------------
191 sub giveOutAll($)
193 my $sFailureFile = shift;
194 local *IN;
195 if (! open(IN, $sFailureFile))
197 print "ERROR: Can't open output file $sFailureFile\n";
198 return;
200 my $line;
201 while ($line = <IN>)
203 chomp($line);
204 print "$line\n";
206 close(IN);
208 # ------------------------------------------------------------------------------
209 sub giveOutFailures($$)
211 my $sTest = shift;
212 my $sFailureFile = shift;
214 my $bBegin = 0;
215 my $nFailures = 0;
217 my $line;
218 local *IN;
219 if (! open(IN, $sFailureFile))
221 print "ERROR: Can't open output file $sFailureFile\n";
222 return;
225 my $bStartUnitTest = 0;
226 while ($line = <IN>)
228 chomp($line);
229 if ( $line =~ /^- start unit test/)
231 $bStartUnitTest = 1;
234 close(IN);
236 if ($bStartUnitTest == 0)
238 print "\nFailure: Unit test not started. Maybe compiler error.\n";
239 giveOutAll($sFailureFile);
240 $nFailures++;
241 # exit(1);
243 else
245 open(IN, $sFailureFile);
246 # check if testshl2 was started
247 while ($line = <IN>)
249 chomp($line);
251 # handling of the states
252 if ( $line =~ /^\# -- BEGIN:/)
254 $bBegin = 1;
256 elsif ( $line =~ /^\# -- END:/)
258 $bBegin = 0;
260 else
262 if ($bBegin == 1)
264 print "$line\n";
265 $nFailures++;
269 close(IN);
272 if ($nFailures > 0)
274 # extra return for a better output
275 print "\nFailures occured: $nFailures\n";
276 print "The whole output can be found in $sFailureFile\n";
277 print "\n";
279 # Statistics
280 $nGlobalFailures += $nFailures;
283 # ------------------------------------------------------------------------------
284 sub printOnLibrary($)
286 my $sTarget = shift;
287 print " on library: " . getLibName($sTarget);
289 # ------------------------------------------------------------------------------
290 sub runASingleTest($$)
292 my $sTarget = shift;
293 my $params = shift;
294 my $dmake = "dmake $params";
296 my $sLogPath = $g_sTempDir . "dmake_out_$$";
297 mkdir($sLogPath);
298 my $sLogFile = $sLogPath . "/" . $sTarget . ".out";
300 # due to the fact, a library name in one project is distinct, we should remember all already run through libraries and
301 # supress same libraries, if they occur one more.
303 if (exists $libraryRunThrough{getLibName($sTarget)})
305 # already done
306 return;
308 printOnLibrary($sTarget);
309 print "\n";
311 # redirect tcsh ">&" (stdout, stderr)
312 # redirect 4nt ">" (stdout), "2>" (stderr)
313 # print "OSNAME: $OSNAME\n";
314 # LLA: redirect check canceled, seems to be not work as I want.
315 # my $redirect = "";
316 # if ($OSNAME eq "linux" || $OSNAME eq "solaris")
318 # # print "UNIX, linux or solaris\n";
319 # $redirect = '>>&!' . $sLogFile;
321 # else
323 # if ($OSNAME eq "MSWin32" || $OSNAME eq "OS2")
325 # # test
326 # $redirect = ">>$sLogFile 2>>$sLogFile";
329 # print "$dmake $redirect\n";
331 # LLA: so system does also not work as I imagine
332 # system("$dmake $redirect");
334 # LLA: next check, use open with pipe
336 local *LOGFILE;
337 if (! open( LOGFILE, '>' . "$sLogFile"))
339 print "ERROR: can't open logfile: $sLogFile\n";
340 return;
343 my $line;
344 local *DMAKEOUTPUT;
345 if (! open( DMAKEOUTPUT, "$dmake 2>&1 |"))
347 print "ERROR: can't open dmake\n";
348 return;
350 while ($line = <DMAKEOUTPUT>)
352 chomp($line);
353 print LOGFILE "$line\n";
355 close(DMAKEOUTPUT);
356 close(LOGFILE);
358 giveOutFailures($sTarget, $sLogFile);
360 $libraryRunThrough{getLibName($sTarget)} = "done";
363 # ------------------------------------------------------------------------------
364 sub interpretLine($)
366 my $line = shift;
368 my $path;
369 my $file;
371 if ($line =~ /^\#/ || $line =~ /^$/)
373 # remark or empty line
375 else
377 # special format, $file == $path
378 ($path, $file) = split(/;/, $line);
379 if (! $file)
381 $file = $path;
383 $file = trim($file);
384 $path = trim($path);
386 return $path, $file;
388 # ------------------------------------------------------------------------------
389 sub runTestsOnPath($$$)
391 my $path = shift;
392 my $file = shift;
393 my $params = shift;
395 # empty values
396 if (!$path || $path eq "")
398 # DBG: print "empty path '$path'\n";
399 return;
401 if (!$file || $file eq "")
403 # DBG: print "empty file '$file'\n";
404 return;
407 # print "File: '$file', Path: '$path'\n";
408 print "Work in directory: $path\n";
409 my $newpath = $cwd . $FS . $path;
410 # print "chdir to $newpath\n";
412 my $error = chdir($newpath);
413 cwd();
415 # run through the hole makefile.mk and check if SHL<D>TARGET = ... exist, for every target call "dmake test<D>"
417 local *MAKEFILE_MK;
418 if (! open(MAKEFILE_MK, "makefile.mk"))
420 print "ERROR: can't open makefile.mk in path: $newpath\n";
421 print "please check your libs2test.txt file in qa directory.\n";
423 my $line;
424 my $nNumber;
425 my $sTarget;
426 my $sLocalParams;
428 while($line = <MAKEFILE_MK>)
430 chomp($line);
432 if ($line =~ /SHL(\d)TARGET=(.*)/)
434 $nNumber = $1;
435 $sTarget = trim($2);
437 # DBG: print "test$number is lib: $target\n";
438 $sLocalParams = $params . " "; # append a whitespace, so we can check if 'test' exist without additional digits
439 $sLocalParams =~ s/test\s/test$nNumber/;
440 # DBG: print "$sLocalParams\n";
441 if ($bBuildAll == 1 ||
442 $file eq $sTarget)
444 # print "runASingleTest on Target: $sTarget 'dmake $sLocalParams'\n";
445 runASingleTest($sTarget, $sLocalParams);
447 else
449 # printOnLibrary($sTarget);
450 # print " suppressed, not in libs2test.txt\n";
454 close(MAKEFILE_MK);
457 # ------------------------------------------------------------------------------
459 sub main($)
461 my $params = shift;
462 # my $sLogFile = shift; # "buildall_$$.out";
463 local *LIBS2TEST;
464 my $filename = "libs2test.txt";
465 my $line;
467 open(LIBS2TEST, $filename) || die "can't open $filename\n";
469 while($line = <LIBS2TEST>)
471 chomp($line);
472 # DOS Hack grrrr...
473 while ($line =~ /
476 $line = substr($line, 0, -1);
479 # print "$line\n";
480 my $path;
481 my $file;
482 ($path, $file) = interpretLine($line);
483 runTestsOnPath($path, $file, $params);
485 close(LIBS2TEST);
487 print "\nComplete logging information will be found in dir: ".$g_sTempDir."dmake_out_$$/\n";
489 if ($nGlobalFailures > 0)
491 print "\nFailures over all occured: $nGlobalFailures\n";
492 print "\nPASSED FAILED.\n";
494 else
496 print "\nPASSED OK.\n";
500 # ------------------------------------------------------------------------------
502 # TODO:
503 # -verbose
504 # -fan - \ | /
506 # END!