xref: /aoo4110/main/sal/qa/buildall.pl (revision b1cdbd2c)
1eval 'exec perl -wS $0 ${1+"$@"}'
2    if 0;
3#**************************************************************
4#
5#  Licensed to the Apache Software Foundation (ASF) under one
6#  or more contributor license agreements.  See the NOTICE file
7#  distributed with this work for additional information
8#  regarding copyright ownership.  The ASF licenses this file
9#  to you under the Apache License, Version 2.0 (the
10#  "License"); you may not use this file except in compliance
11#  with the License.  You may obtain a copy of the License at
12#
13#    http://www.apache.org/licenses/LICENSE-2.0
14#
15#  Unless required by applicable law or agreed to in writing,
16#  software distributed under the License is distributed on an
17#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18#  KIND, either express or implied.  See the License for the
19#  specific language governing permissions and limitations
20#  under the License.
21#
22#**************************************************************
23
24# #!/usr/bin/perl -w
25
26use strict;
27use POSIX;
28use Cwd;
29use File::Path;
30use English;
31use Cwd 'chdir';
32
33my $cwd = getcwd();
34
35# Prototypes
36sub initEnvironment();
37sub main($);
38sub checkForKillobj();
39sub checkARGVFor($);
40
41my $g_sTempDir = "";
42my $FS = "";
43
44my $nGlobalFailures = 0;
45
46my %libraryRunThrough;
47my $bBuildAll = 0;
48
49# LLA: this does not exist, ... use a little bit simpler method.
50# use File::Temp qw/ :POSIX /;
51
52my $params;
53my $param;
54
55if ($#ARGV < 0)
56{
57    $params = "test "; # debug=t TESTOPTADD=\"-boom\"   TESTOPTADD=\"-noerroronexit\"
58
59    # my $nNumber = 55;
60    # my $sLocalParams = $params;
61    # $sLocalParams =~ s/test\s/test$nNumber /;
62    # print "Testparams: $sLocalParams\n";
63    # exit 1;
64    print "Default ";
65}
66else
67{
68    # special hack!
69    if (checkForKillobj() == 1)
70    {
71        $params = "killobj";
72    }
73    elsif (checkARGVFor("buildall") == 1)
74    {
75        $bBuildAll = 1;
76        $params = "test";
77    }
78    else
79    {
80        # always run test, but envelope the other in 'TESTOPT="..."'
81        $params = "test TESTOPT=\"";
82
83        foreach $param (@ARGV)
84        {
85            $params = $params . " " . $param;
86        }
87        $params = $params . "\"";
88    }
89    print "User defined ";
90}
91
92print "parameters for dmake: $params\n";
93
94initEnvironment();
95main($params);
96
97# ------------------------------------------------------------------------------
98sub checkARGVFor($)
99{
100    my $sCheckValue = shift;
101    my $sLocalParam;
102    my $nBackValue = 0;
103    foreach $sLocalParam (@ARGV)
104    {
105        if ($sLocalParam =~ /^${sCheckValue}$/)
106        {
107            $nBackValue = 1;
108            last;
109        }
110    }
111    return $nBackValue;
112}
113# ------------------------------------------------------------------------------
114sub checkForKillobj()
115{
116    my $sLocalParam;
117    my $nBackValue = 0;
118    foreach $sLocalParam (@ARGV)
119    {
120        if ($sLocalParam =~ /^killobj$/)
121        {
122            $nBackValue = 1;
123            last;
124        }
125    }
126    return $nBackValue;
127}
128
129# ------------------------------------------------------------------------------
130sub initEnvironment()
131{
132    my $gui = $ENV{GUI};
133    # no error output in forms of message boxes
134    $ENV{'DISABLE_SAL_DBGBOX'}="t";
135
136  SWITCH: {
137      if ( $gui eq "WNT" ) {
138          $FS             = "\\";
139          $g_sTempDir         = $ENV{TMP}  ? "$ENV{TMP}${FS}" : "c:${FS}tmp${FS}";
140          last SWITCH;
141      }
142      if ( $gui eq "WIN" ) {
143          $FS             = "\\";
144          $g_sTempDir         = $ENV{TMP}  ? "$ENV{TMP}${FS}" : "c:${FS}tmp${FS}";
145          last SWITCH;
146      }
147      if ( $gui eq "OS2" ) {
148          $FS             = "\\";
149          $g_sTempDir         = $ENV{TMP}  ? "$ENV{TMP}${FS}" : "c:${FS}tmp${FS}";
150          last SWITCH;
151      }
152      if ( $gui eq "UNX" ) {
153          $FS             = "/";
154          $g_sTempDir         = $ENV{TMP}  ? "$ENV{TMP}${FS}" : "${FS}tmp${FS}";
155          last SWITCH;
156      }
157      print STDERR "buildall.pl: unkown platform\n";
158      exit(1);
159  }
160}
161# ------------------------------------------------------------------------------
162
163sub trim($)
164{
165    my $oldstr = shift;
166    $oldstr =~ s/^\s*(.*?)\s*$/$1/;
167    return $oldstr;
168}
169
170# ------------------------------------------------------------------------------
171sub getLibName($)
172{
173    my $sFile = shift;
174    if ($OSNAME eq "linux" || $OSNAME eq "solaris")
175    {
176        return "lib" . $sFile . ".so";
177    }
178    if ($OSNAME eq "MSWin32" || $OSNAME eq "OS2")
179    {
180        return $sFile . ".dll";
181    }
182    return $sFile;
183}
184# ------------------------------------------------------------------------------
185sub giveOutAll($)
186{
187    my $sFailureFile = shift;
188    local *IN;
189    if (! open(IN, $sFailureFile))
190    {
191        print "ERROR: Can't open output file $sFailureFile\n";
192        return;
193    }
194    my $line;
195    while ($line = <IN>)
196    {
197        chomp($line);
198        print "$line\n";
199    }
200    close(IN);
201}
202# ------------------------------------------------------------------------------
203sub giveOutFailures($$)
204{
205    my $sTest = shift;
206    my $sFailureFile = shift;
207
208    my $bBegin = 0;
209    my $nFailures = 0;
210
211    my $line;
212    local *IN;
213    if (! open(IN, $sFailureFile))
214    {
215        print "ERROR: Can't open output file $sFailureFile\n";
216        return;
217    }
218
219    my $bStartUnitTest = 0;
220    while ($line = <IN>)
221    {
222        chomp($line);
223        if ( $line =~ /^- start unit test/)
224        {
225            $bStartUnitTest = 1;
226        }
227    }
228    close(IN);
229
230    if ($bStartUnitTest == 0)
231    {
232        print "\nFailure: Unit test not started. Maybe compiler error.\n";
233        giveOutAll($sFailureFile);
234        $nFailures++;
235        # exit(1);
236    }
237    else
238    {
239        open(IN, $sFailureFile);
240        # check if testshl2 was started
241        while ($line = <IN>)
242        {
243            chomp($line);
244
245            # handling of the states
246            if ( $line =~ /^\# -- BEGIN:/)
247            {
248                $bBegin = 1;
249            }
250            elsif ( $line =~ /^\# -- END:/)
251            {
252                $bBegin = 0;
253            }
254            else
255            {
256                if ($bBegin == 1)
257                {
258                    print "$line\n";
259                    $nFailures++;
260                }
261            }
262        }
263        close(IN);
264    }
265
266    if ($nFailures > 0)
267    {
268        # extra return for a better output
269        print "\nFailures occured: $nFailures\n";
270        print "The whole output can be found in $sFailureFile\n";
271        print "\n";
272
273        # Statistics
274        $nGlobalFailures += $nFailures;
275    }
276}
277# ------------------------------------------------------------------------------
278sub printOnLibrary($)
279{
280    my $sTarget = shift;
281    print "       on library: " . getLibName($sTarget);
282}
283# ------------------------------------------------------------------------------
284sub runASingleTest($$)
285{
286    my $sTarget = shift;
287    my $params = shift;
288    my $dmake = "dmake $params";
289
290    my $sLogPath = $g_sTempDir . "dmake_out_$$";
291    mkdir($sLogPath);
292    my $sLogFile = $sLogPath . "/" . $sTarget . ".out";
293
294    # due to the fact, a library name in one project is distinct, we should remember all already run through libraries and
295    # supress same libraries, if they occur one more.
296
297    if (exists $libraryRunThrough{getLibName($sTarget)})
298    {
299        # already done
300        return;
301    }
302    printOnLibrary($sTarget);
303    print "\n";
304
305# redirect tcsh ">&" (stdout, stderr)
306# redirect 4nt   ">" (stdout), "2>" (stderr)
307# print "OSNAME: $OSNAME\n";
308# LLA: redirect check canceled, seems to be not work as I want.
309#     my $redirect = "";
310#     if ($OSNAME eq "linux" || $OSNAME eq "solaris")
311#     {
312#         # print "UNIX, linux or solaris\n";
313#         $redirect = '>>&!' . $sLogFile;
314#     }
315#     else
316#     {
317#         if ($OSNAME eq "MSWin32" || $OSNAME eq "OS2")
318#         {
319#             # test
320#             $redirect = ">>$sLogFile 2>>$sLogFile";
321#         }
322#     }
323#     print "$dmake $redirect\n";
324
325# LLA: so system does also not work as I imagine
326#    system("$dmake $redirect");
327
328# LLA: next check, use open with pipe
329
330    local *LOGFILE;
331    if (! open( LOGFILE, '>' . "$sLogFile"))
332    {
333        print "ERROR: can't open logfile: $sLogFile\n";
334        return;
335    }
336
337    my $line;
338    local *DMAKEOUTPUT;
339    if (! open( DMAKEOUTPUT, "$dmake 2>&1 |"))
340    {
341        print "ERROR: can't open dmake\n";
342        return;
343    }
344    while ($line = <DMAKEOUTPUT>)
345    {
346        chomp($line);
347        print LOGFILE "$line\n";
348    }
349    close(DMAKEOUTPUT);
350    close(LOGFILE);
351
352    giveOutFailures($sTarget, $sLogFile);
353
354    $libraryRunThrough{getLibName($sTarget)} = "done";
355}
356
357# ------------------------------------------------------------------------------
358sub interpretLine($)
359{
360    my $line = shift;
361
362    my $path;
363    my $file;
364
365    if ($line =~ /^\#/ || $line =~ /^$/)
366    {
367        # remark or empty line
368    }
369    else
370    {
371        # special format, $file == $path
372        ($path, $file) = split(/;/, $line);
373        if (! $file)
374        {
375            $file = $path;
376        }
377        $file = trim($file);
378        $path = trim($path);
379    }
380    return $path, $file;
381}
382# ------------------------------------------------------------------------------
383sub runTestsOnPath($$$)
384{
385    my $path = shift;
386    my $file = shift;
387    my $params = shift;
388
389    # empty values
390    if (!$path || $path eq "")
391    {
392        # DBG: print "empty path '$path'\n";
393        return;
394    }
395    if (!$file || $file eq "")
396    {
397        # DBG: print "empty file '$file'\n";
398        return;
399    }
400
401#   print "File: '$file', Path: '$path'\n";
402    print "Work in directory: $path\n";
403    my $newpath = $cwd . $FS . $path;
404#   print "chdir to $newpath\n";
405
406    my $error = chdir($newpath);
407    cwd();
408
409    # run through the hole makefile.mk and check if SHL<D>TARGET = ... exist, for every target call "dmake test<D>"
410
411    local *MAKEFILE_MK;
412    if (! open(MAKEFILE_MK, "makefile.mk"))
413    {
414        print "ERROR: can't open makefile.mk in path: $newpath\n";
415        print "please check your libs2test.txt file in qa directory.\n";
416    }
417    my $line;
418    my $nNumber;
419    my $sTarget;
420    my $sLocalParams;
421
422    while($line = <MAKEFILE_MK>)
423    {
424        chomp($line);
425
426        if ($line =~ /SHL(\d)TARGET=(.*)/)
427        {
428            $nNumber = $1;
429            $sTarget = trim($2);
430
431            # DBG: print "test$number is lib: $target\n";
432            $sLocalParams = $params . " ";                  # append a whitespace, so we can check if 'test' exist without additional digits
433            $sLocalParams =~ s/test\s/test$nNumber/;
434            # DBG: print "$sLocalParams\n";
435            if ($bBuildAll == 1 ||
436                $file eq $sTarget)
437            {
438                # print "runASingleTest on Target: $sTarget 'dmake $sLocalParams'\n";
439                runASingleTest($sTarget, $sLocalParams);
440            }
441            else
442            {
443                # printOnLibrary($sTarget);
444                # print " suppressed, not in libs2test.txt\n";
445            }
446        }
447    }
448    close(MAKEFILE_MK);
449}
450
451# ------------------------------------------------------------------------------
452
453sub main($)
454{
455    my $params = shift;
456#    my $sLogFile = shift;     # "buildall_$$.out";
457    local *LIBS2TEST;
458    my $filename = "libs2test.txt";
459    my $line;
460
461    open(LIBS2TEST, $filename) || die "can't open $filename\n";
462
463    while($line = <LIBS2TEST>)
464    {
465        chomp($line);
466        # DOS Hack grrrr...
467        while ($line =~ /
468$/)
469        {
470            $line = substr($line, 0, -1);
471        }
472
473        # print "$line\n";
474        my $path;
475        my $file;
476        ($path, $file) = interpretLine($line);
477        runTestsOnPath($path, $file, $params);
478    }
479    close(LIBS2TEST);
480
481    print "\nComplete logging information will be found in dir: ".$g_sTempDir."dmake_out_$$/\n";
482
483    if ($nGlobalFailures > 0)
484    {
485        print "\nFailures over all occured: $nGlobalFailures\n";
486        print "\nPASSED FAILED.\n";
487    }
488    else
489    {
490        print "\nPASSED OK.\n";
491    }
492}
493
494# ------------------------------------------------------------------------------
495
496# TODO:
497# -verbose
498# -fan   - \ | /
499
500# END!
501
502