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