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