1 #!/usr/dcs/software/supported/bin/perl -w
3 # Program: NightlyTest.pl
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.
10 # Syntax: NightlyTest.pl [OPTIONS] [CVSROOT BUILDDIR WEBDIR]
12 # OPTIONS may include one or more of the following:
13 # -nocheckout Do not create, checkout, update, or configure
15 # -noremove Do not remove the BUILDDIR after it has been built.
16 # -notest Do not even attempt to run the test programs. Implies
18 # -norunningtests Do not run the Olden benchmark suite with
19 # LARGE_PROBLEM_SIZE enabled.
20 # -parallel Run two parallel jobs with GNU Make.
21 # CVSROOT is the CVS repository from which the tree will be checked out,
22 # specified either in the full :method:user@host:/dir syntax, or
23 # just /dir if using a local repo.
24 # BUILDDIR is the directory where sources for this test run will be checked out
25 # AND objects for this test run will be built. This directory MUST NOT
26 # exist before the script is run; it will be created by the cvs checkout
27 # process and erased (unless -noremove is specified; see above.)
28 # WEBDIR is the directory into which the test results web page will be written,
29 # AND in which the "index.html" is assumed to be a symlink to the most recent
30 # copy of the results. This directory MUST exist before the script is run.
32 use POSIX qw(strftime);
34 my $HOME = $ENV{'HOME'};
35 my $CVSRootDir = $ENV{'CVSROOT'};
36 my $CVSRootDir = "/home/vadve/shared/PublicCVS"
38 my $BuildDir = "$HOME/buildtest";
39 my $WebDir = "$HOME/cvs/testresults-X86";
41 # Calculate the date prefix...
43 my $DATE = sprintf "%4d-%02d-%02d", $TIME[5]+1900, $TIME[4]+1, $TIME[3];
44 my $DateString = strftime "%B %d, %Y", localtime;
48 if (open (FILE, $_[0])) {
53 print "Could not open file '$_[0]' for reading!";
58 sub WriteFile { # (filename, contents)
59 open (FILE, ">$_[0]") or die "Could not open file '$_[0]' for writing!";
64 sub GetRegex { # (Regex with ()'s, value)
72 sub AddPreTag { # Add pre tags around nonempty list, or convert to "none"
74 if (length) { return "<ul><pre>$_</pre></ul>"; } else { "<b>none</b><br>"; }
80 my @Result = reverse sort grep !/$DATE/, grep /[-0-9]+$Suffix/, readdir DH;
85 # DiffFiles - Diff the current version of the file against the last version of
86 # the file, reporting things added and removed. This is used to report, for
87 # example, added and removed warnings. This returns a pair (added, removed)
91 my @Others = GetDir $Suffix;
92 if (@Others == 0) { # No other files? We added all entries...
93 return (`cat $WebDir/$DATE$Suffix`, "");
95 # Diff the files now...
96 my @Diffs = split "\n", `diff $WebDir/$DATE$Suffix $WebDir/$Others[0]`;
97 my $Added = join "\n", grep /^</, @Diffs;
98 my $Removed = join "\n", grep /^>/, @Diffs;
100 $Removed =~ s/^> //gm;
101 return ($Added, $Removed);
104 # FormatTime - Convert a time from 1m23.45 into 83.45
107 if ($Time =~ m/([0-9]+)m([0-9.]+)/) {
108 $Time = sprintf("%7.4f", $1*60.0+$2);
114 # Command line argument settings...
118 my $NORUNNINGTESTS = 0;
123 while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
125 last if /^--$/; # Stop processing arguments on --
127 # List command line options here...
128 if (/^-nocheckout$/) { $NOCHECKOUT = 1; next; }
129 if (/^-noremove$/) { $NOREMOVE = 1; next; }
130 if (/^-notest$/) { $NOTEST = 1; $NORUNNINGTESTS = 1; next; }
131 if (/^-norunningtests$/) { $NORUNNINGTESTS = 1; next; }
132 if (/^-parallel$/) { $MAKEOPTS = "-j2 -l3.0"; next; }
134 print "Unknown option: $_ : ignoring!\n";
137 die "Must specify 0 or 3 options!" if (@ARGV != 0 and @ARGV != 3);
140 $CVSRootDir = $ARGV[0];
141 $BuildDir = $ARGV[1];
145 my $Template = "$BuildDir/llvm/utils/NightlyTestTemplate.html";
146 my $Prefix = "$WebDir/$DATE";
149 print "CVS Root = $CVSRootDir\n";
150 print "BuildDir = $BuildDir\n";
151 print "WebDir = $WebDir\n";
152 print "Prefix = $Prefix\n";
157 # Create the CVS repository directory
160 mkdir $BuildDir or die "Could not create CVS checkout directory $BuildDir!";
162 chdir $BuildDir or die "Could not change to CVS checkout directory $BuildDir!";
166 # Check out the llvm tree, saving CVS messages to the cvs log...
169 $CVSOPT = "-z3" if $CVSRootDir =~ /^:ext:/; # Use compression if going over ssh.
170 system "(time -p cvs $CVSOPT -d $CVSRootDir co llvm) > $Prefix-CVS-Log.txt 2>&1"
173 chdir "llvm" or die "Could not change into llvm directory!";
175 system "cvs up -P -d > /dev/null 2>&1" if (!$NOCHECKOUT);
177 # Read in the HTML template file...
178 my $TemplateContents = ReadFile $Template;
182 # Get some static statistics about the current state of CVS
184 my $CVSCheckoutTime = GetRegex "([0-9.]+)", `grep '^real' $Prefix-CVS-Log.txt`;
185 my $NumFilesInCVS = `grep '^U' $Prefix-CVS-Log.txt | wc -l` + 0;
186 my $NumDirsInCVS = `grep '^cvs checkout' $Prefix-CVS-Log.txt | wc -l` + 0;
187 $LOC = GetRegex "([0-9]+) +total", `wc -l \`utils/getsrcs.sh\` | grep total`;
190 # Build the entire tree, saving build messages to the build log
193 system "(time -p ./configure --enable-jit --enable-spec --with-objroot=.) > $Prefix-Build-Log.txt 2>&1";
195 # Build the entire tree, capturing the output into $Prefix-Build-Log.txt
196 system "(time -p gmake $MAKEOPTS) >> $Prefix-Build-Log.txt 2>&1";
201 my ($Regex, $Num, $Regex2, $File) = @_;
202 my @Items = split "\n", `grep '$Regex' $File`;
203 return GetRegex $Regex2, $Items[$Num];
207 # Get some statistics about the build...
209 my @Linked = split '\n', `grep Linking $Prefix-Build-Log.txt`;
210 my $NumExecutables = scalar(grep(/executable/, @Linked));
211 my $NumLibraries = scalar(grep(!/executable/, @Linked));
212 my $NumObjects = `grep '^Compiling' $Prefix-Build-Log.txt | wc -l` + 0;
214 my $ConfigTimeU = GetRegexNum "^user", 0, "([0-9.]+)", "$Prefix-Build-Log.txt";
215 my $ConfigTimeS = GetRegexNum "^sys", 0, "([0-9.]+)", "$Prefix-Build-Log.txt";
216 my $ConfigTime = $ConfigTimeU+$ConfigTimeS; # ConfigTime = User+System
217 my $ConfigWallTime = GetRegexNum "^real", 0,"([0-9.]+)","$Prefix-Build-Log.txt";
219 my $BuildTimeU = GetRegexNum "^user", 1, "([0-9.]+)", "$Prefix-Build-Log.txt";
220 my $BuildTimeS = GetRegexNum "^sys", 1, "([0-9.]+)", "$Prefix-Build-Log.txt";
221 my $BuildTime = $BuildTimeU+$BuildTimeS; # BuildTime = User+System
222 my $BuildWallTime = GetRegexNum "^real", 1, "([0-9.]+)","$Prefix-Build-Log.txt";
225 if (`grep '^gmake[^:]*: .*Error' $Prefix-Build-Log.txt | wc -l` + 0 ||
226 `grep '^gmake: \*\*\*.*Stop.' $Prefix-Build-Log.txt | wc -l`+0) {
227 $BuildError = "<h3><font color='red'>Build error: compilation " .
228 "<a href=\"$DATE-Build-Log.txt\">aborted</a></font></h3>";
232 # Get warnings from the build
234 my @Warn = split "\n", `egrep 'warning:|Entering dir' $Prefix-Build-Log.txt`;
238 foreach $Warning (@Warn) {
239 if ($Warning =~ m/Entering directory \`([^\`]+)\'/) {
240 $CurDir = $1; # Keep track of directory warning is in...
241 if ($CurDir =~ m#$BuildDir/llvm/(.*)#) { # Remove buildir prefix if included
245 push @Warnings, "$CurDir/$Warning"; # Add directory to warning...
248 my $WarningsFile = join "\n", @Warnings;
249 my $WarningsList = AddPreTag $WarningsFile;
250 $WarningsFile =~ s/:[0-9]+:/::/g;
252 # Emit the warnings file, so we can diff...
253 WriteFile "$WebDir/$DATE-Warnings.txt", $WarningsFile . "\n";
254 my ($WarningsAdded, $WarningsRemoved) = DiffFiles "-Warnings.txt";
255 $WarningsAdded = AddPreTag $WarningsAdded;
256 $WarningsRemoved = AddPreTag $WarningsRemoved;
260 # Get some statistics about CVS commits over the current day...
262 @CVSHistory = split "\n", `cvs history -D '1 day ago' -a -xAMROCGUW`;
263 #print join "\n", @CVSHistory; print "\n";
265 # Extract some information from the CVS history... use a hash so no duplicate
267 my (%AddedFiles, %ModifiedFiles, %RemovedFiles, %UsersCommitted, %UsersUpdated);
269 my $DateRE = "[-:0-9 ]+\\+[0-9]+";
271 # Loop over every record from the CVS history, filling in the hashes.
272 foreach $File (@CVSHistory) {
273 my ($Type, $Date, $UID, $Rev, $Filename);
274 if ($File =~ /([AMRUGC]) ($DateRE) ([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+)/) {
275 ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, $4, "$6/$5");
276 } elsif ($File =~ /([W]) ($DateRE) ([^ ]+) +([^ ]+) +([^ ]+)/) {
277 ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, $4, "$6/$5");
278 } elsif ($File =~ /([O]) ($DateRE) ([^ ]+) +([^ ]+)/) {
279 ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", "$4/");
281 print "UNMATCHABLE: $File\n";
283 # print "$File\nTy = $Type Date = '$Date' UID=$UID Rev=$Rev File = '$Filename'\n";
285 if ($Filename =~ /^llvm/) {
286 if ($Type eq 'M') { # Modified
287 $ModifiedFiles{$Filename} = 1;
288 $UsersCommitted{$UID} = 1;
289 } elsif ($Type eq 'A') { # Added
290 $AddedFiles{$Filename} = 1;
291 $UsersCommitted{$UID} = 1;
292 } elsif ($Type eq 'R') { # Removed
293 $RemovedFiles{$Filename} = 1;
294 $UsersCommitted{$UID} = 1;
296 $UsersUpdated{$UID} = 1;
301 my $UserCommitList = join "\n", keys %UsersCommitted;
302 my $UserUpdateList = join "\n", keys %UsersUpdated;
303 my $AddedFilesList = AddPreTag join "\n", sort keys %AddedFiles;
304 my $ModifiedFilesList = AddPreTag join "\n", sort keys %ModifiedFiles;
305 my $RemovedFilesList = AddPreTag join "\n", sort keys %RemovedFiles;
308 my $SingleSourceProgramsTable;
309 my $MultiSourceProgramsTable;
310 my $ExternalProgramsTable;
316 chdir "test/Programs/$SubDir" or
317 die "Could not change into test/Programs/$SubDir testdir!";
319 # Run the programs tests... creating a report.nightly.html file
321 system "gmake $MAKEOPTS report.nightly.html TEST=nightly "
322 . "> $Prefix-$SubDir-ProgramTest.txt 2>&1";
324 system "gunzip $Prefix-$SubDir-ProgramTest.txt.gz";
328 if (`grep '^gmake[^:]: .*Error' $Prefix-$SubDir-ProgramTest.txt | wc -l` + 0){
330 $ProgramsTable = "<font color=white><h2>Error running tests!</h2></font>";
331 } elsif (`grep '^gmake[^:]: .*No rule to make target' $Prefix-$SubDir-ProgramTest.txt | wc -l` + 0) {
334 "<font color=white><h2>Makefile error running tests!</h2></font>";
337 $ProgramsTable = ReadFile "report.nightly.html";
340 # Create a list of the tests which were run...
342 system "egrep 'TEST-(PASS|FAIL)' < $Prefix-$SubDir-ProgramTest.txt "
343 . "| sort > $Prefix-$SubDir-Tests.txt";
346 # Compress the test output
347 system "gzip -f $Prefix-$SubDir-ProgramTest.txt";
348 chdir "../../.." or die "Cannot return to parent directory!";
349 return $ProgramsTable;
352 # If we build the tree successfully, run the nightly programs tests...
353 if ($BuildError eq "") {
354 $SingleSourceProgramsTable = TestDirectory("SingleSource");
355 $MultiSourceProgramsTable = TestDirectory("MultiSource");
356 $ExternalProgramsTable = TestDirectory("External");
357 system "cat $Prefix-SingleSource-Tests.txt $Prefix-MultiSource-Tests.txt ".
358 " $Prefix-External-Tests.txt | sort > $Prefix-Tests.txt";
361 my ($TestsAdded, $TestsRemoved, $TestsFixed, $TestsBroken) = ("","","","");
364 $TestsAdded = "<b>error testing</b><br>";
365 $TestsRemoved = "<b>error testing</b><br>";
366 $TestsFixed = "<b>error testing</b><br>";
367 $TestsBroken = "<b>error testing</b><br>";
369 my ($RTestsAdded, $RTestsRemoved) = DiffFiles "-Tests.txt";
371 my @RawTestsAddedArray = split '\n', $RTestsAdded;
372 my @RawTestsRemovedArray = split '\n', $RTestsRemoved;
374 my %OldTests = map {GetRegex('TEST-....: (.+)', $_)=>$_}
375 @RawTestsRemovedArray;
376 my %NewTests = map {GetRegex('TEST-....: (.+)', $_)=>$_}
379 foreach $Test (keys %NewTests) {
380 if (!exists $OldTests{$Test}) { # TestAdded if in New but not old
381 $TestsAdded = "$TestsAdded$Test\n";
383 if ($OldTests{$Test} =~ /TEST-PASS/) { # Was the old one a pass?
384 $TestsBroken = "$TestsBroken$Test\n"; # New one must be a failure
386 $TestsFixed = "$TestsFixed$Test\n"; # No, new one is a pass.
390 foreach $Test (keys %OldTests) { # TestRemoved if in Old but not New
391 $TestsRemoved = "$TestsRemoved$Test\n" if (!exists $NewTests{$Test});
394 $TestsAdded = AddPreTag $TestsAdded;
395 $TestsRemoved = AddPreTag $TestsRemoved;
396 $TestsFixed = AddPreTag $TestsFixed;
397 $TestsBroken = AddPreTag $TestsBroken;
400 # If we built the tree successfully, runs of the Olden suite with
401 # LARGE_PROBLEM_SIZE on so that we can get some "running" statistics.
402 if ($BuildError eq "") {
403 my ($NATTime, $CBETime, $LLCTime, $JITTime, $OptTime, $BytecodeSize,
404 $MachCodeSize) = ("","","","","","","");
405 if (!$NORUNNINGTESTS) {
406 chdir "test/Programs/MultiSource/Benchmarks/Olden" or die "Olden tests moved?";
408 # Clean out previous results...
409 system "gmake $MAKEOPTS clean > /dev/null 2>&1";
411 # Run the nightly test in this directory, with LARGE_PROBLEM_SIZE enabled!
412 system "gmake $MAKEOPTS report.nightly.raw.out TEST=nightly " .
413 " LARGE_PROBLEM_SIZE=1 > /dev/null 2>&1";
414 system "cp report.nightly.raw.out $Prefix-Olden-tests.txt";
416 system "gunzip $Prefix-Olden-tests.txt.gz";
419 # Now we know we have $Prefix-Olden-tests.txt as the raw output file. Split
420 # it up into records and read the useful information.
421 my @Records = split />>> ========= /, ReadFile "$Prefix-Olden-tests.txt";
422 shift @Records; # Delete the first (garbage) record
424 # Loop over all of the records, summarizing them into rows for the running
426 my $WallTimeRE = "[A-Za-z0-9.: ]+\\(([0-9.]+) wall clock";
427 foreach $Rec (@Records) {
428 my $rNATTime = GetRegex 'TEST-RESULT-nat-time: real\s*([.0-9m]+)', $Rec;
429 my $rCBETime = GetRegex 'TEST-RESULT-cbe-time: real\s*([.0-9m]+)', $Rec;
430 my $rLLCTime = GetRegex 'TEST-RESULT-llc-time: real\s*([.0-9m]+)', $Rec;
431 my $rJITTime = GetRegex 'TEST-RESULT-jit-time: real\s*([.0-9m]+)', $Rec;
432 my $rOptTime = GetRegex "TEST-RESULT-compile: $WallTimeRE", $Rec;
433 my $rBytecodeSize = GetRegex 'TEST-RESULT-compile: *([0-9]+)', $Rec;
434 my $rMachCodeSize = GetRegex 'TEST-RESULT-jit-machcode: *([0-9]+).*bytes of machine code', $Rec;
436 $NATTime .= " " . FormatTime($rNATTime);
437 $CBETime .= " " . FormatTime($rCBETime);
438 $LLCTime .= " " . FormatTime($rLLCTime);
439 $JITTime .= " " . FormatTime($rJITTime);
440 $OptTime .= " $rOptTime";
441 $BytecodeSize .= " $rBytecodeSize";
442 $MachCodeSize .= " $rMachCodeSize";
445 # Now that we have all of the numbers we want, add them to the running totals
447 AddRecord($NATTime, "running_Olden_nat_time.txt");
448 AddRecord($CBETime, "running_Olden_cbe_time.txt");
449 AddRecord($LLCTime, "running_Olden_llc_time.txt");
450 AddRecord($JITTime, "running_Olden_jit_time.txt");
451 AddRecord($OptTime, "running_Olden_opt_time.txt");
452 AddRecord($BytecodeSize, "running_Olden_bytecode.txt");
453 AddRecord($MachCodeSize, "running_Olden_machcode.txt");
455 system "gzip -f $Prefix-Olden-tests.txt";
462 # Get a list of the previous days that we can link to...
464 my @PrevDays = map {s/.html//; $_} GetDir ".html";
466 splice @PrevDays, 20; # Trim down list to something reasonable...
468 my $PrevDaysList = # Format list for sidebar
469 join "\n ", map { "<a href=\"$_.html\">$_</a><br>" } @PrevDays;
472 # Start outputing files into the web directory
474 chdir $WebDir or die "Could not change into web directory!";
476 # Add information to the files which accumulate information for graphs...
477 AddRecord($LOC, "running_loc.txt");
478 AddRecord($BuildTime, "running_build_time.txt");
481 # Rebuild the graphs now...
483 $GNUPLOT = "/usr/dcs/software/supported/bin/gnuplot";
484 $GNUPLOT = "gnuplot" if ! -x $GNUPLOT;
485 $PlotScriptFilename = "$BuildDir/llvm/utils/NightlyTest.gnuplot";
486 system ($GNUPLOT, $PlotScriptFilename);
489 # Remove the cvs tree...
491 system "rm -rf $BuildDir" if (!$NOCHECKOUT and !$NOREMOVE);
494 # Print out information...
497 print "DateString: $DateString\n";
498 print "CVS Checkout: $CVSCheckoutTime seconds\n";
499 print "Files/Dirs/LOC in CVS: $NumFilesInCVS/$NumDirsInCVS/$LOC\n";
501 print "Build Time: $BuildTime seconds\n";
502 print "Libraries/Executables/Objects built: $NumLibraries/$NumExecutables/$NumObjects\n";
504 print "WARNINGS:\n $WarningsList\n";
506 print "Users committed: $UserCommitList\n";
507 print "Added Files: \n $AddedFilesList\n";
508 print "Modified Files: \n $ModifiedFilesList\n";
509 print "Removed Files: \n $RemovedFilesList\n";
511 print "Previous Days =\n $PrevDaysList\n";
516 # Output the files...
521 eval "\$Output = <<ENDOFFILE;$TemplateContents\nENDOFFILE\n";
522 WriteFile "$DATE.html", $Output;
524 # Change the index.html symlink...
525 system "ln -sf $DATE.html index.html";
528 my ($Val, $Filename) = @_;
530 if (open FILE, "$WebDir/$Filename") {
531 @Records = grep !/$DATE/, split "\n", <FILE>;
534 push @Records, "$DATE: $Val";
535 WriteFile "$WebDir/$Filename", (join "\n", @Records) . "\n";