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