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