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