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