Clean up the Feature and Regression test output to (a) use section headers,
[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 #  -nofeaturetests  Do not run the feature tests.
17 #  -noregressiontests Do not run the regression tests.
18 #  -notest          Do not even attempt to run the test programs. Implies
19 #                   -norunningtests.
20 #  -norunningtests  Do not run the Olden benchmark suite with
21 #                   LARGE_PROBLEM_SIZE enabled.
22 #  -parallel        Run two parallel jobs with GNU Make.
23 #  -enable-linscan  Enable linearscan tests
24 #  -verbose         Turn on some debug output
25 #  -debug           Print information useful only to maintainers of this script.
26 #
27 # CVSROOT is the CVS repository from which the tree will be checked out,
28 #  specified either in the full :method:user@host:/dir syntax, or
29 #  just /dir if using a local repo.
30 # BUILDDIR is the directory where sources for this test run will be checked out
31 #  AND objects for this test run will be built. This directory MUST NOT
32 #  exist before the script is run; it will be created by the cvs checkout
33 #  process and erased (unless -noremove is specified; see above.)
34 # WEBDIR is the directory into which the test results web page will be written,
35 #  AND in which the "index.html" is assumed to be a symlink to the most recent
36 #  copy of the results. This directory MUST exist before the script is run.
37 #
38 use POSIX qw(strftime);
39
40 my $HOME = $ENV{'HOME'};
41 my $CVSRootDir = $ENV{'CVSROOT'};
42    $CVSRootDir = "/home/vadve/shared/PublicCVS"
43      unless $CVSRootDir;
44 my $BuildDir   = $ENV{'BUILDDIR'};
45    $BuildDir   = "$HOME/buildtest"
46      unless $BuildDir;
47 my $WebDir     = $ENV{'WEBDIR'};
48    $WebDir     = "$HOME/cvs/testresults-X86"
49      unless $WebDir;
50
51 # Calculate the date prefix...
52 @TIME = localtime;
53 my $DATE = sprintf "%4d-%02d-%02d", $TIME[5]+1900, $TIME[4]+1, $TIME[3];
54 my $DateString = strftime "%B %d, %Y", localtime;
55
56 sub ReadFile {
57   undef $/;
58   if (open (FILE, $_[0])) {
59     my $Ret = <FILE>;
60     close FILE;
61     return $Ret;
62   } else {
63     print "Could not open file '$_[0]' for reading!";
64     return "";
65   }
66 }
67
68 sub WriteFile {  # (filename, contents)
69   open (FILE, ">$_[0]") or die "Could not open file '$_[0]' for writing!";
70   print FILE $_[1];
71   close FILE;
72 }
73
74 sub GetRegex {   # (Regex with ()'s, value)
75   $_[1] =~ /$_[0]/m;
76   if (defined($1)) {
77     return $1;
78   }
79   return "?";
80 }
81
82 sub AddPreTag {  # Add pre tags around nonempty list, or convert to "none"
83   $_ = shift;
84   if (length) { return "<ul><pre>$_</pre></ul>"; } else { "<b>none</b><br>"; }
85 }
86
87 sub GetDir {
88   my $Suffix = shift;
89   opendir DH, $WebDir;
90   my @Result = reverse sort grep !/$DATE/, grep /[-0-9]+$Suffix/, readdir DH;
91   closedir DH;
92   return @Result;
93 }
94
95 # DiffFiles - Diff the current version of the file against the last version of
96 # the file, reporting things added and removed.  This is used to report, for
97 # example, added and removed warnings.  This returns a pair (added, removed)
98 #
99 sub DiffFiles {
100   my $Suffix = shift;
101   my @Others = GetDir $Suffix;
102   if (@Others == 0) {  # No other files?  We added all entries...
103     return (`cat $WebDir/$DATE$Suffix`, "");
104   }
105   # Diff the files now...
106   my @Diffs = split "\n", `diff $WebDir/$DATE$Suffix $WebDir/$Others[0]`;
107   my $Added   = join "\n", grep /^</, @Diffs;
108   my $Removed = join "\n", grep /^>/, @Diffs;
109   $Added =~ s/^< //gm;
110   $Removed =~ s/^> //gm;
111   return ($Added, $Removed);
112 }
113
114 # FormatTime - Convert a time from 1m23.45 into 83.45
115 sub FormatTime {
116   my $Time = shift;
117   if ($Time =~ m/([0-9]+)m([0-9.]+)/) {
118     $Time = sprintf("%7.4f", $1*60.0+$2);
119   }
120   return $Time;
121 }
122
123
124 # Command line argument settings...
125 my $NOCHECKOUT = 0;
126 my $NOREMOVE   = 0;
127 my $NOFEATURES = 0;
128 my $NOREGRESSIONS = 0;
129 my $NOTEST     = 0;
130 my $NORUNNINGTESTS = 0;
131 my $MAKEOPTS   = "";
132 my $ENABLELINEARSCAN = "";
133 my $VERBOSE  = 0;
134 my $DEBUG = 0;
135
136 # Parse arguments...
137 while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
138   shift;
139   last if /^--$/;  # Stop processing arguments on --
140
141   # List command line options here...
142   if (/^-nocheckout$/)     { $NOCHECKOUT = 1; next; }
143   if (/^-noremove$/)       { $NOREMOVE   = 1; next; }
144   if (/^-nofeaturetests$/) { $NOFEATURES   = 1; next; }
145   if (/^-noregressiontests$/){ $NOREGRESSIONS   = 1; next; }
146   if (/^-notest$/)         { $NOTEST     = 1; $NORUNNINGTESTS = 1; next; }
147   if (/^-norunningtests$/) { $NORUNNINGTESTS = 1; next; }
148   if (/^-parallel$/)       { $MAKEOPTS   = "-j2 -l3.0"; next; }
149   if (/^-enable-linscan$/) { $ENABLELINEARSCAN = "ENABLE_LINEARSCAN=1"; next; }
150   if (/^-verbose$/)        { $VERBOSE  = 1; next; }
151   if (/^-debug$/)          { $DEBUG  = 1; next; }
152
153   print "Unknown option: $_ : ignoring!\n";
154 }
155
156 die "Must specify 0 or 3 options!" if (@ARGV != 0 and @ARGV != 3);
157
158 if (@ARGV == 3) {
159   $CVSRootDir = $ARGV[0];
160   $BuildDir   = $ARGV[1];
161   $WebDir     = $ARGV[2];
162 }
163
164
165 my $Template = "$BuildDir/llvm/utils/NightlyTestTemplate.html";
166 my $Prefix = "$WebDir/$DATE";
167
168 if ($VERBOSE) {
169   print "INITIALIZED\n";
170   print "CVS Root = $CVSRootDir\n";
171   print "BuildDir = $BuildDir\n";
172   print "WebDir   = $WebDir\n";
173   print "Prefix   = $Prefix\n";
174 }
175
176
177 #
178 # Create the CVS repository directory
179 #
180 if (!$NOCHECKOUT) {
181   if (-d $BuildDir) {
182     if (!$NOREMOVE) {
183       system "rm -rf $BuildDir"; 
184     } else {
185        die "CVS checkout directory $BuildDir already exists!";
186     }
187   }
188   mkdir $BuildDir or die "Could not create CVS checkout directory $BuildDir!";
189 }
190 chdir $BuildDir or die "Could not change to CVS checkout directory $BuildDir!";
191
192
193 #
194 # Check out the llvm tree, saving CVS messages to the cvs log...
195 #
196 $CVSOPT = "";
197 $CVSOPT = "-z3" if $CVSRootDir =~ /^:ext:/; # Use compression if going over ssh.
198 if (!$NOCHECKOUT) {
199   if ( $VERBOSE ) { print "CHECKOUT STAGE\n"; }
200   system "(time -p cvs $CVSOPT -d $CVSRootDir co llvm) > $Prefix-CVS-Log.txt 2>&1";
201 }
202
203 chdir "llvm" or die "Could not change into llvm directory!";
204
205 if (!$NOCHECKOUT) {
206   if ( $VERBOSE ) { print "UPDATE STAGE\n"; }
207   system "cvs update -P -d > /dev/null 2>&1" ;
208 }
209
210 # Read in the HTML template file...
211 my $TemplateContents = ReadFile $Template;
212
213
214 #
215 # Get some static statistics about the current state of CVS
216 #
217 my $CVSCheckoutTime = GetRegex "([0-9.]+)", `grep '^real' $Prefix-CVS-Log.txt`;
218 my $NumFilesInCVS = `egrep '^U' $Prefix-CVS-Log.txt | wc -l` + 0;
219 my $NumDirsInCVS  = `egrep '^cvs (checkout|server|update):' $Prefix-CVS-Log.txt | wc -l` + 0;
220 $LOC = GetRegex "([0-9]+) +total", `wc -l \`utils/getsrcs.sh\` | grep total`;
221
222 #
223 # Build the entire tree, saving build messages to the build log
224 #
225 if (!$NOCHECKOUT) {
226   if ( $VERBOSE ) { print "CONFIGURE STAGE\n"; }
227   system "(time -p ./configure --enable-jit --enable-spec --with-objroot=.) > $Prefix-Build-Log.txt 2>&1";
228
229   if ( $VERBOSE ) { print "BUILD STAGE\n"; }
230   # Build the entire tree, capturing the output into $Prefix-Build-Log.txt
231   system "(time -p gmake $MAKEOPTS) >> $Prefix-Build-Log.txt 2>&1";
232 }
233
234
235 sub GetRegexNum {
236   my ($Regex, $Num, $Regex2, $File) = @_;
237   my @Items = split "\n", `grep '$Regex' $File`;
238   return GetRegex $Regex2, $Items[$Num];
239 }
240
241 #
242 # Get some statistics about the build...
243 #
244 my @Linked = split '\n', `grep Linking $Prefix-Build-Log.txt`;
245 my $NumExecutables = scalar(grep(/executable/, @Linked));
246 my $NumLibraries   = scalar(grep(!/executable/, @Linked));
247 my $NumObjects     = `grep '^Compiling' $Prefix-Build-Log.txt | wc -l` + 0;
248
249 my $ConfigTimeU = GetRegexNum "^user", 0, "([0-9.]+)", "$Prefix-Build-Log.txt";
250 my $ConfigTimeS = GetRegexNum "^sys", 0, "([0-9.]+)", "$Prefix-Build-Log.txt";
251 my $ConfigTime  = $ConfigTimeU+$ConfigTimeS;  # ConfigTime = User+System
252 my $ConfigWallTime = GetRegexNum "^real", 0,"([0-9.]+)","$Prefix-Build-Log.txt";
253
254 my $BuildTimeU = GetRegexNum "^user", 1, "([0-9.]+)", "$Prefix-Build-Log.txt";
255 my $BuildTimeS = GetRegexNum "^sys", 1, "([0-9.]+)", "$Prefix-Build-Log.txt";
256 my $BuildTime  = $BuildTimeU+$BuildTimeS;  # BuildTime = User+System
257 my $BuildWallTime = GetRegexNum "^real", 1, "([0-9.]+)","$Prefix-Build-Log.txt";
258
259 my $BuildError = "";
260 if (`grep '^gmake[^:]*: .*Error' $Prefix-Build-Log.txt | wc -l` + 0 ||
261     `grep '^gmake: \*\*\*.*Stop.' $Prefix-Build-Log.txt | wc -l`+0) {
262   $BuildError = "<h3><font color='red'>Build error: compilation " .
263                 "<a href=\"$DATE-Build-Log.txt\">aborted</a></font></h3>";
264   print "BUILD ERROR\n";
265 }
266
267 sub GetQMTestResults { # (filename)
268   my ($filename) = @_;
269   my @lines;
270   my $firstline;
271   $/ = "\n"; #Make sure we're going line at a time.
272   if (open SRCHFILE, $filename) {
273     # Skip stuff before ---TEST RESULTS
274     while ( <SRCHFILE> ) {
275       if ( m/^--- TEST RESULTS/ ) { last; }
276     }
277     # Process test results
278     push(@lines,"<h3>TEST RESULTS</h3><ol><li>\n");
279     my $first_list = 1;
280     my $should_break = 1;
281     while ( <SRCHFILE> ) {
282       if ( length($_) > 1 ) { 
283         chomp($_);
284         if ( ! m/: PASS[ ]*$/ &&
285              ! m/^    qmtest.target:/ && 
286              ! m/^      local/ &&
287              ! m/^gmake:/ ) {
288           if ( m/: XFAIL/ || m/: XPASS/ || m/: FAIL/ ) {
289             if ( $first_list ) {
290               $first_list = 0;
291               $should_break = 1;
292               push(@lines,"<b>$_</b><br/>\n");
293             } else {
294               push(@lines,"</li><li><b>$_</b><br/>\n");
295             }
296           } elsif ( m/^--- STATISTICS/ ) {
297             if ( $first_list ) { push(@lines,"<b>PERFECT!</b>"); }
298             push(@lines,"</li></ol><h3>STATISTICS</h3><pre>\n");
299             $should_break = 0;
300           } elsif ( m/^--- TESTS WITH/ ) {
301             $should_break = 1;
302             $first_list = 1;
303             push(@lines,"</pre><h3>TESTS WITH UNEXPECTED RESULTS</h3><ol><li>\n");
304           } elsif ( m/^real / ) {
305             last;
306           } else {
307             if ( $should_break ) {
308               push(@lines,"$_<br/>\n");
309             } else {
310               push(@lines,"$_\n");
311             }
312           }
313         }
314       }
315     }
316     close SRCHFILE;
317   }
318   my $content = join("",@lines);
319   return "$content</pre>\n";
320 }
321
322 # Get results of feature tests.
323 my $FeatureTestResults; # String containing the results of the feature tests
324 my $FeatureTime;        # System+CPU Time for feature tests
325 my $FeatureWallTime;    # Wall Clock Time for feature tests
326 if (!$NOFEATURES) {
327   if ( $VERBOSE ) { print "FEATURE TEST STAGE\n"; }
328   my $feature_output = "$Prefix-FeatureTests-Log.txt";
329
330   # Run the feature tests so we can summarize the results
331   system "(time -p gmake -C test Feature.t) > $feature_output 2>&1";
332
333   # Extract test results
334   $FeatureTestResults = GetQMTestResults("$feature_output");
335
336   # Extract time of feature tests
337   my $FeatureTimeU = GetRegexNum "^user", 0, "([0-9.]+)", "$feature_output";
338   my $FeatureTimeS = GetRegexNum "^sys", 0, "([0-9.]+)", "$feature_output";
339   $FeatureTime  = $FeatureTimeU+$FeatureTimeS;  # FeatureTime = User+System
340   $FeatureWallTime = GetRegexNum "^real", 0,"([0-9.]+)","$feature_output";
341   # Run the regression tests so we can summarize the results
342 } else {
343   $FeatureTestResults = "Skipped by user choice.";
344   $FeatureTime     = "0.0";
345   $FeatureWallTime = "0.0";
346 }
347
348 if (!$NOREGRESSIONS) {
349   if ( $VERBOSE ) { print "REGRESSION TEST STAGE\n"; }
350   my $regression_output = "$Prefix-RegressionTests-Log.txt";
351
352   # Run the regression tests so we can summarize the results
353   system "(time -p gmake -C test Regression.t) > $regression_output 2>&1";
354
355   # Extract test results
356   $RegressionTestResults = GetQMTestResults("$regression_output");
357
358   # Extract time of regressions tests
359   my $RegressionTimeU = GetRegexNum "^user", 0, "([0-9.]+)", "$regression_output";
360   my $RegressionTimeS = GetRegexNum "^sys", 0, "([0-9.]+)", "$regression_output";
361   $RegressionTime  = $RegressionTimeU+$RegressionTimeS;  # RegressionTime = User+System
362   $RegressionWallTime = GetRegexNum "^real", 0,"([0-9.]+)","$regression_output";
363 } else {
364   $RegressionTestResults = "Skipped by user choice.";
365   $RegressionTime     = "0.0";
366   $RegressionWallTime = "0.0";
367 }
368
369 if ($DEBUG) {
370   print $FeatureTestResults;
371   print $RegressionTestResults;
372 }
373
374 if ( $VERBOSE ) { print "BUILD INFORMATION COLLECTION STAGE\n"; }
375 #
376 # Get warnings from the build
377 #
378 my @Warn = split "\n", `egrep 'warning:|Entering dir' $Prefix-Build-Log.txt`;
379 my @Warnings;
380 my $CurDir = "";
381
382 foreach $Warning (@Warn) {
383   if ($Warning =~ m/Entering directory \`([^\`]+)\'/) {
384     $CurDir = $1;                 # Keep track of directory warning is in...
385     if ($CurDir =~ m#$BuildDir/llvm/(.*)#) { # Remove buildir prefix if included
386       $CurDir = $1;
387     }
388   } else {
389     push @Warnings, "$CurDir/$Warning";     # Add directory to warning...
390   }
391 }
392 my $WarningsFile =  join "\n", @Warnings;
393 my $WarningsList = AddPreTag $WarningsFile;
394 $WarningsFile =~ s/:[0-9]+:/::/g;
395
396 # Emit the warnings file, so we can diff...
397 WriteFile "$WebDir/$DATE-Warnings.txt", $WarningsFile . "\n";
398 my ($WarningsAdded, $WarningsRemoved) = DiffFiles "-Warnings.txt";
399
400 # Output something to stdout if something has changed
401 print "ADDED   WARNINGS:\n$WarningsAdded\n\n" if (length $WarningsAdded);
402 print "REMOVED WARNINGS:\n$WarningsRemoved\n\n" if (length $WarningsRemoved);
403
404 $WarningsAdded = AddPreTag $WarningsAdded;
405 $WarningsRemoved = AddPreTag $WarningsRemoved;
406
407 #
408 # Get some statistics about CVS commits over the current day...
409 #
410 if ($VERBOSE) { print "CVS HISTORY ANALYSIS STAGE\n"; }
411 @CVSHistory = split "\n", `cvs history -D '1 day ago' -a -xAMROCGUW`;
412 #print join "\n", @CVSHistory; print "\n";
413
414 # Extract some information from the CVS history... use a hash so no duplicate
415 # stuff is stored.
416 my (%AddedFiles, %ModifiedFiles, %RemovedFiles, %UsersCommitted, %UsersUpdated);
417
418 my $DateRE = "[-:0-9 ]+\\+[0-9]+";
419
420 # Loop over every record from the CVS history, filling in the hashes.
421 foreach $File (@CVSHistory) {
422   my ($Type, $Date, $UID, $Rev, $Filename);
423   if ($File =~ /([AMRUGC]) ($DateRE) ([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+)/) {
424     ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, $4, "$6/$5");
425   } elsif ($File =~ /([W]) ($DateRE) ([^ ]+)/) {
426     ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", "");
427   } elsif ($File =~ /([O]) ($DateRE) ([^ ]+) +([^ ]+)/) {
428     ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", "$4/");
429   } else {
430     print "UNMATCHABLE: $File\n";
431   }
432   # print "$File\nTy = $Type Date = '$Date' UID=$UID Rev=$Rev File = '$Filename'\n";
433
434   if ($Filename =~ /^llvm/) {
435     if ($Type eq 'M') {        # Modified
436       $ModifiedFiles{$Filename} = 1;
437       $UsersCommitted{$UID} = 1;
438     } elsif ($Type eq 'A') {   # Added
439       $AddedFiles{$Filename} = 1;
440       $UsersCommitted{$UID} = 1;
441     } elsif ($Type eq 'R') {   # Removed
442       $RemovedFiles{$Filename} = 1;
443       $UsersCommitted{$UID} = 1;
444     } else {
445       $UsersUpdated{$UID} = 1;
446     }
447   }
448 }
449
450 my $UserCommitList = join "\n", keys %UsersCommitted;
451 my $UserUpdateList = join "\n", keys %UsersUpdated;
452 my $AddedFilesList = AddPreTag join "\n", sort keys %AddedFiles;
453 my $ModifiedFilesList = AddPreTag join "\n", sort keys %ModifiedFiles;
454 my $RemovedFilesList = AddPreTag join "\n", sort keys %RemovedFiles;
455
456 my $TestError = 1;
457 my $SingleSourceProgramsTable;
458 my $MultiSourceProgramsTable;
459 my $ExternalProgramsTable;
460
461
462 sub TestDirectory {
463   my $SubDir = shift;
464
465   chdir "test/Programs/$SubDir" or
466     die "Could not change into test/Programs/$SubDir testdir!";
467
468   # Run the programs tests... creating a report.nightly.html file
469   if (!$NOTEST) {
470     system "gmake -k $MAKEOPTS $ENABLELINEARSCAN report.nightly.html "
471          . "TEST=nightly > $Prefix-$SubDir-ProgramTest.txt 2>&1";
472   } else {
473     system "gunzip $Prefix-$SubDir-ProgramTest.txt.gz";
474   }
475
476   my $ProgramsTable;
477   if (`grep '^gmake[^:]: .*Error' $Prefix-$SubDir-ProgramTest.txt | wc -l` + 0){
478     $TestError = 1;
479     $ProgramsTable = "<font color=white><h2>Error running tests!</h2></font>";
480     print "ERROR TESTING\n";
481   } elsif (`grep '^gmake[^:]: .*No rule to make target' $Prefix-$SubDir-ProgramTest.txt | wc -l` + 0) {
482     $TestError = 1;
483     $ProgramsTable =
484       "<font color=white><h2>Makefile error running tests!</h2></font>";
485     print "ERROR TESTING\n";
486   } else {
487     $TestError = 0;
488     $ProgramsTable = ReadFile "report.nightly.html";
489
490     #
491     # Create a list of the tests which were run...
492     #
493     system "egrep 'TEST-(PASS|FAIL)' < $Prefix-$SubDir-ProgramTest.txt "
494          . "| sort > $Prefix-$SubDir-Tests.txt";
495   }
496
497   # Compress the test output
498   system "gzip -f $Prefix-$SubDir-ProgramTest.txt";
499   chdir "../../.." or die "Cannot return to parent directory!";
500   return $ProgramsTable;
501 }
502
503 # If we build the tree successfully, run the nightly programs tests...
504 if ($BuildError eq "") {
505   if ( $VERBOSE ) {
506     print "SingleSource TEST STAGE\n";
507   }
508   $SingleSourceProgramsTable = TestDirectory("SingleSource");
509   if ( $VERBOSE ) {
510     print "MultiSource TEST STAGE\n";
511   }
512   $MultiSourceProgramsTable = TestDirectory("MultiSource");
513   if ( $VERBOSE ) {
514     print "External TEST STAGE\n";
515   }
516   $ExternalProgramsTable = TestDirectory("External");
517   system "cat $Prefix-SingleSource-Tests.txt $Prefix-MultiSource-Tests.txt ".
518          " $Prefix-External-Tests.txt | sort > $Prefix-Tests.txt";
519 }
520
521 if ( $VERBOSE ) {
522   print "TEST INFORMATION COLLECTION STAGE\n";
523 }
524 my ($TestsAdded, $TestsRemoved, $TestsFixed, $TestsBroken) = ("","","","");
525
526 if ($TestError) {
527   $TestsAdded   = "<b>error testing</b><br>";
528   $TestsRemoved = "<b>error testing</b><br>";
529   $TestsFixed   = "<b>error testing</b><br>";
530   $TestsBroken  = "<b>error testing</b><br>";
531 } else {
532   my ($RTestsAdded, $RTestsRemoved) = DiffFiles "-Tests.txt";
533
534   my @RawTestsAddedArray = split '\n', $RTestsAdded;
535   my @RawTestsRemovedArray = split '\n', $RTestsRemoved;
536
537   my %OldTests = map {GetRegex('TEST-....: (.+)', $_)=>$_}
538     @RawTestsRemovedArray;
539   my %NewTests = map {GetRegex('TEST-....: (.+)', $_)=>$_}
540     @RawTestsAddedArray;
541
542   foreach $Test (keys %NewTests) {
543     if (!exists $OldTests{$Test}) {  # TestAdded if in New but not old
544       $TestsAdded = "$TestsAdded$Test\n";
545     } else {
546       if ($OldTests{$Test} =~ /TEST-PASS/) {  # Was the old one a pass?
547         $TestsBroken = "$TestsBroken$Test\n";  # New one must be a failure
548       } else {
549         $TestsFixed = "$TestsFixed$Test\n";    # No, new one is a pass.
550       }
551     }
552   }
553   foreach $Test (keys %OldTests) {  # TestRemoved if in Old but not New
554     $TestsRemoved = "$TestsRemoved$Test\n" if (!exists $NewTests{$Test});
555   }
556
557   print "\nTESTS ADDED:  \n\n$TestsAdded\n\n"   if (length $TestsAdded);
558   print "\nTESTS REMOVED:\n\n$TestsRemoved\n\n" if (length $TestsRemoved);
559   print "\nTESTS FIXED:  \n\n$TestsFixed\n\n"   if (length $TestsFixed);
560   print "\nTESTS BROKEN: \n\n$TestsBroken\n\n"  if (length $TestsBroken);
561
562   $TestsAdded   = AddPreTag $TestsAdded;
563   $TestsRemoved = AddPreTag $TestsRemoved;
564   $TestsFixed   = AddPreTag $TestsFixed;
565   $TestsBroken  = AddPreTag $TestsBroken;
566 }
567
568
569 # If we built the tree successfully, runs of the Olden suite with
570 # LARGE_PROBLEM_SIZE on so that we can get some "running" statistics.
571 if ($BuildError eq "") {
572   my ($NATTime, $CBETime, $LLCTime, $JITTime, $OptTime, $BytecodeSize,
573       $MachCodeSize) = ("","","","","","","");
574   if (!$NORUNNINGTESTS) {
575     chdir "test/Programs/MultiSource/Benchmarks/Olden" or die "Olden tests moved?";
576
577     # Clean out previous results...
578     system "gmake $MAKEOPTS clean > /dev/null 2>&1";
579
580     # Run the nightly test in this directory, with LARGE_PROBLEM_SIZE enabled!
581     system "gmake -k $MAKEOPTS report.nightly.raw.out TEST=nightly " .
582            " LARGE_PROBLEM_SIZE=1 > /dev/null 2>&1";
583     system "cp report.nightly.raw.out $Prefix-Olden-tests.txt";
584   } else {
585     system "gunzip $Prefix-Olden-tests.txt.gz";
586   }
587
588   # Now we know we have $Prefix-Olden-tests.txt as the raw output file.  Split
589   # it up into records and read the useful information.
590   my @Records = split />>> ========= /, ReadFile "$Prefix-Olden-tests.txt";
591   shift @Records;  # Delete the first (garbage) record
592
593   # Loop over all of the records, summarizing them into rows for the running
594   # totals file.
595   my $WallTimeRE = "[A-Za-z0-9.: ]+\\(([0-9.]+) wall clock";
596   foreach $Rec (@Records) {
597     my $rNATTime = GetRegex 'TEST-RESULT-nat-time: real\s*([.0-9m]+)', $Rec;
598     my $rCBETime = GetRegex 'TEST-RESULT-cbe-time: real\s*([.0-9m]+)', $Rec;
599     my $rLLCTime = GetRegex 'TEST-RESULT-llc-time: real\s*([.0-9m]+)', $Rec;
600     my $rJITTime = GetRegex 'TEST-RESULT-jit-time: real\s*([.0-9m]+)', $Rec;
601     my $rOptTime = GetRegex "TEST-RESULT-compile: $WallTimeRE", $Rec;
602     my $rBytecodeSize = GetRegex 'TEST-RESULT-compile: *([0-9]+)', $Rec;
603     my $rMachCodeSize = GetRegex 'TEST-RESULT-jit-machcode: *([0-9]+).*bytes of machine code', $Rec;
604
605     $NATTime .= " " . FormatTime($rNATTime);
606     $CBETime .= " " . FormatTime($rCBETime);
607     $LLCTime .= " " . FormatTime($rLLCTime);
608     $JITTime .= " " . FormatTime($rJITTime);
609     $OptTime .= " $rOptTime";
610     $BytecodeSize .= " $rBytecodeSize";
611     $MachCodeSize .= " $rMachCodeSize";
612   }
613
614   # Now that we have all of the numbers we want, add them to the running totals
615   # files.
616   AddRecord($NATTime, "running_Olden_nat_time.txt");
617   AddRecord($CBETime, "running_Olden_cbe_time.txt");
618   AddRecord($LLCTime, "running_Olden_llc_time.txt");
619   AddRecord($JITTime, "running_Olden_jit_time.txt");
620   AddRecord($OptTime, "running_Olden_opt_time.txt");
621   AddRecord($BytecodeSize, "running_Olden_bytecode.txt");
622   AddRecord($MachCodeSize, "running_Olden_machcode.txt");
623
624   system "gzip -f $Prefix-Olden-tests.txt";
625 }
626
627
628
629
630 #
631 # Get a list of the previous days that we can link to...
632 #
633 my @PrevDays = map {s/.html//; $_} GetDir ".html";
634
635 splice @PrevDays, 20;  # Trim down list to something reasonable...
636
637 my $PrevDaysList =     # Format list for sidebar
638   join "\n  ", map { "<a href=\"$_.html\">$_</a><br>" } @PrevDays;
639
640 #
641 # Start outputing files into the web directory
642 #
643 chdir $WebDir or die "Could not change into web directory!";
644
645 # Add information to the files which accumulate information for graphs...
646 AddRecord($LOC, "running_loc.txt");
647 AddRecord($BuildTime, "running_build_time.txt");
648
649 if ( $VERBOSE ) {
650   print "GRAPH GENERATION STAGE\n";
651 }
652 #
653 # Rebuild the graphs now...
654 #
655 $GNUPLOT = "/usr/dcs/software/supported/bin/gnuplot";
656 $GNUPLOT = "gnuplot" if ! -x $GNUPLOT;
657 $PlotScriptFilename = "$BuildDir/llvm/utils/NightlyTest.gnuplot";
658 system ($GNUPLOT, $PlotScriptFilename);
659
660 #
661 # Remove the cvs tree...
662 #
663 system "rm -rf $BuildDir" if (!$NOCHECKOUT and !$NOREMOVE);
664
665 #
666 # Print out information...
667 #
668 if ($VERBOSE) {
669   print "DateString: $DateString\n";
670   print "CVS Checkout: $CVSCheckoutTime seconds\n";
671   print "Files/Dirs/LOC in CVS: $NumFilesInCVS/$NumDirsInCVS/$LOC\n";
672   print "Build Time: $BuildTime seconds\n";
673   print "Feature Test Time: $FeatureTime seconds\n";
674   print "Regression Test Time: $RegressionTime seconds\n";
675   print "Libraries/Executables/Objects built: $NumLibraries/$NumExecutables/$NumObjects\n";
676
677   print "WARNINGS:\n  $WarningsList\n";
678
679   print "Users committed: $UserCommitList\n";
680   print "Added Files: \n  $AddedFilesList\n";
681   print "Modified Files: \n  $ModifiedFilesList\n";
682   print "Removed Files: \n  $RemovedFilesList\n";
683
684   print "Previous Days =\n  $PrevDaysList\n";
685 }
686
687
688 #
689 # Output the files...
690 #
691
692 if ( $VERBOSE ) {
693   print "OUTPUT STAGE\n";
694 }
695 # Main HTML file...
696 my $Output;
697 eval "\$Output = <<ENDOFFILE;$TemplateContents\nENDOFFILE\n";
698 WriteFile "$DATE.html", $Output;
699
700 # Change the index.html symlink...
701 system "ln -sf $DATE.html index.html";
702
703 sub AddRecord {
704   my ($Val, $Filename) = @_;
705   my @Records;
706   if (open FILE, "$WebDir/$Filename") {
707     @Records = grep !/$DATE/, split "\n", <FILE>;
708     close FILE;
709   }
710   push @Records, "$DATE: $Val";
711   WriteFile "$WebDir/$Filename", (join "\n", @Records) . "\n";
712   return @Records;
713 }