NNT: Remove -debug argument, it is unused.
[oota-llvm.git] / utils / NewNightlyTest.pl
1 #!/usr/bin/perl
2 use POSIX qw(strftime);
3 use File::Copy;
4 use File::Find;
5 use Socket;
6
7 #
8 # Program:  NewNightlyTest.pl
9 #
10 # Synopsis: Perform a series of tests which are designed to be run nightly.
11 #           This is used to keep track of the status of the LLVM tree, tracking
12 #           regressions and performance changes. Submits this information
13 #           to llvm.org where it is placed into the nightlytestresults database.
14 #
15 # Syntax:   NightlyTest.pl [OPTIONS] [CVSROOT BUILDDIR WEBDIR]
16 #   where
17 # OPTIONS may include one or more of the following:
18 #
19 # MAIN OPTIONS:
20 #  -config LLVMPATH If specified, use an existing LLVM build and only run and
21 #                   report the test information. The LLVMCONFIG argument should
22 #                   be the path to the llvm-config executable in the LLVM build.
23 #                   This should be the first argument if given. NOT YET
24 #                   IMPLEMENTED.
25 #  -nickname NAME   The NAME argument specifieds the nickname this script
26 #                   will submit to the nightlytest results repository.
27 #  -submit-server   Specifies a server to submit the test results too. If this
28 #                   option is not specified it defaults to
29 #                   llvm.org. This is basically just the address of the
30 #                   webserver
31 #  -submit-script   Specifies which script to call on the submit server. If
32 #                   this option is not specified it defaults to
33 #                   /nightlytest/NightlyTestAccept.php. This is basically
34 #                   everything after the www.yourserver.org.
35 #  -submit-aux      If specified, an auxiliary script to run in addition to the
36 #                   normal submit script. The script will be passed the path to
37 #                   the "sentdata.txt" file as its sole argument.
38 #  -nosubmit        Do not report the test results back to a submit server.
39 #
40 #
41 # BUILD OPTIONS (not used with -config):
42 #  -nocheckout      Do not create, checkout, update, or configure
43 #                   the source tree.
44 #  -noremove        Do not remove the BUILDDIR after it has been built.
45 #  -noremoveresults Do not remove the WEBDIR after it has been built.
46 #  -nobuild         Do not build llvm. If tests are enabled perform them
47 #                   on the llvm build specified in the build directory
48 #  -release         Build an LLVM Release version
49 #  -release-asserts Build an LLVM ReleaseAsserts version
50 #  -disable-bindings     Disable building LLVM bindings.
51 #  -cvstag          Check out a specific CVS tag to build LLVM (useful for
52 #                   testing release branches)
53 #  -usecvs          Check code out from the (old) CVS Repository instead of from
54 #                   the standard Subversion repository.
55 #  -with-clang      Checkout Clang source into tools/clang.
56 #  -compileflags    Next argument specifies extra options passed to make when
57 #                   building LLVM.
58 #  -use-gmake       Use gmake instead of the default make command to build
59 #                   llvm and run tests.
60 #
61 # TESTING OPTIONS:
62 #  -notest          Do not even attempt to run the test programs.
63 #  -nodejagnu       Do not run feature or regression tests
64 #  -enable-llcbeta  Enable testing of beta features in llc.
65 #  -enable-lli      Enable testing of lli (interpreter) features, default is off
66 #  -disable-pic     Disable building with Position Independent Code.
67 #  -disable-llc     Disable LLC tests in the nightly tester.
68 #  -disable-jit     Disable JIT tests in the nightly tester.
69 #  -disable-cbe     Disable C backend tests in the nightly tester.
70 #  -disable-lto     Disable link time optimization.
71 #  -test-cflags     Next argument specifies that C compilation options that
72 #                   override the default when running the testsuite.
73 #  -test-cxxflags   Next argument specifies that C++ compilation options that
74 #                   override the default when running the testsuite.
75 #  -extraflags      Next argument specifies extra options that are passed to
76 #                   compile the tests.
77 #  -noexternals     Do not run the external tests (for cases where povray
78 #                   or SPEC are not installed)
79 #  -with-externals  Specify a directory where the external tests are located.
80 #
81 # OTHER OPTIONS:
82 #  -parallel        Run parallel jobs with GNU Make (see -parallel-jobs).
83 #  -parallel-jobs   The number of parallel Make jobs to use (default is two).
84 #  -verbose         Turn on some debug output
85 #  -nice            Checkout/Configure/Build with "nice" to reduce impact
86 #                   on busy servers.
87 #  -f2c             Next argument specifies path to F2C utility
88 #  -gccpath         Path to gcc/g++ used to build LLVM
89 #  -target          Specify the target triplet
90 #  -cflags          Next argument specifies that C compilation options that
91 #                   override the default.
92 #  -cxxflags        Next argument specifies that C++ compilation options that
93 #                   override the default.
94 #  -ldflags         Next argument specifies that linker options that override
95 #                   the default.
96 #
97 # CVSROOT is the CVS repository from which the tree will be checked out,
98 #  specified either in the full :method:user@host:/dir syntax, or
99 #  just /dir if using a local repo.
100 # BUILDDIR is the directory where sources for this test run will be checked out
101 #  AND objects for this test run will be built. This directory MUST NOT
102 #  exist before the script is run; it will be created by the cvs checkout
103 #  process and erased (unless -noremove is specified; see above.)
104 # WEBDIR is the directory into which the test results web page will be written,
105 #  AND in which the "index.html" is assumed to be a symlink to the most recent
106 #  copy of the results. This directory will be created if it does not exist.
107 # LLVMGCCDIR is the directory in which the LLVM GCC Front End is installed
108 #  to. This is the same as you would have for a normal LLVM build.
109 #
110 ##############################################################
111 #
112 # Getting environment variables
113 #
114 ##############################################################
115 my $HOME       = $ENV{'HOME'};
116 my $SVNURL     = $ENV{"SVNURL"};
117 $SVNURL        = 'http://llvm.org/svn/llvm-project' unless $SVNURL;
118 my $TestSVNURL = $ENV{"TestSVNURL"};
119 $TestSVNURL    = 'http://llvm.org/svn/llvm-project' unless $TestSVNURL;
120 my $CVSRootDir = $ENV{'CVSROOT'};
121 $CVSRootDir    = "/home/vadve/shared/PublicCVS" unless $CVSRootDir;
122 my $BuildDir   = $ENV{'BUILDDIR'};
123 $BuildDir      = "$HOME/buildtest" unless $BuildDir;
124 my $WebDir     = $ENV{'WEBDIR'};
125 $WebDir        = "$HOME/cvs/testresults-X86" unless $WebDir;
126
127 my $LLVMSrcDir   = $ENV{'LLVMSRCDIR'};
128 $LLVMSrcDir    = "$BuildDir/llvm" unless $LLVMSrcDir;
129 my $LLVMObjDir   = $ENV{'LLVMOBJDIR'};
130 $LLVMObjDir    = "$BuildDir/llvm" unless $LLVMObjDir;
131 my $LLVMTestDir   = $ENV{'LLVMTESTDIR'};
132 $LLVMTestDir    = "$BuildDir/llvm/projects/llvm-test" unless $LLVMTestDir;
133
134 ##############################################################
135 #
136 # Calculate the date prefix...
137 #
138 ##############################################################
139 @TIME = localtime;
140 my $DATE = sprintf "%4d-%02d-%02d_%02d-%02d", $TIME[5]+1900, $TIME[4]+1, $TIME[3], $TIME[1], $TIME[0];
141
142 ##############################################################
143 #
144 # Parse arguments...
145 #
146 ##############################################################
147 $CONFIG_PATH="";
148 $CONFIGUREARGS="";
149 $nickname="";
150 $NOTEST=0;
151 $USESVN=1;
152 $MAKECMD="make";
153 $SUBMITSERVER = "llvm.org";
154 $SUBMITSCRIPT = "/nightlytest/NightlyTestAccept.php";
155 $SUBMITAUX="";
156 $SUBMIT = 1;
157 $PARALLELJOBS = "2";
158 my $TESTFLAGS="";
159
160 while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
161   shift;
162   last if /^--$/;  # Stop processing arguments on --
163
164   # List command line options here...
165   if (/^-config$/)         { $CONFIG_PATH = "$ARGV[0]"; shift; next; }
166   if (/^-nocheckout$/)     { $NOCHECKOUT = 1; next; }
167   if (/^-nocvsstats$/)     { $NOCVSSTATS = 1; next; }
168   if (/^-noremove$/)       { $NOREMOVE = 1; next; }
169   if (/^-noremoveatend$/)  { $NOREMOVEATEND = 1; next; }
170   if (/^-noremoveresults$/){ $NOREMOVERESULTS = 1; next; }
171   if (/^-notest$/)         { $NOTEST = 1; next; }
172   if (/^-norunningtests$/) { next; } # Backward compatibility, ignored.
173   if (/^-parallel-jobs$/)  { $PARALLELJOBS = "$ARGV[0]"; shift; next;}
174   if (/^-parallel$/)       { $MAKEOPTS = "$MAKEOPTS -j$PARALLELJOBS -l3.0"; next; }
175   if (/^-with-clang$/)     { $WITHCLANG = 1; next; }
176   if (/^-release$/)        { $MAKEOPTS = "$MAKEOPTS ENABLE_OPTIMIZED=1 ".
177                              "OPTIMIZE_OPTION=-O2"; $BUILDTYPE="release"; next;}
178   if (/^-release-asserts$/){ $MAKEOPTS = "$MAKEOPTS ENABLE_OPTIMIZED=1 ".
179                              "DISABLE_ASSERTIONS=1 ".
180                              "OPTIMIZE_OPTION=-O2";
181                              $BUILDTYPE="release-asserts"; next;}
182   if (/^-enable-llcbeta$/) { $PROGTESTOPTS .= " ENABLE_LLCBETA=1"; next; }
183   if (/^-disable-pic$/)    { $CONFIGUREARGS .= " --enable-pic=no"; next; }
184   if (/^-enable-lli$/)     { $PROGTESTOPTS .= " ENABLE_LLI=1";
185                              $CONFIGUREARGS .= " --enable-lli"; next; }
186   if (/^-disable-llc$/)    { $PROGTESTOPTS .= " DISABLE_LLC=1";
187                              $CONFIGUREARGS .= " --disable-llc_diffs"; next; }
188   if (/^-disable-jit$/)    { $PROGTESTOPTS .= " DISABLE_JIT=1";
189                              $CONFIGUREARGS .= " --disable-jit"; next; }
190   if (/^-disable-bindings$/)    { $CONFIGUREARGS .= " --disable-bindings"; next; }
191   if (/^-disable-cbe$/)    { $PROGTESTOPTS .= " DISABLE_CBE=1"; next; }
192   if (/^-disable-lto$/)    { $PROGTESTOPTS .= " DISABLE_LTO=1"; next; }
193   if (/^-test-opts$/)      { $PROGTESTOPTS .= " $ARGV[0]"; shift; next; }
194   if (/^-verbose$/)        { $VERBOSE = 1; next; }
195   if (/^-teelogs$/)        { $TEELOGS = 1; next; }
196   if (/^-nice$/)           { $NICE = "nice "; next; }
197   if (/^-f2c$/)            { $CONFIGUREARGS .= " --with-f2c=$ARGV[0]";
198                              shift; next; }
199   if (/^-with-externals$/) { $CONFIGUREARGS .= " --with-externals=$ARGV[0]";
200                              shift; next; }
201   if (/^-configure-args$/) { $CONFIGUREARGS .= " $ARGV[0]";
202                              shift; next; }
203   if (/^-submit-server/)   { $SUBMITSERVER = "$ARGV[0]"; shift; next; }
204   if (/^-submit-script/)   { $SUBMITSCRIPT = "$ARGV[0]"; shift; next; }
205   if (/^-submit-aux/)      { $SUBMITAUX = "$ARGV[0]"; shift; next; }
206   if (/^-nosubmit$/)       { $SUBMIT = 0; next; }
207   if (/^-nickname$/)       { $nickname = "$ARGV[0]"; shift; next; }
208   if (/^-gccpath/)         { $CONFIGUREARGS .=
209                              " CC=$ARGV[0]/gcc CXX=$ARGV[0]/g++";
210                              $GCCPATH=$ARGV[0]; shift;  next; }
211   else                     { $GCCPATH=""; }
212   if (/^-cvstag/)          { $CVSCOOPT .= " -r $ARGV[0]"; shift; next; }
213   else                     { $CVSCOOPT="";}
214   if (/^-usecvs/)          { $USESVN = 0; }
215   if (/^-target/)          { $CONFIGUREARGS .= " --target=$ARGV[0]";
216                              shift; next; }
217   if (/^-cflags/)          { $MAKEOPTS = "$MAKEOPTS C.Flags=\'$ARGV[0]\'";
218                              shift; next; }
219   if (/^-cxxflags/)        { $MAKEOPTS = "$MAKEOPTS CXX.Flags=\'$ARGV[0]\'";
220                              shift; next; }
221   if (/^-ldflags/)         { $MAKEOPTS = "$MAKEOPTS LD.Flags=\'$ARGV[0]\'";
222                              shift; next; }
223   if (/^-test-cflags/)     { $TESTFLAGS = "$TESTFLAGS CFLAGS=\'$ARGV[0]\'";
224                              shift; next; }
225   if (/^-test-cxxflags/)   { $TESTFLAGS = "$TESTFLAGS CXXFLAGS=\'$ARGV[0]\'";
226                              shift; next; }
227   if (/^-compileflags/)    { $MAKEOPTS = "$MAKEOPTS $ARGV[0]"; shift; next; }
228   if (/^-use-gmake/)       { $MAKECMD = "gmake"; shift; next; }
229   if (/^-extraflags/)      { $CONFIGUREARGS .=
230                              " --with-extra-options=\'$ARGV[0]\'"; shift; next;}
231   if (/^-noexternals$/)    { $NOEXTERNALS = 1; next; }
232   if (/^-nodejagnu$/)      { $NODEJAGNU = 1; next; }
233   if (/^-nobuild$/)        { $NOBUILD = 1; next; }
234   print "Unknown option: $_ : ignoring!\n";
235 }
236
237 if (!($CONFIG_PATH eq "")) {
238   die "error: -config mode is not yet implemented,";
239 }
240
241 if ($ENV{'LLVMGCCDIR'}) {
242   $CONFIGUREARGS .= " --with-llvmgccdir=" . $ENV{'LLVMGCCDIR'};
243   $LLVMGCCPATH = $ENV{'LLVMGCCDIR'} . '/bin';
244 }
245 else {
246   $LLVMGCCPATH = "";
247 }
248
249 if ($CONFIGUREARGS !~ /--disable-jit/) {
250   $CONFIGUREARGS .= " --enable-jit";
251 }
252
253 if (@ARGV != 0 and @ARGV != 3 and $VERBOSE) {
254   foreach $x (@ARGV) {
255     print "$x\n";
256   }
257   print "Must specify 0 or 3 options!";
258 }
259
260 if (@ARGV == 3) {
261   $CVSRootDir = $ARGV[0];
262   $BuildDir   = $ARGV[1];
263   $WebDir     = $ARGV[2];
264 }
265
266 if ($CVSRootDir eq "" or
267     $BuildDir   eq "" or
268     $WebDir     eq "") {
269   die("please specify a cvs root directory, a build directory, and a ".
270        "web directory");
271  }
272
273 if ($nickname eq "") {
274   die ("Please invoke NewNightlyTest.pl with command line option " .
275        "\"-nickname <nickname>\"");
276 }
277
278 if ($BUILDTYPE ne "release" && $BUILDTYPE ne "release-asserts") {
279   $BUILDTYPE = "debug";
280 }
281
282 ##############################################################
283 #
284 # Define the file names we'll use
285 #
286 ##############################################################
287 my $Prefix = "$WebDir/$DATE";
288 my $BuildLog = "$Prefix-Build-Log.txt";
289 my $COLog = "$Prefix-CVS-Log.txt";
290 my $SingleSourceLog = "$Prefix-SingleSource-ProgramTest.txt.gz";
291 my $MultiSourceLog = "$Prefix-MultiSource-ProgramTest.txt.gz";
292 my $ExternalLog = "$Prefix-External-ProgramTest.txt.gz";
293 my $DejagnuLog = "$Prefix-Dejagnu-testrun.log";
294 my $DejagnuSum = "$Prefix-Dejagnu-testrun.sum";
295 my $DejagnuTestsLog = "$Prefix-DejagnuTests-Log.txt";
296 if (! -d $WebDir) {
297   mkdir $WebDir, 0777;
298   if($VERBOSE){
299     warn "$WebDir did not exist; creating it.\n";
300   }
301 }
302
303 if ($VERBOSE) {
304   print "INITIALIZED\n";
305   if ($USESVN) {
306     print "SVN URL  = $SVNURL\n";
307   } else {
308     print "CVS Root = $CVSRootDir\n";
309   }
310   print "COLog    = $COLog\n";
311   print "BuildDir = $BuildDir\n";
312   print "WebDir   = $WebDir\n";
313   print "Prefix   = $Prefix\n";
314   print "BuildLog = $BuildLog\n";
315 }
316
317 ##############################################################
318 #
319 # Helper functions
320 #
321 ##############################################################
322
323 sub GetDir {
324   my $Suffix = shift;
325   opendir DH, $WebDir;
326   my @Result = reverse sort grep !/$DATE/, grep /[-0-9]+$Suffix/, readdir DH;
327   closedir DH;
328   return @Result;
329 }
330
331 sub RunLoggedCommand {
332   my $Command = shift;
333   my $Log = shift;
334   my $Title = shift;
335   if ($TEELOGS) {
336       if ($VERBOSE) {
337           print "$Title\n";
338           print "$Command 2>&1 | tee $Log\n";
339       }
340       system "$Command 2>&1 | tee $Log";
341   } else {
342       if ($VERBOSE) {
343           print "$Title\n";
344           print "$Command 2>&1 > $Log\n";
345       }
346       system "$Command 2>&1 > $Log";
347   }
348 }
349
350 sub RunAppendingLoggedCommand {
351   my $Command = shift;
352   my $Log = shift;
353   my $Title = shift;
354   if ($TEELOGS) {
355       if ($VERBOSE) {
356           print "$Title\n";
357           print "$Command 2>&1 | tee -a $Log\n";
358       }
359       system "$Command 2>&1 | tee -a $Log";
360   } else {
361       if ($VERBOSE) {
362           print "$Title\n";
363           print "$Command 2>&1 > $Log\n";
364       }
365       system "$Command 2>&1 >> $Log";
366   }
367 }
368
369 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
370 #
371 # DiffFiles - Diff the current version of the file against the last version of
372 # the file, reporting things added and removed.  This is used to report, for
373 # example, added and removed warnings.  This returns a pair (added, removed)
374 #
375 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
376 sub DiffFiles {
377   my $Suffix = shift;
378   my @Others = GetDir $Suffix;
379   if (@Others == 0) {  # No other files?  We added all entries...
380     return (`cat $WebDir/$DATE$Suffix`, "");
381   }
382 # Diff the files now...
383   my @Diffs = split "\n", `diff $WebDir/$DATE$Suffix $WebDir/$Others[0]`;
384   my $Added   = join "\n", grep /^</, @Diffs;
385   my $Removed = join "\n", grep /^>/, @Diffs;
386   $Added =~ s/^< //gm;
387   $Removed =~ s/^> //gm;
388   return ($Added, $Removed);
389 }
390
391 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
392 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
393 sub GetRegex {   # (Regex with ()'s, value)
394   $_[1] =~ /$_[0]/m;
395   return $1
396     if (defined($1));
397   return "0";
398 }
399
400 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
401 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
402 sub GetRegexNum {
403   my ($Regex, $Num, $Regex2, $File) = @_;
404   my @Items = split "\n", `grep '$Regex' $File`;
405   return GetRegex $Regex2, $Items[$Num];
406 }
407
408 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
409 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
410 sub ChangeDir { # directory, logical name
411   my ($dir,$name) = @_;
412   chomp($dir);
413   if ( $VERBOSE ) { print "Changing To: $name ($dir)\n"; }
414   $result = chdir($dir);
415   if (!$result) {
416     print "ERROR!!! Cannot change directory to: $name ($dir) because $!";
417     return false;
418   }
419   return true;
420 }
421
422 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
423 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
424 sub ReadFile {
425   if (open (FILE, $_[0])) {
426     undef $/;
427     my $Ret = <FILE>;
428     close FILE;
429     $/ = '\n';
430     return $Ret;
431   } else {
432     print "Could not open file '$_[0]' for reading!\n";
433     return "";
434   }
435 }
436
437 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
438 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
439 sub WriteFile {  # (filename, contents)
440   open (FILE, ">$_[0]") or die "Could not open file '$_[0]' for writing!\n";
441   print FILE $_[1];
442   close FILE;
443 }
444
445 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
446 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
447 sub CopyFile { #filename, newfile
448   my ($file, $newfile) = @_;
449   chomp($file);
450   if ($VERBOSE) { print "Copying $file to $newfile\n"; }
451   copy($file, $newfile);
452 }
453
454 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
455 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
456 sub AddRecord {
457   my ($Val, $Filename,$WebDir) = @_;
458   my @Records;
459   if (open FILE, "$WebDir/$Filename") {
460     @Records = grep !/$DATE/, split "\n", <FILE>;
461     close FILE;
462   }
463   push @Records, "$DATE: $Val";
464   WriteFile "$WebDir/$Filename", (join "\n", @Records) . "\n";
465 }
466
467 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
468 #
469 # FormatTime - Convert a time from 1m23.45 into 83.45
470 #
471 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
472 sub FormatTime {
473   my $Time = shift;
474   if ($Time =~ m/([0-9]+)m([0-9.]+)/) {
475     $Time = sprintf("%7.4f", $1*60.0+$2);
476   }
477   return $Time;
478 }
479
480 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
481 #
482 # This function is meant to read in the dejagnu sum file and
483 # return a string with only the results (i.e. PASS/FAIL/XPASS/
484 # XFAIL).
485 #
486 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
487 sub GetDejagnuTestResults { # (filename, log)
488     my ($filename, $DejagnuLog) = @_;
489     my @lines;
490     $/ = "\n"; #Make sure we're going line at a time.
491
492     if( $VERBOSE) { print "DEJAGNU TEST RESULTS:\n"; }
493
494     if (open SRCHFILE, $filename) {
495         # Process test results
496         while ( <SRCHFILE> ) {
497             if ( length($_) > 1 ) {
498                 chomp($_);
499                 if ( m/^(PASS|XPASS|FAIL|XFAIL): .*\/llvm\/test\/(.*)$/ ) {
500                     push(@lines, "$1: test/$2");
501                 }
502             }
503         }
504     }
505     close SRCHFILE;
506
507     my $content = join("\n", @lines);
508     return $content;
509 }
510
511
512
513 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
514 #
515 # This function acts as a mini web browswer submitting data
516 # to our central server via the post method
517 #
518 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
519 sub SendData {
520     $host = $_[0];
521     $file = $_[1];
522     $variables = $_[2];
523
524     # Write out the "...-sentdata.txt" file.
525
526     my $sentdata="";
527     foreach $x (keys (%$variables)){
528         $value = $variables->{$x};
529         $sentdata.= "$x  => $value\n";
530     }
531     WriteFile "$Prefix-sentdata.txt", $sentdata;
532
533     if (!($SUBMITAUX eq "")) {
534         system "$SUBMITAUX \"$Prefix-sentdata.txt\"";
535     }
536
537     if (!$SUBMIT) {
538         return "Skipped standard submit.\n";
539     }
540
541     # Create the content to send to the server.
542
543     my $content;
544     foreach $key (keys (%$variables)){
545         $value = $variables->{$key};
546         $value =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
547         $content .= "$key=$value&";
548     }
549
550     # Send the data to the server.
551     #
552     # FIXME: This code should be more robust?
553
554     $port=80;
555     $socketaddr= sockaddr_in $port, inet_aton $host or die "Bad hostname\n";
556     socket SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp') or
557       die "Bad socket\n";
558     connect SOCK, $socketaddr or die "Bad connection\n";
559     select((select(SOCK), $| = 1)[0]);
560
561     $length = length($content);
562
563     my $send= "POST $file HTTP/1.0\n";
564     $send.= "Host: $host\n";
565     $send.= "Content-Type: application/x-www-form-urlencoded\n";
566     $send.= "Content-length: $length\n\n";
567     $send.= "$content";
568
569     print SOCK $send;
570     my $result;
571     while(<SOCK>){
572         $result  .= $_;
573     }
574     close(SOCK);
575
576     return $result;
577 }
578
579 ##############################################################
580 #
581 # Getting Start timestamp
582 #
583 ##############################################################
584 $starttime = `date "+20%y-%m-%d %H:%M:%S"`;
585
586 ##############################################################
587 #
588 # Create the CVS repository directory
589 #
590 ##############################################################
591 if (!$NOCHECKOUT) {
592   if (-d $BuildDir) {
593     if (!$NOREMOVE) {
594       if ( $VERBOSE ) {
595         print "Build directory exists! Removing it\n";
596       }
597       system "rm -rf $BuildDir";
598       mkdir $BuildDir or die "Could not create checkout directory $BuildDir!";
599     } else {
600       if ( $VERBOSE ) {
601         print "Build directory exists!\n";
602       }
603     }
604   } else {
605     mkdir $BuildDir or die "Could not create checkout directory $BuildDir!";
606   }
607 }
608
609
610 ##############################################################
611 #
612 # Check out the llvm tree, using either SVN or CVS
613 #
614 ##############################################################
615 if (!$NOCHECKOUT) {
616   ChangeDir( $BuildDir, "checkout directory" );
617   if ($USESVN) {
618       my $SVNCMD = "$NICE svn co --non-interactive $SVNURL";
619       my $SVNCMD2 = "$NICE svn co --non-interactive $TestSVNURL";
620       RunLoggedCommand("( time -p $SVNCMD/llvm/trunk llvm; cd llvm/projects ; " .
621                        "$SVNCMD2/test-suite/trunk llvm-test )", $COLog,
622                        "CHECKOUT LLVM");
623       if ($WITHCLANG) {
624         my $SVNCMD = "$NICE svn co --non-interactive $SVNURL/cfe/trunk";
625         RunLoggedCommand("( time -p cd llvm/tools ; $SVNCMD clang )", $COLog,
626                          "CHECKOUT CLANG");
627       }
628   } else {
629     my $CVSOPT = "";
630     $CVSOPT = "-z3" # Use compression if going over ssh.
631       if $CVSRootDir =~ /^:ext:/;
632     my $CVSCMD = "$NICE cvs $CVSOPT -d $CVSRootDir co -P $CVSCOOPT";
633     RunLoggedCommand("( time -p $CVSCMD llvm; cd llvm/projects ; " .
634                      "$CVSCMD llvm-test )", $COLog,
635                      "CHECKOUT LLVM-TEST");
636   }
637 }
638 ChangeDir( $LLVMSrcDir , "llvm source directory") ;
639
640 ##############################################################
641 #
642 # Get some static statistics about the current state of CVS
643 #
644 # This can probably be put on the server side
645 #
646 ##############################################################
647 my $CheckoutTime_Wall = GetRegex "([0-9.]+)", `grep '^real' $COLog`;
648 my $CheckoutTime_User = GetRegex "([0-9.]+)", `grep '^user' $COLog`;
649 my $CheckoutTime_Sys = GetRegex "([0-9.]+)", `grep '^sys' $COLog`;
650 my $CheckoutTime_CPU = $CVSCheckoutTime_User + $CVSCheckoutTime_Sys;
651
652 my $NumFilesInCVS = 0;
653 my $NumDirsInCVS  = 0;
654 if ($USESVN) {
655   $NumFilesInCVS = `egrep '^A' $COLog | wc -l` + 0;
656   $NumDirsInCVS  = `sed -e 's#/[^/]*\$##' $COLog | sort | uniq | wc -l` + 0;
657 } else {
658   $NumFilesInCVS = `egrep '^U' $COLog | wc -l` + 0;
659   $NumDirsInCVS  = `egrep '^cvs (checkout|server|update):' $COLog | wc -l` + 0;
660 }
661
662 ##############################################################
663 #
664 # Extract some information from the CVS history... use a hash so no duplicate
665 # stuff is stored. This gets the history from the previous days worth
666 # of cvs activity and parses it.
667 #
668 ##############################################################
669
670 # This just computes a reasonably accurate #of seconds since 2000. It doesn't
671 # have to be perfect as its only used for comparing date ranges within a couple
672 # of days.
673 sub ConvertToSeconds {
674   my ($sec, $min, $hour, $day, $mon, $yr) = @_;
675   my $Result = ($yr - 2000) * 12;
676   $Result += $mon;
677   $Result *= 31;
678   $Result += $day;
679   $Result *= 24;
680   $Result += $hour;
681   $Result *= 60;
682   $Result += $min;
683   $Result *= 60;
684   $Result += $sec;
685   return $Result;
686 }
687
688 my (%AddedFiles, %ModifiedFiles, %RemovedFiles, %UsersCommitted, %UsersUpdated);
689
690 if (!$NOCVSSTATS) {
691   if ($VERBOSE) { print "CHANGE HISTORY ANALYSIS STAGE\n"; }
692
693   if ($USESVN) {
694     @SVNHistory = split /<logentry/, `svn log --non-interactive --xml --verbose -r{$DATE}:HEAD`;
695     # Skip very first entry because it is the XML header cruft
696     shift @SVNHistory;
697     my $Now = time();
698     foreach $Record (@SVNHistory) {
699       my @Lines = split "\n", $Record;
700       my ($Author, $Date, $Revision);
701       # Get the date and see if its one we want to process.
702       my ($Year, $Month, $Day, $Hour, $Min, $Sec);
703       if ($Lines[3] =~ /<date>(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/){
704         $Year = $1; $Month = $2; $Day = $3; $Hour = $4; $Min = $5; $Sec = $6;
705       }
706       my $Then = ConvertToSeconds($Sec, $Min, $Hour, $Day, $Month, $Year);
707       # Get the current date and compute when "yesterday" is.
708       my ($NSec, $NMin, $NHour, $NDay, $NMon, $NYear) = gmtime();
709       my $Now = ConvertToSeconds( $NSec, $NMin, $NHour, $NDay, $NMon, $NYear);
710       if (($Now - 24*60*60) > $Then) {
711         next;
712       }
713       if ($Lines[1] =~ /   revision="([0-9]*)">/) {
714         $Revision = $1;
715       }
716       if ($Lines[2] =~ /<author>([^<]*)<\/author>/) {
717         $Author = $1;
718       }
719       $UsersCommitted{$Author} = 1;
720       $Date = $Year . "-" . $Month . "-" . $Day;
721       $Time = $Hour . ":" . $Min . ":" . $Sec;
722       print "Rev: $Revision, Author: $Author, Date: $Date, Time: $Time\n";
723       for ($i = 6; $i < $#Lines; $i += 2 ) {
724         if ($Lines[$i] =~ /^   action="(.)">([^<]*)</) {
725           if ($1 == "A") {
726             $AddedFiles{$2} = 1;
727           } elsif ($1 == 'D') {
728             $RemovedFiles{$2} = 1;
729           } elsif ($1 == 'M' || $1 == 'R' || $1 == 'C') {
730             $ModifiedFiles{$2} = 1;
731           } else {
732             print "UNMATCHABLE: $Lines[$i]\n";
733           }
734         }
735       }
736     }
737   } else {
738     @CVSHistory = split "\n", `cvs history -D '1 day ago' -a -xAMROCGUW`;
739 #print join "\n", @CVSHistory; print "\n";
740
741     my $DateRE = '[-/:0-9 ]+\+[0-9]+';
742
743 # Loop over every record from the CVS history, filling in the hashes.
744     foreach $File (@CVSHistory) {
745         my ($Type, $Date, $UID, $Rev, $Filename);
746         if ($File =~ /([AMRUGC]) ($DateRE) ([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+)/) {
747             ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, $4, "$6/$5");
748         } elsif ($File =~ /([W]) ($DateRE) ([^ ]+)/) {
749             ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", "");
750         } elsif ($File =~ /([O]) ($DateRE) ([^ ]+) +([^ ]+)/) {
751             ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", "$4/");
752         } else {
753             print "UNMATCHABLE: $File\n";
754             next;
755         }
756         # print "$File\nTy = $Type Date = '$Date' UID=$UID Rev=$Rev File = '$Filename'\n";
757
758         if ($Filename =~ /^llvm/) {
759             if ($Type eq 'M') {        # Modified
760                 $ModifiedFiles{$Filename} = 1;
761                 $UsersCommitted{$UID} = 1;
762             } elsif ($Type eq 'A') {   # Added
763                 $AddedFiles{$Filename} = 1;
764                 $UsersCommitted{$UID} = 1;
765             } elsif ($Type eq 'R') {   # Removed
766                 $RemovedFiles{$Filename} = 1;
767                 $UsersCommitted{$UID} = 1;
768             } else {
769                 $UsersUpdated{$UID} = 1;
770             }
771         }
772     }
773
774     my $TestError = 1;
775   } #$USESVN
776 }#!NOCVSSTATS
777
778 my $CVSAddedFiles = join "\n", sort keys %AddedFiles;
779 my $CVSModifiedFiles = join "\n", sort keys %ModifiedFiles;
780 my $CVSRemovedFiles = join "\n", sort keys %RemovedFiles;
781 my $UserCommitList = join "\n", sort keys %UsersCommitted;
782 my $UserUpdateList = join "\n", sort keys %UsersUpdated;
783
784 ##############################################################
785 #
786 # Build the entire tree, saving build messages to the build log
787 #
788 ##############################################################
789 if (!$NOCHECKOUT && !$NOBUILD) {
790   my $EXTRAFLAGS = "--enable-spec --with-objroot=.";
791   RunLoggedCommand("(time -p $NICE ./configure $CONFIGUREARGS $EXTRAFLAGS) ",
792                    $BuildLog, "CONFIGURE");
793   # Build the entire tree, capturing the output into $BuildLog
794   RunAppendingLoggedCommand("(time -p $NICE $MAKECMD clean)", $BuildLog, "BUILD CLEAN");
795   RunAppendingLoggedCommand("(time -p $NICE $MAKECMD $MAKEOPTS)", $BuildLog, "BUILD");
796 }
797
798 ##############################################################
799 #
800 # Get some statistics about the build...
801 #
802 ##############################################################
803 #this can de done on server
804 #my @Linked = split '\n', `grep Linking $BuildLog`;
805 #my $NumExecutables = scalar(grep(/executable/, @Linked));
806 #my $NumLibraries   = scalar(grep(!/executable/, @Linked));
807 #my $NumObjects     = `grep ']\: Compiling ' $BuildLog | wc -l` + 0;
808
809 # Get the number of lines of source code. Must be here after the build is done
810 # because countloc.sh uses the llvm-config script which must be built.
811 my $LOC = `utils/countloc.sh -topdir $LLVMSrcDir`;
812
813 # Get the time taken by the configure script
814 my $ConfigTimeU = GetRegexNum "^user", 0, "([0-9.]+)", "$BuildLog";
815 my $ConfigTimeS = GetRegexNum "^sys", 0, "([0-9.]+)", "$BuildLog";
816 my $ConfigTime  = $ConfigTimeU+$ConfigTimeS;  # ConfigTime = User+System
817 my $ConfigWallTime = GetRegexNum "^real", 0,"([0-9.]+)","$BuildLog";
818
819 $ConfigTime=-1 unless $ConfigTime;
820 $ConfigWallTime=-1 unless $ConfigWallTime;
821
822 my $BuildTimeU = GetRegexNum "^user", 1, "([0-9.]+)", "$BuildLog";
823 my $BuildTimeS = GetRegexNum "^sys", 1, "([0-9.]+)", "$BuildLog";
824 my $BuildTime  = $BuildTimeU+$BuildTimeS;  # BuildTime = User+System
825 my $BuildWallTime = GetRegexNum "^real", 1, "([0-9.]+)","$BuildLog";
826
827 $BuildTime=-1 unless $BuildTime;
828 $BuildWallTime=-1 unless $BuildWallTime;
829
830 my $BuildError = 0, $BuildStatus = "OK";
831 if ($NOBUILD) {
832   $BuildStatus = "Skipped by user";
833 }
834 elsif (`grep '^$MAKECMD\[^:]*: .*Error' $BuildLog | wc -l` + 0 ||
835   `grep '^$MAKECMD: \*\*\*.*Stop.' $BuildLog | wc -l`+0) {
836   $BuildStatus = "Error: compilation aborted";
837   $BuildError = 1;
838   if( $VERBOSE) { print  "\n***ERROR BUILDING TREE\n\n"; }
839 }
840 if ($BuildError) { $NODEJAGNU=1; }
841
842 my $a_file_sizes="";
843 my $o_file_sizes="";
844 if (!$BuildError) {
845   print "Organizing size of .o and .a files\n"
846     if ( $VERBOSE );
847   ChangeDir( "$LLVMObjDir", "Build Directory" );
848
849   my @dirs = ('utils', 'lib', 'tools');
850   if($BUILDTYPE eq "release"){
851     push @dirs, 'Release';
852   } elsif($BUILDTYPE eq "release-asserts") {
853     push @dirs, 'Release-Asserts';
854   } else {
855     push @dirs, 'Debug';
856   }
857
858   find(sub {
859       $a_file_sizes .= (-s $_)." $File::Find::name $BUILDTYPE\n" if /\.a$/i;
860       $o_file_sizes .= (-s $_)." $File::Find::name $BUILDTYPE\n" if /\.o$/i;
861     }, @dirs);
862 } else {
863   $a_file_sizes="No data due to a bad build.";
864   $o_file_sizes="No data due to a bad build.";
865 }
866
867 ##############################################################
868 #
869 # Running dejagnu tests
870 #
871 ##############################################################
872 my $DejangnuTestResults=""; # String containing the results of the dejagnu
873 my $dejagnu_output = "$DejagnuTestsLog";
874 if (!$NODEJAGNU) {
875   #Run the feature and regression tests, results are put into testrun.sum
876   #Full log in testrun.log
877   RunLoggedCommand("(time -p $MAKECMD $MAKEOPTS check)", $dejagnu_output, "DEJAGNU");
878
879   #Copy the testrun.log and testrun.sum to our webdir
880   CopyFile("test/testrun.log", $DejagnuLog);
881   CopyFile("test/testrun.sum", $DejagnuSum);
882   #can be done on server
883   $DejagnuTestResults = GetDejagnuTestResults($DejagnuSum, $DejagnuLog);
884   $unexpfail_tests = $DejagnuTestResults;
885 }
886
887 #Extract time of dejagnu tests
888 my $DejagnuTimeU = GetRegexNum "^user", 0, "([0-9.]+)", "$dejagnu_output";
889 my $DejagnuTimeS = GetRegexNum "^sys", 0, "([0-9.]+)", "$dejagnu_output";
890 $DejagnuTime  = $DejagnuTimeU+$DejagnuTimeS;  # DejagnuTime = User+System
891 $DejagnuWallTime = GetRegexNum "^real", 0,"([0-9.]+)","$dejagnu_output";
892 $DejagnuTestResults =
893   "Dejagnu skipped by user choice." unless $DejagnuTestResults;
894 $DejagnuTime     = "0.0" unless $DejagnuTime;
895 $DejagnuWallTime = "0.0" unless $DejagnuWallTime;
896
897 ##############################################################
898 #
899 # Get warnings from the build
900 #
901 ##############################################################
902 if (!$NODEJAGNU) {
903   if ( $VERBOSE ) { print "BUILD INFORMATION COLLECTION STAGE\n"; }
904   my @Warn = split "\n", `egrep 'warning:|Entering dir' $BuildLog`;
905   my @Warnings;
906   my $CurDir = "";
907
908   foreach $Warning (@Warn) {
909     if ($Warning =~ m/Entering directory \`([^\`]+)\'/) {
910       $CurDir = $1;                 # Keep track of directory warning is in...
911       # Remove buildir prefix if included
912       if ($CurDir =~ m#$LLVMSrcDir/(.*)#) { $CurDir = $1; }
913     } else {
914       push @Warnings, "$CurDir/$Warning";     # Add directory to warning...
915     }
916   }
917   my $WarningsFile =  join "\n", @Warnings;
918   $WarningsFile =~ s/:[0-9]+:/::/g;
919
920   # Emit the warnings file, so we can diff...
921   WriteFile "$WebDir/$DATE-Warnings.txt", $WarningsFile . "\n";
922   my ($WarningsAdded, $WarningsRemoved) = DiffFiles "-Warnings.txt";
923
924   # Output something to stdout if something has changed
925   #print "ADDED   WARNINGS:\n$WarningsAdded\n\n" if (length $WarningsAdded);
926   #print "REMOVED WARNINGS:\n$WarningsRemoved\n\n" if (length $WarningsRemoved);
927
928   #my @TmpWarningsAdded = split "\n", $WarningsAdded; ~PJ on upgrade
929   #my @TmpWarningsRemoved = split "\n", $WarningsRemoved; ~PJ on upgrade
930
931 } #endif !NODEGAGNU
932
933 ##############################################################
934 #
935 # If we built the tree successfully, run the nightly programs tests...
936 #
937 # A set of tests to run is passed in (i.e. "SingleSource" "MultiSource"
938 # "External")
939 #
940 ##############################################################
941
942 sub TestDirectory {
943   my $SubDir = shift;
944   ChangeDir( "$LLVMTestDir/$SubDir",
945              "Programs Test Subdirectory" ) || return ("", "");
946
947   my $ProgramTestLog = "$Prefix-$SubDir-ProgramTest.txt";
948
949   # Run the programs tests... creating a report.nightly.csv file
950   if (!$NOTEST) {
951     if( $VERBOSE) {
952       print "$MAKECMD -k $MAKEOPTS $PROGTESTOPTS report.nightly.csv ".
953             "$TESTFLAGS TEST=nightly > $ProgramTestLog 2>&1\n";
954     }
955     RunLoggedCommand("$MAKECMD -k $MAKEOPTS $PROGTESTOPTS report.nightly.csv ".
956                      "$TESTFLAGS TEST=nightly",
957                      $ProgramTestLog, "TEST DIRECTORY $SubDir");
958     $llcbeta_options=`$MAKECMD print-llcbeta-option`;
959   }
960
961   my $ProgramsTable;
962   if (`grep '^$MAKECMD\[^:]: .*Error' $ProgramTestLog | wc -l` + 0) {
963     $TestError = 1;
964     $ProgramsTable="Error running test $SubDir\n";
965     print "ERROR TESTING\n";
966   } elsif (`grep '^$MAKECMD\[^:]: .*No rule to make target' $ProgramTestLog | wc -l` + 0) {
967     $TestError = 1;
968     $ProgramsTable="Makefile error running tests $SubDir!\n";
969     print "ERROR TESTING\n";
970   } else {
971     $TestError = 0;
972   #
973   # Create a list of the tests which were run...
974   #
975   system "egrep 'TEST-(PASS|FAIL)' < $ProgramTestLog ".
976          "| sort > $Prefix-$SubDir-Tests.txt";
977   }
978   $ProgramsTable = ReadFile "report.nightly.csv";
979
980   ChangeDir( "../../..", "Programs Test Parent Directory" );
981   return ($ProgramsTable, $llcbeta_options);
982 } #end sub TestDirectory
983
984 ##############################################################
985 #
986 # Calling sub TestDirectory
987 #
988 ##############################################################
989 if (!$BuildError) {
990   ($SingleSourceProgramsTable, $llcbeta_options) =
991     TestDirectory("SingleSource");
992   WriteFile "$Prefix-SingleSource-Performance.txt", $SingleSourceProgramsTable;
993   ($MultiSourceProgramsTable, $llcbeta_options) = TestDirectory("MultiSource");
994   WriteFile "$Prefix-MultiSource-Performance.txt", $MultiSourceProgramsTable;
995   if ( ! $NOEXTERNALS ) {
996     ($ExternalProgramsTable, $llcbeta_options) = TestDirectory("External");
997     WriteFile "$Prefix-External-Performance.txt", $ExternalProgramsTable;
998     system "cat $Prefix-SingleSource-Tests.txt " .
999                "$Prefix-MultiSource-Tests.txt ".
1000                "$Prefix-External-Tests.txt | sort > $Prefix-Tests.txt";
1001     system "cat $Prefix-SingleSource-Performance.txt " .
1002                "$Prefix-MultiSource-Performance.txt ".
1003                "$Prefix-External-Performance.txt | sort > $Prefix-Performance.txt";
1004   } else {
1005     $ExternalProgramsTable = "External TEST STAGE SKIPPED\n";
1006     if ( $VERBOSE ) {
1007       print "External TEST STAGE SKIPPED\n";
1008     }
1009     system "cat $Prefix-SingleSource-Tests.txt " .
1010                "$Prefix-MultiSource-Tests.txt ".
1011                " | sort > $Prefix-Tests.txt";
1012     system "cat $Prefix-SingleSource-Performance.txt " .
1013                "$Prefix-MultiSource-Performance.txt ".
1014                " | sort > $Prefix-Performance.txt";
1015   }
1016
1017   ##############################################################
1018   #
1019   #
1020   # gathering tests added removed broken information here
1021   #
1022   #
1023   ##############################################################
1024   my $dejagnu_test_list = ReadFile "$Prefix-Tests.txt";
1025   my @DEJAGNU = split "\n", $dejagnu_test_list;
1026   my ($passes, $fails, $xfails) = "";
1027
1028   if(!$NODEJAGNU) {
1029     for ($x=0; $x<@DEJAGNU; $x++) {
1030       if ($DEJAGNU[$x] =~ m/^PASS:/) {
1031         $passes.="$DEJAGNU[$x]\n";
1032       }
1033       elsif ($DEJAGNU[$x] =~ m/^FAIL:/) {
1034         $fails.="$DEJAGNU[$x]\n";
1035       }
1036       elsif ($DEJAGNU[$x] =~ m/^XFAIL:/) {
1037         $xfails.="$DEJAGNU[$x]\n";
1038       }
1039     }
1040   }
1041
1042 } #end if !$BuildError
1043
1044 ##############################################################
1045 #
1046 # Getting end timestamp
1047 #
1048 ##############################################################
1049 $endtime = `date "+20%y-%m-%d %H:%M:%S"`;
1050
1051
1052 ##############################################################
1053 #
1054 # Place all the logs neatly into one humungous file
1055 #
1056 ##############################################################
1057 if ( $VERBOSE ) { print "PREPARING LOGS TO BE SENT TO SERVER\n"; }
1058
1059 $machine_data = "uname: ".`uname -a`.
1060                 "hardware: ".`uname -m`.
1061                 "os: ".`uname -sr`.
1062                 "name: ".`uname -n`.
1063                 "date: ".`date \"+20%y-%m-%d\"`.
1064                 "time: ".`date +\"%H:%M:%S\"`;
1065
1066 my @CVS_DATA;
1067 my $cvs_data;
1068 @CVS_DATA = ReadFile "$COLog";
1069 $cvs_data = join("\n", @CVS_DATA);
1070
1071 my @BUILD_DATA;
1072 my $build_data;
1073 @BUILD_DATA = ReadFile "$BuildLog";
1074 $build_data = join("\n", @BUILD_DATA);
1075
1076 my (@DEJAGNU_LOG, @DEJAGNU_SUM, @DEJAGNULOG_FULL, @GCC_VERSION);
1077 my ($dejagnutests_log ,$dejagnutests_sum, $dejagnulog_full) = "";
1078 my ($gcc_version, $gcc_version_long) = "";
1079
1080 $gcc_version_long="";
1081 if ($GCCPATH ne "") {
1082         $gcc_version_long = `$GCCPATH/gcc --version`;
1083 } elsif ($ENV{"CC"}) {
1084         $gcc_version_long = `$ENV{"CC"} --version`;
1085 } else {
1086         $gcc_version_long = `gcc --version`;
1087 }
1088 @GCC_VERSION = split '\n', $gcc_version_long;
1089 $gcc_version = $GCC_VERSION[0];
1090
1091 $llvmgcc_version_long="";
1092 if ($LLVMGCCPATH ne "") {
1093   $llvmgcc_version_long = `$LLVMGCCPATH/llvm-gcc -v 2>&1`;
1094 } else {
1095   $llvmgcc_version_long = `llvm-gcc -v 2>&1`;
1096 }
1097 @LLVMGCC_VERSION = split '\n', $llvmgcc_version_long;
1098 $llvmgcc_versionTarget = $LLVMGCC_VERSION[1];
1099 $llvmgcc_versionTarget =~ /Target: (.+)/;
1100 $targetTriple = $1;
1101
1102 if(!$BuildError){
1103   @DEJAGNU_LOG = ReadFile "$DejagnuLog";
1104   @DEJAGNU_SUM = ReadFile "$DejagnuSum";
1105   $dejagnutests_log = join("\n", @DEJAGNU_LOG);
1106   $dejagnutests_sum = join("\n", @DEJAGNU_SUM);
1107
1108   @DEJAGNULOG_FULL = ReadFile "$DejagnuTestsLog";
1109   $dejagnulog_full = join("\n", @DEJAGNULOG_FULL);
1110 }
1111
1112 ##############################################################
1113 #
1114 # Send data via a post request
1115 #
1116 ##############################################################
1117
1118 if ( $VERBOSE ) { print "SEND THE DATA VIA THE POST REQUEST\n"; }
1119
1120 my %hash_of_data = (
1121   'machine_data' => $machine_data,
1122   'build_data' => $build_data,
1123   'gcc_version' => $gcc_version,
1124   'nickname' => $nickname,
1125   'dejagnutime_wall' => $DejagnuWallTime,
1126   'dejagnutime_cpu' => $DejagnuTime,
1127   'cvscheckouttime_wall' => $CheckoutTime_Wall,
1128   'cvscheckouttime_cpu' => $CheckoutTime_CPU,
1129   'configtime_wall' => $ConfigWallTime,
1130   'configtime_cpu'=> $ConfigTime,
1131   'buildtime_wall' => $BuildWallTime,
1132   'buildtime_cpu' => $BuildTime,
1133   'warnings' => $WarningsFile,
1134   'cvsusercommitlist' => $UserCommitList,
1135   'cvsuserupdatelist' => $UserUpdateList,
1136   'cvsaddedfiles' => $CVSAddedFiles,
1137   'cvsmodifiedfiles' => $CVSModifiedFiles,
1138   'cvsremovedfiles' => $CVSRemovedFiles,
1139   'lines_of_code' => $LOC,
1140   'cvs_file_count' => $NumFilesInCVS,
1141   'cvs_dir_count' => $NumDirsInCVS,
1142   'buildstatus' => $BuildStatus,
1143   'singlesource_programstable' => $SingleSourceProgramsTable,
1144   'multisource_programstable' => $MultiSourceProgramsTable,
1145   'externalsource_programstable' => $ExternalProgramsTable,
1146   'llcbeta_options' => $multisource_llcbeta_options,
1147   'warnings_removed' => $WarningsRemoved,
1148   'warnings_added' => $WarningsAdded,
1149   'passing_tests' => $passes,
1150   'expfail_tests' => $xfails,
1151   'unexpfail_tests' => $fails,
1152   'all_tests' => $dejagnu_test_list,
1153   'new_tests' => "",
1154   'removed_tests' => "",
1155   'dejagnutests_results' => $DejagnuTestResults,
1156   'dejagnutests_log' => $dejagnulog_full,
1157   'starttime' => $starttime,
1158   'endtime' => $endtime,
1159   'o_file_sizes' => $o_file_sizes,
1160   'a_file_sizes' => $a_file_sizes,
1161   'target_triple' => $targetTriple
1162 );
1163
1164 if ($SUBMIT || !($SUBMITAUX eq "")) {
1165   my $response = SendData $SUBMITSERVER,$SUBMITSCRIPT,\%hash_of_data;
1166   if( $VERBOSE) { print "============================\n$response"; }
1167 } else {
1168   print "============================\n";
1169   foreach $x(keys %hash_of_data){
1170       print "$x  => $hash_of_data{$x}\n";
1171   }
1172 }
1173
1174 ##############################################################
1175 #
1176 # Remove the cvs tree...
1177 #
1178 ##############################################################
1179 system ( "$NICE rm -rf $BuildDir")
1180   if (!$NOCHECKOUT and !$NOREMOVE and !$NOREMOVEATEND);
1181 system ( "$NICE rm -rf $WebDir")
1182   if (!$NOCHECKOUT and !$NOREMOVE and !$NOREMOVERESULTS);