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