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