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