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