Use and print out BuildStatus, we don't always have build errors.
[oota-llvm.git] / utils / NightlyTest.pl
1 #!/usr/bin/perl -w
2 #
3 # Program:  NightlyTest.pl
4 #
5 # Synopsis: Perform a series of tests which are designed to be run nightly.
6 #           This is used to keep track of the status of the LLVM tree, tracking
7 #           regressions and performance changes.  This generates one web page a
8 #           day which can be used to access this information.
9 #
10 # Syntax:   NightlyTest.pl [OPTIONS] [CVSROOT BUILDDIR WEBDIR]
11 #   where
12 # OPTIONS may include one or more of the following:
13 #  -nocheckout      Do not create, checkout, update, or configure
14 #                   the source tree.
15 #  -noremove        Do not remove the BUILDDIR after it has been built.
16 #  -notest          Do not even attempt to run the test programs. Implies
17 #                   -norunningtests.
18 #  -norunningtests  Do not run the Olden benchmark suite with
19 #                   LARGE_PROBLEM_SIZE enabled.
20 #  -noexternals     Do not run the external tests (for cases where povray
21 #                   or SPEC are not installed)
22 #  -nodejagnu       Do not run feature or regression tests
23 #  -parallel        Run two parallel jobs with GNU Make.
24 #  -release         Build an LLVM Release version
25 #  -pedantic        Enable additional GCC warnings to detect possible errors.
26 #  -enable-linscan  Enable linearscan tests
27 #  -disable-llc     Disable LLC tests in the nightly tester.
28 #  -disable-jit     Disable 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 #  -f2c             Next argument specifies path to F2C utility
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 will be created if it does not exist.
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 use File::Copy;
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 $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 = "";
82 my $NICE = "";
83 my $NODEJAGNU = 0;
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 Touch {
113   my @files = @_;
114   my $now = time;
115   foreach my $file (@files) {
116     if (! -f $file) {
117       open (FILE, ">$file") or warn "Could not create new file $file";
118       close FILE;
119     }
120     utime $now, $now, $file;
121   }
122 }
123
124 sub AddRecord {
125   my ($Val, $Filename) = @_;
126   my @Records;
127   if (open FILE, "$WebDir/$Filename") {
128     @Records = grep !/$DATE/, split "\n", <FILE>;
129     close FILE;
130   }
131   push @Records, "$DATE: $Val";
132   WriteFile "$WebDir/$Filename", (join "\n", @Records) . "\n";
133 }
134
135 sub AddPreTag {  # Add pre tags around nonempty list, or convert to "none"
136   $_ = shift;
137   if (length) { return "<ul><pre>$_</pre></ul>"; } else { "<b>none</b><br>"; }
138 }
139
140 sub ChangeDir { # directory, logical name
141   my ($dir,$name) = @_;
142   chomp($dir);
143   if ( $VERBOSE ) { print "Changing To: $name ($dir)\n"; }
144   chdir($dir) || die "Cannot change directory to: $name ($dir) ";
145 }
146
147 sub CopyFile { #filename, newfile
148   my ($file, $newfile) = @_;
149   chomp($file);
150   if ($VERBOSE) { print "Copying $file to $newfile\n"; }
151   copy($file, $newfile);
152 }
153
154 sub GetDir {
155   my $Suffix = shift;
156   opendir DH, $WebDir;
157   my @Result = reverse sort grep !/$DATE/, grep /[-0-9]+$Suffix/, readdir DH;
158   closedir DH;
159   return @Result;
160 }
161
162 # DiffFiles - Diff the current version of the file against the last version of
163 # the file, reporting things added and removed.  This is used to report, for
164 # example, added and removed warnings.  This returns a pair (added, removed)
165 #
166 sub DiffFiles {
167   my $Suffix = shift;
168   my @Others = GetDir $Suffix;
169   if (@Others == 0) {  # No other files?  We added all entries...
170     return (`cat $WebDir/$DATE$Suffix`, "");
171   }
172   # Diff the files now...
173   my @Diffs = split "\n", `diff $WebDir/$DATE$Suffix $WebDir/$Others[0]`;
174   my $Added   = join "\n", grep /^</, @Diffs;
175   my $Removed = join "\n", grep /^>/, @Diffs;
176   $Added =~ s/^< //gm;
177   $Removed =~ s/^> //gm;
178   return ($Added, $Removed);
179 }
180
181 # FormatTime - Convert a time from 1m23.45 into 83.45
182 sub FormatTime {
183   my $Time = shift;
184   if ($Time =~ m/([0-9]+)m([0-9.]+)/) {
185     $Time = sprintf("%7.4f", $1*60.0+$2);
186   }
187   return $Time;
188 }
189
190 sub GetRegexNum {
191   my ($Regex, $Num, $Regex2, $File) = @_;
192   my @Items = split "\n", `grep '$Regex' $File`;
193   return GetRegex $Regex2, $Items[$Num];
194 }
195
196 sub GetDejagnuTestResults { # (filename, log)
197   my ($filename, $DejagnuLog) = @_;
198   my @lines;
199   my $firstline;
200   $/ = "\n"; #Make sure we're going line at a time.
201   if (open SRCHFILE, $filename) {
202     # Process test results
203     push(@lines,"<h3>UNEXPECTED TEST RESULTS</h3><ol><li>\n");
204     my $first_list = 1;
205     my $should_break = 1;
206     my $nocopy = 0;
207     my $readingsum = 0;
208     while ( <SRCHFILE> ) {
209       if ( length($_) > 1 ) { 
210         chomp($_);
211         if ( m/^XPASS:/ || m/^FAIL:/ ) {
212           $nocopy = 0;
213           if ( $first_list ) {
214             $first_list = 0;
215             $should_break = 1;
216             push(@lines,"<b>$_</b><br/>\n");
217           } else {
218             push(@lines,"</li><li><b>$_</b><br/>\n");
219           }
220         } elsif ( m/Summary/ ) {
221           if ( $first_list ) { push(@lines,"<b>PERFECT!</b>"); }
222           push(@lines,"</li></ol><h3>STATISTICS</h3><pre>\n");
223           $should_break = 0;
224           $nocopy = 0;
225           $readingsum = 1;
226         } elsif ( $readingsum ) {
227           push(@lines,"$_\n");
228         }
229       }
230     }
231   }
232   push(@lines, "</pre>\n");
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 (/^-notest$/)         { $NOTEST = 1; $NORUNNINGTESTS = 1; next; }
256   if (/^-norunningtests$/) { $NORUNNINGTESTS = 1; next; }
257   if (/^-parallel$/)       { $MAKEOPTS = "$MAKEOPTS -j2 -l3.0"; next; }
258   if (/^-release$/)        { $MAKEOPTS = "$MAKEOPTS ENABLE_OPTIMIZED=1"; next; }
259   if (/^-pedantic$/)       { 
260       $MAKEOPTS   = "$MAKEOPTS CompileOptimizeOpts='-O3 -DNDEBUG -finline-functions -Wpointer-arith -Wcast-align -Wno-deprecated -Wold-style-cast -Wabi -Woverloaded-virtual -ffor-scope'"; 
261       next; 
262   }
263   if (/^-enable-llcbeta$/) { $PROGTESTOPTS .= " ENABLE_LLCBETA=1"; next; }
264   if (/^-disable-llc$/)    { $PROGTESTOPTS .= " DISABLE_LLC=1";
265                              $CONFIGUREARGS .= " --disable-llc_diffs"; next; }
266   if (/^-disable-jit$/)    { $PROGTESTOPTS .= " DISABLE_JIT=1";
267                              $CONFIGUREARGS .= " --disable-jit"; next; }
268   if (/^-verbose$/)        { $VERBOSE = 1; next; }
269   if (/^-debug$/)          { $DEBUG = 1; next; }
270   if (/^-nice$/)           { $NICE = "nice "; next; }
271   if (/^-f2c$/)            {
272     $CONFIGUREARGS .= " --with-f2c=$ARGV[0]"; shift; next;
273   }
274   if (/^-gnuplotscript$/)  { $PlotScriptFilename = $ARGV[0]; shift; next; }
275   if (/^-templatefile$/)   { $Template = $ARGV[0]; shift; next; }
276   if (/^-gccpath/)         { 
277     $CONFIGUREARGS .= " CC=$ARGV[0]/gcc CXX=$ARGV[0]/g++"; shift; next; 
278   }
279   if (/^-noexternals$/)    { $NOEXTERNALS = 1; next; }
280   if(/^-nodejagnu$/) { $NODEJAGNU = 1; next; }
281
282   print "Unknown option: $_ : ignoring!\n";
283 }
284
285 if ($ENV{'LLVMGCCDIR'}) {
286   $CONFIGUREARGS .= " --with-llvmgccdir=" . $ENV{'LLVMGCCDIR'};
287 }
288 if ($CONFIGUREARGS !~ /--disable-jit/) {
289   $CONFIGUREARGS .= " --enable-jit";
290 }
291
292 die "Must specify 0 or 3 options!" if (@ARGV != 0 and @ARGV != 3);
293
294 if (@ARGV == 3) {
295   $CVSRootDir = $ARGV[0];
296   $BuildDir   = $ARGV[1];
297   $WebDir     = $ARGV[2];
298 }
299
300 my $Prefix = "$WebDir/$DATE";
301
302 #define the file names we'll use
303 my $BuildLog = "$Prefix-Build-Log.txt";
304 my $CVSLog = "$Prefix-CVS-Log.txt";
305 my $OldenTestsLog = "$Prefix-Olden-tests.txt";
306 my $SingleSourceLog = "$Prefix-SingleSource-ProgramTest.txt.gz";
307 my $MultiSourceLog = "$Prefix-MultiSource-ProgramTest.txt.gz";
308 my $ExternalLog = "$Prefix-External-ProgramTest.txt.gz";
309 my $DejagnuLog = "$Prefix-Dejagnu-testrun.log";
310 my $DejagnuSum = "$Prefix-Dejagnu-testrun.sum";
311 my $DejagnuTestsLog = "$Prefix-DejagnuTests-Log.txt";
312
313 if ($VERBOSE) {
314   print "INITIALIZED\n";
315   print "CVS Root = $CVSRootDir\n";
316   print "BuildDir = $BuildDir\n";
317   print "WebDir   = $WebDir\n";
318   print "Prefix   = $Prefix\n";
319   print "CVSLog   = $CVSLog\n";
320   print "BuildLog = $BuildLog\n";
321 }
322
323 if (! -d $WebDir) {
324   mkdir $WebDir, 0777;
325   warn "Warning: $WebDir did not exist; creating it.\n";
326 }
327
328 #
329 # Create the CVS repository directory
330 #
331 if (!$NOCHECKOUT) {
332   if (-d $BuildDir) {
333     if (!$NOREMOVE) {
334       system "rm -rf $BuildDir"; 
335     } else {
336        die "CVS checkout directory $BuildDir already exists!";
337     }
338   }
339   mkdir $BuildDir or die "Could not create CVS checkout directory $BuildDir!";
340 }
341
342 ChangeDir( $BuildDir, "CVS checkout directory" );
343
344
345 #
346 # Check out the llvm tree, saving CVS messages to the cvs log...
347 #
348 $CVSOPT = "";
349 $CVSOPT = "-z3" if $CVSRootDir =~ /^:ext:/; # Use compression if going over ssh.
350 if (!$NOCHECKOUT) {
351   if ( $VERBOSE ) { print "CHECKOUT STAGE\n"; }
352   system "( time -p $NICE cvs $CVSOPT -d $CVSRootDir co -APR llvm; cd llvm/projects ; " .
353      "$NICE cvs $CVSOPT -d $CVSRootDir co -APR llvm-test ) > $CVSLog 2>&1";
354   ChangeDir( $BuildDir , "CVS Checkout directory") ;
355 }
356
357 ChangeDir( "llvm" , "llvm source directory") ;
358
359 if (!$NOCHECKOUT) {
360   if ( $VERBOSE ) { print "UPDATE STAGE\n"; }
361   system "$NICE cvs update -PdRA >> $CVSLog 2>&1" ;
362 }
363
364 if ( $Template eq "" ) {
365   $Template = "$BuildDir/llvm/utils/NightlyTestTemplate.html";
366 }
367 die "Template file $Template is not readable" if ( ! -r "$Template" );
368
369 if ( $PlotScriptFilename eq "" ) {
370   $PlotScriptFilename = "$BuildDir/llvm/utils/NightlyTest.gnuplot";
371 }
372 die "GNUPlot Script $PlotScriptFilename is not readable" if ( ! -r "$PlotScriptFilename" );
373
374 # Read in the HTML template file...
375 if ( $VERBOSE ) { print "READING TEMPLATE\n"; }
376 my $TemplateContents = ReadFile $Template;
377
378 #
379 # Get some static statistics about the current state of CVS
380 #
381 my $CVSCheckoutTime = GetRegex "([0-9.]+)", `grep '^real' $CVSLog`;
382 my $NumFilesInCVS = `egrep '^U' $CVSLog | wc -l` + 0;
383 my $NumDirsInCVS  = `egrep '^cvs (checkout|server|update):' $CVSLog | wc -l` + 0;
384 $LOC = `utils/countloc.sh`;
385
386 #
387 # Build the entire tree, saving build messages to the build log
388 #
389 if (!$NOCHECKOUT) {
390   if ( $VERBOSE ) { print "CONFIGURE STAGE\n"; }
391   system "(time -p $NICE ./configure $CONFIGUREARGS --enable-spec --with-objroot=.) > $BuildLog 2>&1";
392
393   if ( $VERBOSE ) { print "BUILD STAGE\n"; }
394   # Build the entire tree, capturing the output into $BuildLog
395   system "(time -p $NICE gmake $MAKEOPTS) >> $BuildLog 2>&1";
396 }
397
398
399 #
400 # Get some statistics about the build...
401 #
402 my @Linked = split '\n', `grep Linking $BuildLog`;
403 my $NumExecutables = scalar(grep(/executable/, @Linked));
404 my $NumLibraries   = scalar(grep(!/executable/, @Linked));
405 my $NumObjects     = `grep '^Compiling' $BuildLog | wc -l` + 0;
406
407 my $ConfigTimeU = GetRegexNum "^user", 0, "([0-9.]+)", "$BuildLog";
408 my $ConfigTimeS = GetRegexNum "^sys", 0, "([0-9.]+)", "$BuildLog";
409 my $ConfigTime  = $ConfigTimeU+$ConfigTimeS;  # ConfigTime = User+System
410 my $ConfigWallTime = GetRegexNum "^real", 0,"([0-9.]+)","$BuildLog";
411
412 my $BuildTimeU = GetRegexNum "^user", 1, "([0-9.]+)", "$BuildLog";
413 my $BuildTimeS = GetRegexNum "^sys", 1, "([0-9.]+)", "$BuildLog";
414 my $BuildTime  = $BuildTimeU+$BuildTimeS;  # BuildTime = User+System
415 my $BuildWallTime = GetRegexNum "^real", 1, "([0-9.]+)","$BuildLog";
416
417 my $BuildError = 0, $BuildStatus = "OK";
418 if (`grep '^gmake[^:]*: .*Error' $BuildLog | wc -l` + 0 ||
419     `grep '^gmake: \*\*\*.*Stop.' $BuildLog | wc -l`+0) {
420   $BuildStatus = "<h3><font color='red'>error: compilation " .
421                 "<a href=\"$DATE-Build-Log.txt\">aborted</a></font></h3>";
422   $BuildError = 1;
423   if ($VERBOSE) { print "BUILD ERROR\n"; }
424 }
425
426 if ($BuildError) { $NODEJAGNU=1; }
427
428 my $DejangnuTestResults; # String containing the results of the dejagnu
429 if(!$NODEJAGNU) {
430   if($VERBOSE) { print "DEJAGNU FEATURE/REGRESSION TEST STAGE\n"; }
431   
432   my $dejagnu_output = "$DejagnuTestsLog";
433   
434   #Run the feature and regression tests, results are put into testrun.sum
435   #Full log in testrun.log
436   system "(time -p gmake $MAKEOPTS check) > $dejagnu_output 2>&1";
437
438   #Extract time of dejagnu tests
439   my $DejagnuTimeU = GetRegexNum "^user", 0, "([0-9.]+)", "$dejagnu_output";
440   my $DejagnuTimeS = GetRegexNum "^sys", 0, "([0-9.]+)", "$dejagnu_output";
441   $DejagnuTime  = $DejagnuTimeU+$DejagnuTimeS;  # DejagnuTime = User+System
442   $DejagnuWallTime = GetRegexNum "^real", 0,"([0-9.]+)","$dejagnu_output";
443
444   #Copy the testrun.log and testrun.sum to our webdir
445   CopyFile("test/testrun.log", $DejagnuLog);
446   CopyFile("test/testrun.sum", $DejagnuSum);
447
448   $DejagnuTestResults = GetDejagnuTestResults($DejagnuSum, $DejagnuLog);
449   print $DejagnuTestResults;
450
451 } else {
452   $DejagnuTestResults = "Skipped by user choice.";
453   $DejagnuTime     = "0.0";
454   $DejagnuWallTime = "0.0";
455 }
456
457 if ($DEBUG) {
458   print $DejagnuTestResults;
459 }
460
461 if ( $VERBOSE ) { print "BUILD INFORMATION COLLECTION STAGE\n"; }
462 #
463 # Get warnings from the build
464 #
465 my @Warn = split "\n", `egrep 'warning:|Entering dir' $BuildLog`;
466 my @Warnings;
467 my $CurDir = "";
468
469 foreach $Warning (@Warn) {
470   if ($Warning =~ m/Entering directory \`([^\`]+)\'/) {
471     $CurDir = $1;                 # Keep track of directory warning is in...
472     if ($CurDir =~ m#$BuildDir/llvm/(.*)#) { # Remove buildir prefix if included
473       $CurDir = $1;
474     }
475   } else {
476     push @Warnings, "$CurDir/$Warning";     # Add directory to warning...
477   }
478 }
479 my $WarningsFile =  join "\n", @Warnings;
480 my $WarningsList = AddPreTag $WarningsFile;
481 $WarningsFile =~ s/:[0-9]+:/::/g;
482
483 # Emit the warnings file, so we can diff...
484 WriteFile "$WebDir/$DATE-Warnings.txt", $WarningsFile . "\n";
485 my ($WarningsAdded, $WarningsRemoved) = DiffFiles "-Warnings.txt";
486
487 # Output something to stdout if something has changed
488 print "ADDED   WARNINGS:\n$WarningsAdded\n\n" if (length $WarningsAdded);
489 print "REMOVED WARNINGS:\n$WarningsRemoved\n\n" if (length $WarningsRemoved);
490
491 $WarningsAdded = AddPreTag $WarningsAdded;
492 $WarningsRemoved = AddPreTag $WarningsRemoved;
493
494 #
495 # Get some statistics about CVS commits over the current day...
496 #
497 if ($VERBOSE) { print "CVS HISTORY ANALYSIS STAGE\n"; }
498 @CVSHistory = split "\n", `cvs history -D '1 day ago' -a -xAMROCGUW`;
499 #print join "\n", @CVSHistory; print "\n";
500
501 # Extract some information from the CVS history... use a hash so no duplicate
502 # stuff is stored.
503 my (%AddedFiles, %ModifiedFiles, %RemovedFiles, %UsersCommitted, %UsersUpdated);
504
505 my $DateRE = '[-/:0-9 ]+\+[0-9]+';
506
507 # Loop over every record from the CVS history, filling in the hashes.
508 foreach $File (@CVSHistory) {
509   my ($Type, $Date, $UID, $Rev, $Filename);
510   if ($File =~ /([AMRUGC]) ($DateRE) ([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+)/) {
511     ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, $4, "$6/$5");
512   } elsif ($File =~ /([W]) ($DateRE) ([^ ]+)/) {
513     ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", "");
514   } elsif ($File =~ /([O]) ($DateRE) ([^ ]+) +([^ ]+)/) {
515     ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", "$4/");
516   } else {
517     print "UNMATCHABLE: $File\n";
518     next;
519   }
520   # print "$File\nTy = $Type Date = '$Date' UID=$UID Rev=$Rev File = '$Filename'\n";
521
522   if ($Filename =~ /^llvm/) {
523     if ($Type eq 'M') {        # Modified
524       $ModifiedFiles{$Filename} = 1;
525       $UsersCommitted{$UID} = 1;
526     } elsif ($Type eq 'A') {   # Added
527       $AddedFiles{$Filename} = 1;
528       $UsersCommitted{$UID} = 1;
529     } elsif ($Type eq 'R') {   # Removed
530       $RemovedFiles{$Filename} = 1;
531       $UsersCommitted{$UID} = 1;
532     } else {
533       $UsersUpdated{$UID} = 1;
534     }
535   }
536 }
537
538 my $UserCommitList = join "\n", keys %UsersCommitted;
539 my $UserUpdateList = join "\n", keys %UsersUpdated;
540 my $AddedFilesList = AddPreTag join "\n", sort keys %AddedFiles;
541 my $ModifiedFilesList = AddPreTag join "\n", sort keys %ModifiedFiles;
542 my $RemovedFilesList = AddPreTag join "\n", sort keys %RemovedFiles;
543
544 my $TestError = 1;
545 my $SingleSourceProgramsTable = "!";
546 my $MultiSourceProgramsTable = "!";
547 my $ExternalProgramsTable = "!";
548
549
550 sub TestDirectory {
551   my $SubDir = shift;
552
553   ChangeDir( "projects/llvm-test/$SubDir", "Programs Test Subdirectory" );
554
555   my $ProgramTestLog = "$Prefix-$SubDir-ProgramTest.txt";
556
557   # Run the programs tests... creating a report.nightly.html file
558   if (!$NOTEST) {
559     system "gmake -k $MAKEOPTS $PROGTESTOPTS report.nightly.html "
560          . "TEST=nightly > $ProgramTestLog 2>&1";
561   } else {
562     system "gunzip ${ProgramTestLog}.gz";
563   }
564
565   my $ProgramsTable;
566   if (`grep '^gmake[^:]: .*Error' $ProgramTestLog | wc -l` + 0){
567     $TestError = 1;
568     $ProgramsTable = "<font color=white><h2>Error running tests!</h2></font>";
569     print "ERROR TESTING\n";
570   } elsif (`grep '^gmake[^:]: .*No rule to make target' $ProgramTestLog | wc -l` + 0) {
571     $TestError = 1;
572     $ProgramsTable =
573       "<font color=white><h2>Makefile error running tests!</h2></font>";
574     print "ERROR TESTING\n";
575   } else {
576     $TestError = 0;
577     $ProgramsTable = ReadFile "report.nightly.html";
578
579     #
580     # Create a list of the tests which were run...
581     #
582     system "egrep 'TEST-(PASS|FAIL)' < $ProgramTestLog "
583          . "| sort > $Prefix-$SubDir-Tests.txt";
584   }
585
586   # Compress the test output
587   system "gzip -f $ProgramTestLog";
588   ChangeDir( "../../..", "Programs Test Parent Directory" );
589   return $ProgramsTable;
590 }
591
592 # If we built the tree successfully, run the nightly programs tests...
593 if (!$BuildError) {
594   if ( $VERBOSE ) {
595     print "SingleSource TEST STAGE\n";
596   }
597   $SingleSourceProgramsTable = TestDirectory("SingleSource");
598   if ( $VERBOSE ) {
599     print "MultiSource TEST STAGE\n";
600   }
601   $MultiSourceProgramsTable = TestDirectory("MultiSource");
602   if ( ! $NOEXTERNALS ) {
603     if ( $VERBOSE ) {
604       print "External TEST STAGE\n";
605     }
606     $ExternalProgramsTable = TestDirectory("External");
607     system "cat $Prefix-SingleSource-Tests.txt $Prefix-MultiSource-Tests.txt ".
608          " $Prefix-External-Tests.txt | sort > $Prefix-Tests.txt";
609   } else {
610     $ExternalProgramsTable = '<tr><td>External TEST STAGE SKIPPED</td></tr>';
611     if ( $VERBOSE ) {
612       print "External TEST STAGE SKIPPED\n";
613     }
614     system "cat $Prefix-SingleSource-Tests.txt $Prefix-MultiSource-Tests.txt ".
615          " | sort > $Prefix-Tests.txt";
616   }
617 }
618
619 if ( $VERBOSE ) { print "TEST INFORMATION COLLECTION STAGE\n"; }
620 my ($TestsAdded, $TestsRemoved, $TestsFixed, $TestsBroken) = ("","","","");
621
622 if ($TestError) {
623   $TestsAdded   = "<b>error testing</b><br>";
624   $TestsRemoved = "<b>error testing</b><br>";
625   $TestsFixed   = "<b>error testing</b><br>";
626   $TestsBroken  = "<b>error testing</b><br>";
627 } else {
628   my ($RTestsAdded, $RTestsRemoved) = DiffFiles "-Tests.txt";
629
630   my @RawTestsAddedArray = split '\n', $RTestsAdded;
631   my @RawTestsRemovedArray = split '\n', $RTestsRemoved;
632
633   my %OldTests = map {GetRegex('TEST-....: (.+)', $_)=>$_}
634     @RawTestsRemovedArray;
635   my %NewTests = map {GetRegex('TEST-....: (.+)', $_)=>$_}
636     @RawTestsAddedArray;
637
638   foreach $Test (keys %NewTests) {
639     if (!exists $OldTests{$Test}) {  # TestAdded if in New but not old
640       $TestsAdded = "$TestsAdded$Test\n";
641     } else {
642       if ($OldTests{$Test} =~ /TEST-PASS/) {  # Was the old one a pass?
643         $TestsBroken = "$TestsBroken$Test\n";  # New one must be a failure
644       } else {
645         $TestsFixed = "$TestsFixed$Test\n";    # No, new one is a pass.
646       }
647     }
648   }
649   foreach $Test (keys %OldTests) {  # TestRemoved if in Old but not New
650     $TestsRemoved = "$TestsRemoved$Test\n" if (!exists $NewTests{$Test});
651   }
652
653   print "\nTESTS ADDED:  \n\n$TestsAdded\n\n"   if (length $TestsAdded);
654   print "\nTESTS REMOVED:\n\n$TestsRemoved\n\n" if (length $TestsRemoved);
655   print "\nTESTS FIXED:  \n\n$TestsFixed\n\n"   if (length $TestsFixed);
656   print "\nTESTS BROKEN: \n\n$TestsBroken\n\n"  if (length $TestsBroken);
657
658   $TestsAdded   = AddPreTag $TestsAdded;
659   $TestsRemoved = AddPreTag $TestsRemoved;
660   $TestsFixed   = AddPreTag $TestsFixed;
661   $TestsBroken  = AddPreTag $TestsBroken;
662 }
663
664
665 # If we built the tree successfully, runs of the Olden suite with
666 # LARGE_PROBLEM_SIZE on so that we can get some "running" statistics.
667 if (!$BuildError) {
668   if ( $VERBOSE ) { print "OLDEN TEST SUITE STAGE\n"; }
669   my ($NATTime, $CBETime, $LLCTime, $JITTime, $OptTime, $BytecodeSize,
670       $MachCodeSize) = ("","","","","","","");
671   if (!$NORUNNINGTESTS) {
672     ChangeDir( "$BuildDir/llvm/projects/llvm-test/MultiSource/Benchmarks/Olden",
673       "Olden Test Directory");
674
675     # Clean out previous results...
676     system "$NICE gmake $MAKEOPTS clean > /dev/null 2>&1";
677
678     # Run the nightly test in this directory, with LARGE_PROBLEM_SIZE and
679     # GET_STABLE_NUMBERS enabled!
680     system "gmake -k $MAKEOPTS $PROGTESTOPTS report.nightly.raw.out TEST=nightly " .
681            " LARGE_PROBLEM_SIZE=1 GET_STABLE_NUMBERS=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 = "Time: ([0-9.]+) seconds \\([0-9.]+ wall clock";
695   foreach $Rec (@Records) {
696     my $rNATTime = GetRegex 'TEST-RESULT-nat-time: program\s*([.0-9m]+)', $Rec;
697     my $rCBETime = GetRegex 'TEST-RESULT-cbe-time: program\s*([.0-9m]+)', $Rec;
698     my $rLLCTime = GetRegex 'TEST-RESULT-llc-time: program\s*([.0-9m]+)', $Rec;
699     my $rJITTime = GetRegex 'TEST-RESULT-jit-time: program\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 outputting files into the web directory
741 #
742 ChangeDir( $WebDir, "Web Directory" );
743
744 # Make sure we don't get errors running the nightly tester the first time
745 # because of files that don't exist.
746 Touch ('running_build_time.txt', 'running_Olden_llc_time.txt',
747        'running_loc.txt', 'running_Olden_machcode.txt',
748        'running_Olden_bytecode.txt', 'running_Olden_nat_time.txt',
749        'running_Olden_cbe_time.txt', 'running_Olden_opt_time.txt',
750        'running_Olden_jit_time.txt');
751
752 # Add information to the files which accumulate information for graphs...
753 AddRecord($LOC, "running_loc.txt");
754 AddRecord($BuildTime, "running_build_time.txt");
755
756 if ( $VERBOSE ) {
757   print "GRAPH GENERATION STAGE\n";
758 }
759 #
760 # Rebuild the graphs now...
761 #
762 $GNUPLOT = "/usr/bin/gnuplot";
763 $GNUPLOT = "gnuplot" if ! -x $GNUPLOT;
764 system ("$GNUPLOT", $PlotScriptFilename);
765
766 #
767 # Remove the cvs tree...
768 #
769 system ( "$NICE rm -rf $BuildDir") if (!$NOCHECKOUT and !$NOREMOVE);
770
771 #
772 # Print out information...
773 #
774 if ($VERBOSE) {
775   print "DateString: $DateString\n";
776   print "CVS Checkout: $CVSCheckoutTime seconds\n";
777   print "Files/Dirs/LOC in CVS: $NumFilesInCVS/$NumDirsInCVS/$LOC\n";
778   print "Build Time: $BuildTime seconds\n";
779   print "Libraries/Executables/Objects built: $NumLibraries/$NumExecutables/$NumObjects\n";
780
781   print "WARNINGS:\n  $WarningsList\n";
782
783   print "Users committed: $UserCommitList\n";
784   print "Added Files: \n  $AddedFilesList\n";
785   print "Modified Files: \n  $ModifiedFilesList\n";
786   print "Removed Files: \n  $RemovedFilesList\n";
787
788   print "Previous Days =\n  $PrevDaysList\n";
789 }
790
791
792 #
793 # Output the files...
794 #
795
796 if ( $VERBOSE ) {
797   print "OUTPUT STAGE\n";
798 }
799 # Main HTML file...
800 my $Output;
801 my $TestFinishTime = gmtime;
802 my $TestPlatform = `uname -a`;
803 eval "\$Output = <<ENDOFFILE;$TemplateContents\nENDOFFILE\n";
804 WriteFile "$DATE.html", $Output;
805 system ( "ln -sf $DATE.html index.html" );
806
807 # Change the index.html symlink...
808
809 # vim: sw=2 ai