Issue cvs co with -P option to prune empty directories. Remove the unnecessary
[oota-llvm.git] / utils / NightlyTest.pl
1 #!/usr/bin/perl -w
2 #
3 # Program:  NightlyTest.pl
4 #
5 # Synopsis: Perform a series of tests which are designed to be run nightly.
6 #           This is used to keep track of the status of the LLVM tree, tracking
7 #           regressions and performance changes.  This generates one web page a
8 #           day which can be used to access this information.
9 #
10 # Syntax:   NightlyTest.pl [OPTIONS] [CVSROOT BUILDDIR WEBDIR]
11 #   where
12 # OPTIONS may include one or more of the following:
13 #  -nocheckout      Do not create, checkout, update, or configure
14 #                   the source tree.
15 #  -noremove        Do not remove the BUILDDIR after it has been built.
16 #  -notest          Do not even attempt to run the test programs. Implies
17 #                   -norunningtests.
18 #  -norunningtests  Do not run the Olden benchmark suite with
19 #                   LARGE_PROBLEM_SIZE enabled.
20 #  -nodejagnu       Do not run feature or regression tests
21 #  -parallel        Run two parallel jobs with GNU Make.
22 #  -release         Build an LLVM Release version
23 #  -enable-llcbeta  Enable testing of beta features in llc.
24 #  -disable-llc     Disable LLC tests in the nightly tester.
25 #  -disable-jit     Disable JIT tests in the nightly tester.
26 #  -disable-cbe     Disable C backend tests in the nightly tester.
27 #  -verbose         Turn on some debug output
28 #  -debug           Print information useful only to maintainers of this script.
29 #  -nice            Checkout/Configure/Build with "nice" to reduce impact 
30 #                   on busy servers.
31 #  -f2c             Next argument specifies path to F2C utility
32 #  -gnuplotscript   Next argument specifies gnuplot script to use
33 #  -templatefile    Next argument specifies template file to use
34 #  -gccpath         Path to gcc/g++ used to build LLVM
35 #  -cvstag          Check out a specific CVS tag to build LLVM (useful for
36 #                   testing release branches)
37 #  -target          Specify the target triplet
38 #  -cflags          Next argument specifies that C compilation options that
39 #                   override the default.
40 #  -cxxflags        Next argument specifies that C++ compilation options that
41 #                   override the default.
42 #  -ldflags         Next argument specifies that linker options that override
43 #                   the default.
44 #  -compileflags    Next argument specifies extra options passed to make when
45 #                   building LLVM.
46 #
47 #  ---------------- Options to configure llvm-test ----------------------------
48 #  -extraflags      Next argument specifies extra options that are passed to
49 #                   compile the tests.
50 #  -noexternals     Do not run the external tests (for cases where povray
51 #                   or SPEC are not installed)
52 #  -with-externals  Specify a directory where the external tests are located.
53 #
54 # CVSROOT is the CVS repository from which the tree will be checked out,
55 #  specified either in the full :method:user@host:/dir syntax, or
56 #  just /dir if using a local repo.
57 # BUILDDIR is the directory where sources for this test run will be checked out
58 #  AND objects for this test run will be built. This directory MUST NOT
59 #  exist before the script is run; it will be created by the cvs checkout
60 #  process and erased (unless -noremove is specified; see above.)
61 # WEBDIR is the directory into which the test results web page will be written,
62 #  AND in which the "index.html" is assumed to be a symlink to the most recent
63 #  copy of the results. This directory will be created if it does not exist.
64 # LLVMGCCDIR is the directory in which the LLVM GCC Front End is installed
65 #  to. This is the same as you would have for a normal LLVM build.
66 #
67 use POSIX qw(strftime);
68 use File::Copy;
69
70 my $HOME = $ENV{'HOME'};
71 my $CVSRootDir = $ENV{'CVSROOT'};
72    $CVSRootDir = "/home/vadve/shared/PublicCVS"
73      unless $CVSRootDir;
74 my $BuildDir   = $ENV{'BUILDDIR'};
75    $BuildDir   = "$HOME/buildtest"
76      unless $BuildDir;
77 my $WebDir     = $ENV{'WEBDIR'};
78    $WebDir     = "$HOME/cvs/testresults-X86"
79      unless $WebDir;
80
81 # Calculate the date prefix...
82 @TIME = localtime;
83 my $DATE = sprintf "%4d-%02d-%02d", $TIME[5]+1900, $TIME[4]+1, $TIME[3];
84 my $DateString = strftime "%B %d, %Y", localtime;
85 my $TestStartTime = gmtime() . "GMT<br>" . localtime() . " (local)";
86
87 # Command line argument settings...
88 my $NOCHECKOUT = 0;
89 my $NOREMOVE = 0;
90 my $NOTEST = 0;
91 my $NORUNNINGTESTS = 0;
92 my $NOEXTERNALS = 0;
93 my $MAKEOPTS = "";
94 my $PROGTESTOPTS = "";
95 my $VERBOSE = 0;
96 my $DEBUG = 0;
97 my $CONFIGUREARGS = "";
98 my $CVSCOOPT = "-APR";
99 my $NICE = "";
100 my $NODEJAGNU = 0;
101
102 sub ReadFile {
103   if (open (FILE, $_[0])) {
104     undef $/;
105     my $Ret = <FILE>;
106     close FILE;
107     $/ = '\n';
108     return $Ret;
109   } else {
110     print "Could not open file '$_[0]' for reading!";
111     return "";
112   }
113 }
114
115 sub WriteFile {  # (filename, contents)
116   open (FILE, ">$_[0]") or die "Could not open file '$_[0]' for writing!";
117   print FILE $_[1];
118   close FILE;
119 }
120
121 sub GetRegex {   # (Regex with ()'s, value)
122   $_[1] =~ /$_[0]/m;
123   if (defined($1)) {
124     return $1;
125   }
126   return "0";
127 }
128
129 sub Touch {
130   my @files = @_;
131   my $now = time;
132   foreach my $file (@files) {
133     if (! -f $file) {
134       open (FILE, ">$file") or warn "Could not create new file $file";
135       close FILE;
136     }
137     utime $now, $now, $file;
138   }
139 }
140
141 sub AddRecord {
142   my ($Val, $Filename) = @_;
143   my @Records;
144   if (open FILE, "$WebDir/$Filename") {
145     @Records = grep !/$DATE/, split "\n", <FILE>;
146     close FILE;
147   }
148   push @Records, "$DATE: $Val";
149   WriteFile "$WebDir/$Filename", (join "\n", @Records) . "\n";
150 }
151
152 sub AddPreTag {  # Add pre tags around nonempty list, or convert to "none"
153   $_ = shift;
154   if (length) { return "<pre>$_</pre>"; } else { "<b>none</b><br>"; }
155 }
156
157 sub ArrayToList { # Add <li> tags around nonempty list or convert to "none"
158   my $result = "";
159   if (scalar @_) {
160     $result = "<ul>";
161     foreach $item (@_) {
162       $result .= "<li><tt>$item</tt></li>";
163     }
164     $result .= "</ul>";
165   } else {
166     $result = "<p><b>none</b></p>";
167   }
168   return $result;
169 }
170
171 sub ChangeDir { # directory, logical name
172   my ($dir,$name) = @_;
173   chomp($dir);
174   if ( $VERBOSE ) { print "Changing To: $name ($dir)\n"; }
175   chdir($dir) || die "Cannot change directory to: $name ($dir) ";
176 }
177
178 sub CopyFile { #filename, newfile
179   my ($file, $newfile) = @_;
180   chomp($file);
181   if ($VERBOSE) { print "Copying $file to $newfile\n"; }
182   copy($file, $newfile);
183 }
184
185 sub GetDir {
186   my $Suffix = shift;
187   opendir DH, $WebDir;
188   my @Result = reverse sort grep !/$DATE/, grep /[-0-9]+$Suffix/, readdir DH;
189   closedir DH;
190   return @Result;
191 }
192
193 # DiffFiles - Diff the current version of the file against the last version of
194 # the file, reporting things added and removed.  This is used to report, for
195 # example, added and removed warnings.  This returns a pair (added, removed)
196 #
197 sub DiffFiles {
198   my $Suffix = shift;
199   my @Others = GetDir $Suffix;
200   if (@Others == 0) {  # No other files?  We added all entries...
201     return (`cat $WebDir/$DATE$Suffix`, "");
202   }
203   # Diff the files now...
204   my @Diffs = split "\n", `diff $WebDir/$DATE$Suffix $WebDir/$Others[0]`;
205   my $Added   = join "\n", grep /^</, @Diffs;
206   my $Removed = join "\n", grep /^>/, @Diffs;
207   $Added =~ s/^< //gm;
208   $Removed =~ s/^> //gm;
209   return ($Added, $Removed);
210 }
211
212 # FormatTime - Convert a time from 1m23.45 into 83.45
213 sub FormatTime {
214   my $Time = shift;
215   if ($Time =~ m/([0-9]+)m([0-9.]+)/) {
216     $Time = sprintf("%7.4f", $1*60.0+$2);
217   }
218   return $Time;
219 }
220
221 sub GetRegexNum {
222   my ($Regex, $Num, $Regex2, $File) = @_;
223   my @Items = split "\n", `grep '$Regex' $File`;
224   return GetRegex $Regex2, $Items[$Num];
225 }
226
227 sub GetDejagnuTestResults { # (filename, log)
228   my ($filename, $DejagnuLog) = @_;
229   my @lines;
230   my $firstline;
231   $/ = "\n"; #Make sure we're going line at a time.
232
233   print "DEJAGNU TEST RESULTS:\n";
234
235   if (open SRCHFILE, $filename) {
236     # Process test results
237     my $first_list = 1;
238     my $should_break = 1;
239     my $nocopy = 0;
240     my $readingsum = 0;
241     while ( <SRCHFILE> ) {
242       if ( length($_) > 1 ) { 
243         chomp($_);
244         if ( m/^XPASS:/ || m/^FAIL:/ ) {
245           $nocopy = 0;
246           if ( $first_list ) {
247             push(@lines, "<h3>UNEXPECTED TEST RESULTS</h3><ol><li>\n");
248             $first_list = 0;
249             $should_break = 1;
250             push(@lines, "<b>$_</b><br/>\n");
251             print "  $_\n";
252           } else {
253             push(@lines, "</li><li><b>$_</b><br/>\n");
254             print "  $_\n";
255           }
256         } elsif ( m/Summary/ ) {
257           if ( $first_list ) {
258             push(@lines, "<b>PERFECT!</b>"); 
259             print "  PERFECT!\n";
260           } else {
261             push(@lines, "</li></ol>\n");
262           }
263           push(@lines, "<h3>STATISTICS</h3><pre>\n");
264           print "\nDEJAGNU STATISTICS:\n";
265           $should_break = 0;
266           $nocopy = 0;
267           $readingsum = 1;
268         } elsif ( $readingsum ) {
269           push(@lines,"$_\n");
270           print "  $_\n";
271         }
272       }
273     }
274   }
275   push(@lines, "</pre>\n");
276   close SRCHFILE;
277
278   my $content = join("", @lines);
279   return "$content</li></ol>\n";
280 }
281
282
283 #####################################################################
284 ## MAIN PROGRAM
285 #####################################################################
286
287 my $Template = "";
288 my $PlotScriptFilename = "";
289
290 # Parse arguments... 
291 while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
292   shift;
293   last if /^--$/;  # Stop processing arguments on --
294
295   # List command line options here...
296   if (/^-nocheckout$/)     { $NOCHECKOUT = 1; next; }
297   if (/^-noremove$/)       { $NOREMOVE = 1; next; }
298   if (/^-notest$/)         { $NOTEST = 1; $NORUNNINGTESTS = 1; next; }
299   if (/^-norunningtests$/) { $NORUNNINGTESTS = 1; next; }
300   if (/^-parallel$/)       { $MAKEOPTS = "$MAKEOPTS -j2 -l3.0"; next; }
301   if (/^-release$/)        { $MAKEOPTS = "$MAKEOPTS ENABLE_OPTIMIZED=1"; next; }
302   if (/^-enable-llcbeta$/) { $PROGTESTOPTS .= " ENABLE_LLCBETA=1"; next; }
303   if (/^-disable-llc$/)    { $PROGTESTOPTS .= " DISABLE_LLC=1";
304                              $CONFIGUREARGS .= " --disable-llc_diffs"; next; }
305   if (/^-disable-jit$/)    { $PROGTESTOPTS .= " DISABLE_JIT=1";
306                              $CONFIGUREARGS .= " --disable-jit"; next; }
307   if (/^-disable-cbe$/)    { $PROGTESTOPTS .= " DISABLE_CBE=1"; next; }
308   if (/^-verbose$/)        { $VERBOSE = 1; next; }
309   if (/^-debug$/)          { $DEBUG = 1; next; }
310   if (/^-nice$/)           { $NICE = "nice "; next; }
311   if (/^-f2c$/)            {
312     $CONFIGUREARGS .= " --with-f2c=$ARGV[0]"; shift; next;
313   }
314   if (/^-with-externals/)  { 
315     $CONFIGUREARGS .= " --with-externals=$ARGV[0]"; shift; next 
316   }
317   if (/^-gnuplotscript$/)  { $PlotScriptFilename = $ARGV[0]; shift; next; }
318   if (/^-templatefile$/)   { $Template = $ARGV[0]; shift; next; }
319   if (/^-gccpath/)         { 
320     $CONFIGUREARGS .= " CC=$ARGV[0]/gcc CXX=$ARGV[0]/g++"; shift; next; 
321   }
322   if (/^-cvstag/)          { $CVSCOOPT .= " -r $ARGV[0]"; shift; next; }
323   if (/^-target/)          {
324     $CONFIGUREARGS .= " --target=$ARGV[0]"; shift; next;
325   }
326   if (/^-cflags/)          {
327     $MAKEOPTS = "$MAKEOPTS C.Flags=\'$ARGV[0]\'"; shift; next;
328   }
329   if (/^-cxxflags/)        {
330     $MAKEOPTS = "$MAKEOPTS CXX.Flags=\'$ARGV[0]\'"; shift; next;
331   }
332   if (/^-ldflags/)         {
333     $MAKEOPTS = "$MAKEOPTS LD.Flags=\'$ARGV[0]\'"; shift; next;
334   }
335   if (/^-compileflags/)    {
336     $MAKEOPTS = "$MAKEOPTS $ARGV[0]"; shift; next;
337   }
338   if (/^-extraflags/)      {
339     $CONFIGUREARGS .= " --with-extra-options=\'$ARGV[0]\'"; shift; next;
340   }
341   if (/^-noexternals$/)    { $NOEXTERNALS = 1; next; }
342   if (/^-nodejagnu$/)      { $NODEJAGNU = 1; next; }
343   print "Unknown option: $_ : ignoring!\n";
344 }
345
346 if ($ENV{'LLVMGCCDIR'}) {
347   $CONFIGUREARGS .= " --with-llvmgccdir=" . $ENV{'LLVMGCCDIR'};
348 }
349 if ($CONFIGUREARGS !~ /--disable-jit/) {
350   $CONFIGUREARGS .= " --enable-jit";
351 }
352
353 die "Must specify 0 or 3 options!" if (@ARGV != 0 and @ARGV != 3);
354
355 if (@ARGV == 3) {
356   $CVSRootDir = $ARGV[0];
357   $BuildDir   = $ARGV[1];
358   $WebDir     = $ARGV[2];
359 }
360
361 my $Prefix = "$WebDir/$DATE";
362
363 #define the file names we'll use
364 my $BuildLog = "$Prefix-Build-Log.txt";
365 my $CVSLog = "$Prefix-CVS-Log.txt";
366 my $OldenTestsLog = "$Prefix-Olden-tests.txt";
367 my $SingleSourceLog = "$Prefix-SingleSource-ProgramTest.txt.gz";
368 my $MultiSourceLog = "$Prefix-MultiSource-ProgramTest.txt.gz";
369 my $ExternalLog = "$Prefix-External-ProgramTest.txt.gz";
370 my $DejagnuLog = "$Prefix-Dejagnu-testrun.log";
371 my $DejagnuSum = "$Prefix-Dejagnu-testrun.sum";
372 my $DejagnuTestsLog = "$Prefix-DejagnuTests-Log.txt";
373
374 if ($VERBOSE) {
375   print "INITIALIZED\n";
376   print "CVS Root = $CVSRootDir\n";
377   print "BuildDir = $BuildDir\n";
378   print "WebDir   = $WebDir\n";
379   print "Prefix   = $Prefix\n";
380   print "CVSLog   = $CVSLog\n";
381   print "BuildLog = $BuildLog\n";
382 }
383
384 if (! -d $WebDir) {
385   mkdir $WebDir, 0777;
386   warn "Warning: $WebDir did not exist; creating it.\n";
387 }
388
389 #
390 # Create the CVS repository directory
391 #
392 if (!$NOCHECKOUT) {
393   if (-d $BuildDir) {
394     if (!$NOREMOVE) {
395       system "rm -rf $BuildDir"; 
396     } else {
397        die "CVS checkout directory $BuildDir already exists!";
398     }
399   }
400   mkdir $BuildDir or die "Could not create CVS checkout directory $BuildDir!";
401 }
402
403 ChangeDir( $BuildDir, "CVS checkout directory" );
404
405
406 #
407 # Check out the llvm tree, saving CVS messages to the cvs log...
408 #
409 my $CVSOPT = "";
410 # Use compression if going over ssh.
411 $CVSOPT = "-z3" if $CVSRootDir =~ /^:ext:/;
412 my $CVSCMD = "$NICE cvs $CVSOPT -d $CVSRootDir co -P $CVSCOOPT";
413 if (!$NOCHECKOUT) {
414   if ( $VERBOSE ) { print "CHECKOUT STAGE\n"; }
415   system "( time -p $CVSCMD llvm; cd llvm/projects ; " .
416      "$CVSCMD llvm-test ) > $CVSLog 2>&1";
417   ChangeDir( $BuildDir , "CVS Checkout directory") ;
418 }
419
420 ChangeDir( "llvm" , "llvm source directory") ;
421
422 if ( $Template eq "" ) {
423   $Template = "$BuildDir/llvm/utils/NightlyTestTemplate.html";
424 }
425 die "Template file $Template is not readable" if ( ! -r "$Template" );
426
427 if ( $PlotScriptFilename eq "" ) {
428   $PlotScriptFilename = "$BuildDir/llvm/utils/NightlyTest.gnuplot";
429 }
430 die "GNUPlot Script $PlotScriptFilename is not readable" if ( ! -r "$PlotScriptFilename" );
431
432 # Read in the HTML template file...
433 if ( $VERBOSE ) { print "READING TEMPLATE\n"; }
434 my $TemplateContents = ReadFile $Template;
435
436 #
437 # Get some static statistics about the current state of CVS
438 #
439 my $CVSCheckoutTime = GetRegex "([0-9.]+)", `grep '^real' $CVSLog`;
440 my $NumFilesInCVS = `egrep '^U' $CVSLog | wc -l` + 0;
441 my $NumDirsInCVS  = `egrep '^cvs (checkout|server|update):' $CVSLog | wc -l` + 0;
442 $LOC = `utils/countloc.sh`;
443
444 #
445 # Build the entire tree, saving build messages to the build log
446 #
447 if (!$NOCHECKOUT) {
448   if ( $VERBOSE ) { print "CONFIGURE STAGE\n"; }
449   my $EXTRAFLAGS = "--enable-spec --with-objroot=.";
450   system "(time -p $NICE ./configure $CONFIGUREARGS $EXTRAFLAGS) > $BuildLog 2>&1";
451
452   if ( $VERBOSE ) { print "BUILD STAGE\n"; }
453   # Build the entire tree, capturing the output into $BuildLog
454   system "(time -p $NICE gmake $MAKEOPTS) >> $BuildLog 2>&1";
455 }
456
457
458 #
459 # Get some statistics about the build...
460 #
461 my @Linked = split '\n', `grep Linking $BuildLog`;
462 my $NumExecutables = scalar(grep(/executable/, @Linked));
463 my $NumLibraries   = scalar(grep(!/executable/, @Linked));
464 my $NumObjects     = `grep ']\: Compiling ' $BuildLog | wc -l` + 0;
465
466 my $ConfigTimeU = GetRegexNum "^user", 0, "([0-9.]+)", "$BuildLog";
467 my $ConfigTimeS = GetRegexNum "^sys", 0, "([0-9.]+)", "$BuildLog";
468 my $ConfigTime  = $ConfigTimeU+$ConfigTimeS;  # ConfigTime = User+System
469 my $ConfigWallTime = GetRegexNum "^real", 0,"([0-9.]+)","$BuildLog";
470
471 my $BuildTimeU = GetRegexNum "^user", 1, "([0-9.]+)", "$BuildLog";
472 my $BuildTimeS = GetRegexNum "^sys", 1, "([0-9.]+)", "$BuildLog";
473 my $BuildTime  = $BuildTimeU+$BuildTimeS;  # BuildTime = User+System
474 my $BuildWallTime = GetRegexNum "^real", 1, "([0-9.]+)","$BuildLog";
475
476 my $BuildError = 0, $BuildStatus = "OK";
477 if (`grep '^gmake[^:]*: .*Error' $BuildLog | wc -l` + 0 ||
478     `grep '^gmake: \*\*\*.*Stop.' $BuildLog | wc -l`+0) {
479   $BuildStatus = "<h3><font color='red'>error: compilation " .
480                 "<a href=\"$DATE-Build-Log.txt\">aborted</a></font></h3>";
481   $BuildError = 1;
482   print "\n***ERROR BUILDING TREE\n\n";
483 }
484
485 if ($BuildError) { $NODEJAGNU=1; }
486
487 my $DejangnuTestResults; # String containing the results of the dejagnu
488 if(!$NODEJAGNU) {
489   if($VERBOSE) { print "DEJAGNU FEATURE/REGRESSION TEST STAGE\n"; }
490   
491   my $dejagnu_output = "$DejagnuTestsLog";
492   
493   #Run the feature and regression tests, results are put into testrun.sum
494   #Full log in testrun.log
495   system "(time -p gmake $MAKEOPTS check) > $dejagnu_output 2>&1";
496
497   #Extract time of dejagnu tests
498   my $DejagnuTimeU = GetRegexNum "^user", 0, "([0-9.]+)", "$dejagnu_output";
499   my $DejagnuTimeS = GetRegexNum "^sys", 0, "([0-9.]+)", "$dejagnu_output";
500   $DejagnuTime  = $DejagnuTimeU+$DejagnuTimeS;  # DejagnuTime = User+System
501   $DejagnuWallTime = GetRegexNum "^real", 0,"([0-9.]+)","$dejagnu_output";
502
503   #Copy the testrun.log and testrun.sum to our webdir
504   CopyFile("test/testrun.log", $DejagnuLog);
505   CopyFile("test/testrun.sum", $DejagnuSum);
506
507   $DejagnuTestResults = GetDejagnuTestResults($DejagnuSum, $DejagnuLog);
508
509 } else {
510   $DejagnuTestResults = "Skipped by user choice.";
511   $DejagnuTime     = "0.0";
512   $DejagnuWallTime = "0.0";
513 }
514
515 if ($DEBUG) {
516   print $DejagnuTestResults;
517 }
518
519 if ( $VERBOSE ) { print "BUILD INFORMATION COLLECTION STAGE\n"; }
520 #
521 # Get warnings from the build
522 #
523 my @Warn = split "\n", `egrep 'warning:|Entering dir' $BuildLog`;
524 my @Warnings;
525 my $CurDir = "";
526
527 foreach $Warning (@Warn) {
528   if ($Warning =~ m/Entering directory \`([^\`]+)\'/) {
529     $CurDir = $1;                 # Keep track of directory warning is in...
530     if ($CurDir =~ m#$BuildDir/llvm/(.*)#) { # Remove buildir prefix if included
531       $CurDir = $1;
532     }
533   } else {
534     push @Warnings, "$CurDir/$Warning";     # Add directory to warning...
535   }
536 }
537 my $WarningsFile =  join "\n", @Warnings;
538 my $WarningsList = ArrayToList @Warnings;
539 $WarningsFile =~ s/:[0-9]+:/::/g;
540
541 # Emit the warnings file, so we can diff...
542 WriteFile "$WebDir/$DATE-Warnings.txt", $WarningsFile . "\n";
543 my ($WarningsAdded, $WarningsRemoved) = DiffFiles "-Warnings.txt";
544
545 # Output something to stdout if something has changed
546 print "ADDED   WARNINGS:\n$WarningsAdded\n\n" if (length $WarningsAdded);
547 print "REMOVED WARNINGS:\n$WarningsRemoved\n\n" if (length $WarningsRemoved);
548
549 my @TmpWarningsAdded = split "\n", $WarningsAdded;
550 my @TmpWarningsRemoved = split "\n", $WarningsRemoved;
551 $WarningsAdded = ArrayToList @TmpWarningsAdded;
552 $WarningsRemoved = ArrayToList @TmpWarningsRemoved;
553
554 #
555 # Get some statistics about CVS commits over the current day...
556 #
557 if ($VERBOSE) { print "CVS HISTORY ANALYSIS STAGE\n"; }
558 @CVSHistory = split "\n", `cvs history -D '1 day ago' -a -xAMROCGUW`;
559 #print join "\n", @CVSHistory; print "\n";
560
561 # Extract some information from the CVS history... use a hash so no duplicate
562 # stuff is stored.
563 my (%AddedFiles, %ModifiedFiles, %RemovedFiles, %UsersCommitted, %UsersUpdated);
564
565 my $DateRE = '[-/:0-9 ]+\+[0-9]+';
566
567 # Loop over every record from the CVS history, filling in the hashes.
568 foreach $File (@CVSHistory) {
569   my ($Type, $Date, $UID, $Rev, $Filename);
570   if ($File =~ /([AMRUGC]) ($DateRE) ([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+)/) {
571     ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, $4, "$6/$5");
572   } elsif ($File =~ /([W]) ($DateRE) ([^ ]+)/) {
573     ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", "");
574   } elsif ($File =~ /([O]) ($DateRE) ([^ ]+) +([^ ]+)/) {
575     ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", "$4/");
576   } else {
577     print "UNMATCHABLE: $File\n";
578     next;
579   }
580   # print "$File\nTy = $Type Date = '$Date' UID=$UID Rev=$Rev File = '$Filename'\n";
581
582   if ($Filename =~ /^llvm/) {
583     if ($Type eq 'M') {        # Modified
584       $ModifiedFiles{$Filename} = 1;
585       $UsersCommitted{$UID} = 1;
586     } elsif ($Type eq 'A') {   # Added
587       $AddedFiles{$Filename} = 1;
588       $UsersCommitted{$UID} = 1;
589     } elsif ($Type eq 'R') {   # Removed
590       $RemovedFiles{$Filename} = 1;
591       $UsersCommitted{$UID} = 1;
592     } else {
593       $UsersUpdated{$UID} = 1;
594     }
595   }
596 }
597
598 my $UserCommitList = join "\n", sort keys %UsersCommitted;
599 my $UserUpdateList = join "\n", sort keys %UsersUpdated;
600 my $AddedFilesList = AddPreTag join "\n", sort keys %AddedFiles;
601 my $ModifiedFilesList = AddPreTag join "\n", sort keys %ModifiedFiles;
602 my $RemovedFilesList = AddPreTag join "\n", sort keys %RemovedFiles;
603
604 my $TestError = 1;
605 my $SingleSourceProgramsTable = "!";
606 my $MultiSourceProgramsTable = "!";
607 my $ExternalProgramsTable = "!";
608
609
610 sub TestDirectory {
611   my $SubDir = shift;
612
613   ChangeDir( "projects/llvm-test/$SubDir", "Programs Test Subdirectory" );
614
615   my $ProgramTestLog = "$Prefix-$SubDir-ProgramTest.txt";
616
617   # Run the programs tests... creating a report.nightly.html file
618   if (!$NOTEST) {
619     system "gmake -k $MAKEOPTS $PROGTESTOPTS report.nightly.html "
620          . "TEST=nightly > $ProgramTestLog 2>&1";
621   } else {
622     system "gunzip ${ProgramTestLog}.gz";
623   }
624
625   my $ProgramsTable;
626   if (`grep '^gmake[^:]: .*Error' $ProgramTestLog | wc -l` + 0){
627     $TestError = 1;
628     $ProgramsTable = "<font color=white><h2>Error running tests!</h2></font>";
629     print "ERROR TESTING\n";
630   } elsif (`grep '^gmake[^:]: .*No rule to make target' $ProgramTestLog | wc -l` + 0) {
631     $TestError = 1;
632     $ProgramsTable =
633       "<font color=white><h2>Makefile error running tests!</h2></font>";
634     print "ERROR TESTING\n";
635   } else {
636     $TestError = 0;
637     $ProgramsTable = ReadFile "report.nightly.html";
638
639     #
640     # Create a list of the tests which were run...
641     #
642     system "egrep 'TEST-(PASS|FAIL)' < $ProgramTestLog "
643          . "| sort > $Prefix-$SubDir-Tests.txt";
644   }
645
646   # Compress the test output
647   system "gzip -f $ProgramTestLog";
648   ChangeDir( "../../..", "Programs Test Parent Directory" );
649   return $ProgramsTable;
650 }
651
652 # If we built the tree successfully, run the nightly programs tests...
653 if (!$BuildError) {
654   if ( $VERBOSE ) {
655     print "SingleSource TEST STAGE\n";
656   }
657   $SingleSourceProgramsTable = TestDirectory("SingleSource");
658   if ( $VERBOSE ) {
659     print "MultiSource TEST STAGE\n";
660   }
661   $MultiSourceProgramsTable = TestDirectory("MultiSource");
662   if ( ! $NOEXTERNALS ) {
663     if ( $VERBOSE ) {
664       print "External TEST STAGE\n";
665     }
666     $ExternalProgramsTable = TestDirectory("External");
667     system "cat $Prefix-SingleSource-Tests.txt $Prefix-MultiSource-Tests.txt ".
668          " $Prefix-External-Tests.txt | sort > $Prefix-Tests.txt";
669   } else {
670     $ExternalProgramsTable = '<tr><td>External TEST STAGE SKIPPED</td></tr>';
671     if ( $VERBOSE ) {
672       print "External TEST STAGE SKIPPED\n";
673     }
674     system "cat $Prefix-SingleSource-Tests.txt $Prefix-MultiSource-Tests.txt ".
675          " | sort > $Prefix-Tests.txt";
676   }
677 }
678
679 if ( $VERBOSE ) { print "TEST INFORMATION COLLECTION STAGE\n"; }
680 my ($TestsAdded, $TestsRemoved, $TestsFixed, $TestsBroken) = ("","","","");
681
682 if ($TestError) {
683   $TestsAdded   = "<b>error testing</b><br>";
684   $TestsRemoved = "<b>error testing</b><br>";
685   $TestsFixed   = "<b>error testing</b><br>";
686   $TestsBroken  = "<b>error testing</b><br>";
687 } else {
688   my ($RTestsAdded, $RTestsRemoved) = DiffFiles "-Tests.txt";
689
690   my @RawTestsAddedArray = split '\n', $RTestsAdded;
691   my @RawTestsRemovedArray = split '\n', $RTestsRemoved;
692
693   my %OldTests = map {GetRegex('TEST-....: (.+)', $_)=>$_}
694     @RawTestsRemovedArray;
695   my %NewTests = map {GetRegex('TEST-....: (.+)', $_)=>$_}
696     @RawTestsAddedArray;
697
698   foreach $Test (keys %NewTests) {
699     if (!exists $OldTests{$Test}) {  # TestAdded if in New but not old
700       $TestsAdded = "$TestsAdded$Test\n";
701     } else {
702       if ($OldTests{$Test} =~ /TEST-PASS/) {  # Was the old one a pass?
703         $TestsBroken = "$TestsBroken$Test\n";  # New one must be a failure
704       } else {
705         $TestsFixed = "$TestsFixed$Test\n";    # No, new one is a pass.
706       }
707     }
708   }
709   foreach $Test (keys %OldTests) {  # TestRemoved if in Old but not New
710     $TestsRemoved = "$TestsRemoved$Test\n" if (!exists $NewTests{$Test});
711   }
712
713   print "\nTESTS ADDED:  \n\n$TestsAdded\n\n"   if (length $TestsAdded);
714   print "\nTESTS REMOVED:\n\n$TestsRemoved\n\n" if (length $TestsRemoved);
715   print "\nTESTS FIXED:  \n\n$TestsFixed\n\n"   if (length $TestsFixed);
716   print "\nTESTS BROKEN: \n\n$TestsBroken\n\n"  if (length $TestsBroken);
717
718   $TestsAdded   = AddPreTag $TestsAdded;
719   $TestsRemoved = AddPreTag $TestsRemoved;
720   $TestsFixed   = AddPreTag $TestsFixed;
721   $TestsBroken  = AddPreTag $TestsBroken;
722 }
723
724
725 # If we built the tree successfully, runs of the Olden suite with
726 # LARGE_PROBLEM_SIZE on so that we can get some "running" statistics.
727 if (!$BuildError) {
728   if ( $VERBOSE ) { print "OLDEN TEST SUITE STAGE\n"; }
729   my ($NATTime, $CBETime, $LLCTime, $JITTime, $OptTime, $BytecodeSize,
730       $MachCodeSize) = ("","","","","","","");
731   if (!$NORUNNINGTESTS) {
732     ChangeDir( "$BuildDir/llvm/projects/llvm-test/MultiSource/Benchmarks/Olden",
733       "Olden Test Directory");
734
735     # Clean out previous results...
736     system "$NICE gmake $MAKEOPTS clean > /dev/null 2>&1";
737
738     # Run the nightly test in this directory, with LARGE_PROBLEM_SIZE and
739     # GET_STABLE_NUMBERS enabled!
740     system "gmake -k $MAKEOPTS $PROGTESTOPTS report.nightly.raw.out TEST=nightly " .
741            " LARGE_PROBLEM_SIZE=1 GET_STABLE_NUMBERS=1 > /dev/null 2>&1";
742     system "cp report.nightly.raw.out $OldenTestsLog";
743   } else {
744     system "gunzip ${OldenTestsLog}.gz";
745   }
746
747   # Now we know we have $OldenTestsLog as the raw output file.  Split
748   # it up into records and read the useful information.
749   my @Records = split />>> ========= /, ReadFile "$OldenTestsLog";
750   shift @Records;  # Delete the first (garbage) record
751
752   # Loop over all of the records, summarizing them into rows for the running
753   # totals file.
754   my $WallTimeRE = "Time: ([0-9.]+) seconds \\([0-9.]+ wall clock";
755   foreach $Rec (@Records) {
756     my $rNATTime = GetRegex 'TEST-RESULT-nat-time: program\s*([.0-9m]+)', $Rec;
757     my $rCBETime = GetRegex 'TEST-RESULT-cbe-time: program\s*([.0-9m]+)', $Rec;
758     my $rLLCTime = GetRegex 'TEST-RESULT-llc-time: program\s*([.0-9m]+)', $Rec;
759     my $rJITTime = GetRegex 'TEST-RESULT-jit-time: program\s*([.0-9m]+)', $Rec;
760     my $rOptTime = GetRegex "TEST-RESULT-compile: .*$WallTimeRE", $Rec;
761     my $rBytecodeSize = GetRegex 'TEST-RESULT-compile: *([0-9]+)', $Rec;
762
763     $NATTime .= " " . FormatTime($rNATTime);
764     $CBETime .= " " . FormatTime($rCBETime);
765     $LLCTime .= " " . FormatTime($rLLCTime);
766     $JITTime .= " " . FormatTime($rJITTime);
767     $OptTime .= " $rOptTime";
768     $BytecodeSize .= " $rBytecodeSize";
769   }
770
771   # Now that we have all of the numbers we want, add them to the running totals
772   # files.
773   AddRecord($NATTime, "running_Olden_nat_time.txt");
774   AddRecord($CBETime, "running_Olden_cbe_time.txt");
775   AddRecord($LLCTime, "running_Olden_llc_time.txt");
776   AddRecord($JITTime, "running_Olden_jit_time.txt");
777   AddRecord($OptTime, "running_Olden_opt_time.txt");
778   AddRecord($BytecodeSize, "running_Olden_bytecode.txt");
779
780   system "gzip -f $OldenTestsLog";
781 }
782
783
784 #
785 # Get a list of the previous days that we can link to...
786 #
787 my @PrevDays = map {s/.html//; $_} GetDir ".html";
788
789 if ((scalar @PrevDays) > 20) {
790   splice @PrevDays, 20;  # Trim down list to something reasonable...
791 }
792
793 # Format list for sidebar
794 my $PrevDaysList = join "\n  ", map { "<a href=\"$_.html\">$_</a><br>" } @PrevDays;
795
796 #
797 # Start outputting files into the web directory
798 #
799 ChangeDir( $WebDir, "Web Directory" );
800
801 # Make sure we don't get errors running the nightly tester the first time
802 # because of files that don't exist.
803 Touch ('running_build_time.txt', 'running_Olden_llc_time.txt',
804        'running_loc.txt', 
805        'running_Olden_bytecode.txt', 'running_Olden_nat_time.txt',
806        'running_Olden_cbe_time.txt', 'running_Olden_opt_time.txt',
807        'running_Olden_jit_time.txt');
808
809 # Add information to the files which accumulate information for graphs...
810 AddRecord($LOC, "running_loc.txt");
811 AddRecord($BuildTime, "running_build_time.txt");
812
813 if ( $VERBOSE ) {
814   print "GRAPH GENERATION STAGE\n";
815 }
816 #
817 # Rebuild the graphs now...
818 #
819 $GNUPLOT = "/usr/bin/gnuplot";
820 $GNUPLOT = "gnuplot" if ! -x $GNUPLOT;
821 system ("$GNUPLOT", $PlotScriptFilename);
822
823 #
824 # Remove the cvs tree...
825 #
826 system ( "$NICE rm -rf $BuildDir") if (!$NOCHECKOUT and !$NOREMOVE);
827
828 print "\nUSERS WHO COMMITTED:\n  " . (join "\n  ", sort keys %UsersCommitted) . "\n"
829   if (scalar %UsersCommitted);
830
831 print "\nADDED FILES:\n  " . (join "\n  ", sort keys %AddedFiles) . "\n"
832   if (scalar %AddedFiles);
833
834 print "\nCHANGED FILES:\n  " . (join "\n  ", sort keys %ModifiedFiles) . "\n"
835   if (scalar %ModifiedFiles);
836
837 print "\nREMOVED FILES:\n  " . (join "\n  ", sort keys %RemovedFiles) . "\n"
838   if (scalar %RemovedFiles);
839
840 #
841 # Print out information...
842 #
843 if ($VERBOSE) {
844   print "DateString: $DateString\n";
845   print "CVS Checkout: $CVSCheckoutTime seconds\n";
846   print "Files/Dirs/LOC in CVS: $NumFilesInCVS/$NumDirsInCVS/$LOC\n";
847   print "Build Time: $BuildTime seconds\n";
848   print "Libraries/Executables/Objects built: $NumLibraries/$NumExecutables/$NumObjects\n";
849
850   print "WARNINGS:\n  $WarningsList\n";
851   print "Previous Days =\n  $PrevDaysList\n";
852 }
853
854
855 #
856 # Output the files...
857 #
858
859 if ( $VERBOSE ) {
860   print "OUTPUT STAGE\n";
861 }
862 # Main HTML file...
863 my $Output;
864 my $TestFinishTime = gmtime() . " GMT<br>" . localtime() . " (local)";
865
866 my $TestPlatform = `uname -a`;
867 eval "\$Output = <<ENDOFFILE;$TemplateContents\nENDOFFILE\n";
868 WriteFile "$DATE.html", $Output;
869
870 # Remove the symlink before creating it for systems that don't have "ln -sf".
871 system ("rm index.html");
872 system ("ln -s $DATE.html index.html");
873
874 # Change the index.html symlink...
875
876 # vim: sw=2 ai