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