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