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 <CVSRootDir> <BuildDir> <WebDir>
12 use POSIX qw(strftime);
14 my $HOME = $ENV{HOME};
15 my $CVSRootDir = "/home/vadve/vadve/Research/DynOpt/CVSRepository";
16 my $BuildDir = "$HOME/buildtest";
17 my $WebDir = "$HOME/cvs/testresults-X86";
19 # Calculate the date prefix...
21 my $DATE = sprintf "%4d-%02d-%02d", $TIME[5]+1900, $TIME[4]+1, $TIME[3];
22 my $DateString = strftime "%B %d, %Y", localtime;
26 if (open (FILE, $_[0])) {
31 print "Could not open file '$_[0]' for reading!";
36 sub WriteFile { # (filename, contents)
37 open (FILE, ">$_[0]") or die "Could not open file '$_[0]' for writing!";
42 sub GetRegex { # (Regex with ()'s, value)
50 sub AddPreTag { # Add pre tags around nonempty list, or convert to "none"
52 if (length) { return "<ul><pre>$_</pre></ul>"; } else { "<b>none</b><br>"; }
58 my @Result = reverse sort grep !/$DATE/, grep /[-0-9]+$Suffix/, readdir DH;
63 # DiffFiles - Diff the current version of the file against the last version of
64 # the file, reporting things added and removed. This is used to report, for
65 # example, added and removed warnings. This returns a pair (added, removed)
69 my @Others = GetDir $Suffix;
70 if (@Others == 0) { # No other files? We added all entries...
71 return (`cat $WebDir/$DATE$Suffix`, "");
73 # Diff the files now...
74 my @Diffs = split "\n", `diff $WebDir/$DATE$Suffix $WebDir/$Others[0]`;
75 my $Added = join "\n", grep /^</, @Diffs;
76 my $Removed = join "\n", grep /^>/, @Diffs;
78 $Removed =~ s/^> //gm;
79 return ($Added, $Removed);
82 # FormatTime - Convert a time from 1m23.45 into 83.45
85 if ($Time =~ m/([0-9]+)m([0-9.]+)/) {
86 $Time = sprintf("%7.4f", $1*60.0+$2);
92 # Command line argument settings...
96 my $NORUNNINGTESTS = 0;
100 while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
102 last if /^--$/; # Stop processing arguments on --
104 # List command line options here...
105 if (/^-nocheckout$/) { $NOCHECKOUT = 1; next; }
106 if (/^-noremove$/) { $NOREMOVE = 1; next; }
107 if (/^-notest$/) { $NOTEST = 1; $NORUNNINGTESTS = 1; next; }
108 if (/^-norunningtests$/) { $NORUNNINGTESTS = 1; next; }
109 if (/^-parallel$/) { $MAKEOPTS = "-j2 -l3.0"; next; }
111 print "Unknown option: $_ : ignoring!\n";
114 die "Must specify 0 or 3 options!" if (@ARGV != 0 and @ARGV != 3);
117 $CVSRootDir = $ARGV[0];
118 $BuildDir = $ARGV[1];
122 my $Template = "$BuildDir/llvm/utils/NightlyTestTemplate.html";
123 my $Prefix = "$WebDir/$DATE";
126 print "CVS Root = $CVSRootDir\n";
127 print "BuildDir = $BuildDir\n";
128 print "WebDir = $WebDir\n";
129 print "Prefix = $Prefix\n";
134 # Create the CVS repository directory
137 mkdir $BuildDir or die "Could not create CVS checkout directory $BuildDir!";
139 chdir $BuildDir or die "Could not change to CVS checkout directory $BuildDir!";
143 # Check out the llvm tree, saving CVS messages to the cvs log...
145 system "(time -p cvs -d $CVSRootDir co llvm) > $Prefix-CVS-Log.txt 2>&1"
148 chdir "llvm" or die "Could not change into llvm directory!";
150 system "cvs up -P -d > /dev/null 2>&1" if (!$NOCHECKOUT);
152 # Read in the HTML template file...
153 my $TemplateContents = ReadFile $Template;
157 # Get some static statistics about the current state of CVS
159 my $CVSCheckoutTime = GetRegex "([0-9.]+)", `grep '^real' $Prefix-CVS-Log.txt`;
160 my $NumFilesInCVS = `grep '^U' $Prefix-CVS-Log.txt | wc -l` + 0;
161 my $NumDirsInCVS = `grep '^cvs checkout' $Prefix-CVS-Log.txt | wc -l` + 0;
162 $LOC = GetRegex "([0-9]+) +total", `wc -l \`utils/getsrcs.sh\` | grep total`;
165 # Build the entire tree, saving build messages to the build log
168 system "(time -p ./configure --enable-jit --enable-spec --with-objroot=.) > $Prefix-Build-Log.txt 2>&1";
170 # Build the entire tree, capturing the output into $Prefix-Build-Log.txt
171 system "(time -p gmake $MAKEOPTS) >> $Prefix-Build-Log.txt 2>&1";
176 my ($Regex, $Num, $Regex2, $File) = @_;
177 my @Items = split "\n", `grep '$Regex' $File`;
178 return GetRegex $Regex2, $Items[$Num];
182 # Get some statistics about the build...
184 my @Linked = split '\n', `grep Linking $Prefix-Build-Log.txt`;
185 my $NumExecutables = scalar(grep(/executable/, @Linked));
186 my $NumLibraries = scalar(grep(!/executable/, @Linked));
187 my $NumObjects = `grep '^Compiling' $Prefix-Build-Log.txt | wc -l` + 0;
189 my $ConfigTimeU = GetRegexNum "^user", 0, "([0-9.]+)", "$Prefix-Build-Log.txt";
190 my $ConfigTimeS = GetRegexNum "^sys", 0, "([0-9.]+)", "$Prefix-Build-Log.txt";
191 my $ConfigTime = $ConfigTimeU+$ConfigTimeS; # ConfigTime = User+System
192 my $ConfigWallTime = GetRegexNum "^real", 0,"([0-9.]+)","$Prefix-Build-Log.txt";
194 my $BuildTimeU = GetRegexNum "^user", 1, "([0-9.]+)", "$Prefix-Build-Log.txt";
195 my $BuildTimeS = GetRegexNum "^sys", 1, "([0-9.]+)", "$Prefix-Build-Log.txt";
196 my $BuildTime = $BuildTimeU+$BuildTimeS; # BuildTime = User+System
197 my $BuildWallTime = GetRegexNum "^real", 1, "([0-9.]+)","$Prefix-Build-Log.txt";
200 if (`grep '^gmake[^:]*: .*Error' $Prefix-Build-Log.txt | wc -l` + 0) {
201 $BuildError = "<h3><font color='red'>Build error: compilation " .
202 "<a href=\"$DATE-Build-Log.txt\">aborted</a></font></h3>";
206 # Get warnings from the build
208 my @Warn = split "\n", `egrep 'warning:|Entering dir' $Prefix-Build-Log.txt`;
212 foreach $Warning (@Warn) {
213 if ($Warning =~ m/Entering directory \`([^\`]+)\'/) {
214 $CurDir = $1; # Keep track of directory warning is in...
215 if ($CurDir =~ m#$BuildDir/llvm/(.*)#) { # Remove buildir prefix if included
219 push @Warnings, "$CurDir/$Warning"; # Add directory to warning...
222 my $WarningsFile = join "\n", @Warnings;
223 my $WarningsList = AddPreTag $WarningsFile;
224 $WarningsFile =~ s/:[0-9]+:/::/g;
226 # Emit the warnings file, so we can diff...
227 WriteFile "$WebDir/$DATE-Warnings.txt", $WarningsFile . "\n";
228 my ($WarningsAdded, $WarningsRemoved) = DiffFiles "-Warnings.txt";
229 $WarningsAdded = AddPreTag $WarningsAdded;
230 $WarningsRemoved = AddPreTag $WarningsRemoved;
234 # Get some statistics about CVS commits over the current day...
236 @CVSHistory = split "\n", `cvs history -D '1 day ago' -a -xAMROCGUW`;
237 #print join "\n", @CVSHistory; print "\n";
239 # Extract some information from the CVS history... use a hash so no duplicate
241 my (%AddedFiles, %ModifiedFiles, %RemovedFiles, %UsersCommitted, %UsersUpdated);
243 my $DateRE = "[-:0-9 ]+\\+[0-9]+";
245 # Loop over every record from the CVS history, filling in the hashes.
246 foreach $File (@CVSHistory) {
247 my ($Type, $Date, $UID, $Rev, $Filename);
248 if ($File =~ /([AMRUGC]) ($DateRE) ([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+)/) {
249 ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, $4, "$6/$5");
250 } elsif ($File =~ /([W]) ($DateRE) ([^ ]+) +([^ ]+) +([^ ]+)/) {
251 ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, $4, "$6/$5");
252 } elsif ($File =~ /([O]) ($DateRE) ([^ ]+) +([^ ]+)/) {
253 ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", "$4/");
255 print "UNMATCHABLE: $File\n";
257 # print "$File\nTy = $Type Date = '$Date' UID=$UID Rev=$Rev File = '$Filename'\n";
259 if ($Filename =~ /^llvm/) {
260 if ($Type eq 'M') { # Modified
261 $ModifiedFiles{$Filename} = 1;
262 $UsersCommitted{$UID} = 1;
263 } elsif ($Type eq 'A') { # Added
264 $AddedFiles{$Filename} = 1;
265 $UsersCommitted{$UID} = 1;
266 } elsif ($Type eq 'R') { # Removed
267 $RemovedFiles{$Filename} = 1;
268 $UsersCommitted{$UID} = 1;
270 $UsersUpdated{$UID} = 1;
275 my $UserCommitList = join "\n", keys %UsersCommitted;
276 my $UserUpdateList = join "\n", keys %UsersUpdated;
277 my $AddedFilesList = AddPreTag join "\n", sort keys %AddedFiles;
278 my $ModifiedFilesList = AddPreTag join "\n", sort keys %ModifiedFiles;
279 my $RemovedFilesList = AddPreTag join "\n", sort keys %RemovedFiles;
282 my $SingleSourceProgramsTable;
283 my $MultiSourceProgramsTable;
284 my $ExternalProgramsTable;
290 chdir "test/Programs/$SubDir" or
291 die "Could not change into test/Programs/$SubDir testdir!";
293 # Run the programs tests... creating a report.nightly.html file
295 system "gmake $MAKEOPTS report.nightly.html TEST=nightly "
296 . "> $Prefix-$SubDir-ProgramTest.txt 2>&1";
298 system "gunzip $Prefix-$SubDir-ProgramTest.txt.gz";
302 if (`grep '^gmake[^:]: .*Error' $Prefix-$SubDir-ProgramTest.txt | wc -l` + 0){
304 $ProgramsTable = "<font color=white><h2>Error running tests!</h2></font>";
305 } elsif (`grep '^gmake[^:]: .*No rule to make target' $Prefix-$SubDir-ProgramTest.txt | wc -l` + 0) {
308 "<font color=white><h2>Makefile error running tests!</h2></font>";
311 $ProgramsTable = ReadFile "report.nightly.html";
314 # Create a list of the tests which were run...
316 system "egrep 'TEST-(PASS|FAIL)' < $Prefix-$SubDir-ProgramTest.txt "
317 . "| sort > $Prefix-$SubDir-Tests.txt";
320 # Compress the test output
321 system "gzip -f $Prefix-$SubDir-ProgramTest.txt";
322 chdir "../../.." or die "Cannot return to parent directory!";
323 return $ProgramsTable;
326 # If we build the tree successfully, run the nightly programs tests...
327 if ($BuildError eq "") {
328 $SingleSourceProgramsTable = TestDirectory("SingleSource");
329 $MultiSourceProgramsTable = TestDirectory("MultiSource");
330 $ExternalProgramsTable = TestDirectory("External");
331 system "cat $Prefix-SingleSource-Tests.txt $Prefix-MultiSource-Tests.txt ".
332 " $Prefix-External-Tests.txt | sort > $Prefix-Tests.txt";
335 my ($TestsAdded, $TestsRemoved, $TestsFixed, $TestsBroken) = ("","","","");
338 $TestsAdded = "<b>error testing</b><br>";
339 $TestsRemoved = "<b>error testing</b><br>";
340 $TestsFixed = "<b>error testing</b><br>";
341 $TestsBroken = "<b>error testing</b><br>";
343 my ($RTestsAdded, $RTestsRemoved) = DiffFiles "-Tests.txt";
345 my @RawTestsAddedArray = split '\n', $RTestsAdded;
346 my @RawTestsRemovedArray = split '\n', $RTestsRemoved;
348 my %OldTests = map {GetRegex('TEST-....: (.+)', $_)=>$_}
349 @RawTestsRemovedArray;
350 my %NewTests = map {GetRegex('TEST-....: (.+)', $_)=>$_}
353 foreach $Test (keys %NewTests) {
354 if (!exists $OldTests{$Test}) { # TestAdded if in New but not old
355 $TestsAdded = "$TestsAdded$Test\n";
357 if ($OldTests{$Test} =~ /TEST-PASS/) { # Was the old one a pass?
358 $TestsBroken = "$TestsBroken$Test\n"; # New one must be a failure
360 $TestsFixed = "$TestsFixed$Test\n"; # No, new one is a pass.
364 foreach $Test (keys %OldTests) { # TestRemoved if in Old but not New
365 $TestsRemoved = "$TestsRemoved$Test\n" if (!exists $NewTests{$Test});
368 $TestsAdded = AddPreTag $TestsAdded;
369 $TestsRemoved = AddPreTag $TestsRemoved;
370 $TestsFixed = AddPreTag $TestsFixed;
371 $TestsBroken = AddPreTag $TestsBroken;
374 # If we built the tree successfully, runs of the Olden suite with
375 # LARGE_PROBLEM_SIZE on so that we can get some "running" statistics.
376 if ($BuildError eq "") {
377 my ($NATTime, $CBETime, $LLCTime, $JITTime, $OptTime, $BytecodeSize,
378 $MachCodeSize) = ("","","","","","","");
379 if (!$NORUNNINGTESTS) {
380 chdir "test/Programs/MultiSource/Olden" or die "Olden tests moved?";
382 # Clean out previous results...
383 system "gmake $MAKEOPTS clean > /dev/null 2>&1";
385 # Run the nightly test in this directory, with LARGE_PROBLEM_SIZE enabled!
386 system "gmake $MAKEOPTS report.nightly.raw.out TEST=nightly " .
387 " LARGE_PROBLEM_SIZE=1 > /dev/null 2>&1";
388 system "cp report.nightly.raw.out $Prefix-Olden-tests.txt";
390 system "gunzip $Prefix-Olden-tests.txt.gz";
393 # Now we know we have $Prefix-Olden-tests.txt as the raw output file. Split
394 # it up into records and read the useful information.
395 my @Records = split />>> ========= /, ReadFile "$Prefix-Olden-tests.txt";
396 shift @Records; # Delete the first (garbage) record
398 # Loop over all of the records, summarizing them into rows for the running
400 my $WallTimeRE = "[A-Za-z0-9.: ]+\\(([0-9.]+) wall clock";
401 foreach $Rec (@Records) {
402 my $rNATTime = GetRegex 'TEST-RESULT-nat-time: real\s*([.0-9m]+)', $Rec;
403 my $rCBETime = GetRegex 'TEST-RESULT-cbe-time: real\s*([.0-9m]+)', $Rec;
404 my $rLLCTime = GetRegex 'TEST-RESULT-llc-time: real\s*([.0-9m]+)', $Rec;
405 my $rJITTime = GetRegex 'TEST-RESULT-jit-time: real\s*([.0-9m]+)', $Rec;
406 my $rOptTime = GetRegex "TEST-RESULT-compile: $WallTimeRE", $Rec;
407 my $rBytecodeSize = GetRegex 'TEST-RESULT-compile: *([0-9]+)', $Rec;
408 my $rMachCodeSize = GetRegex 'TEST-RESULT-jit-machcode: *([0-9]+).*bytes of machine code', $Rec;
410 $NATTime .= " " . FormatTime($rNATTime);
411 $CBETime .= " " . FormatTime($rCBETime);
412 $LLCTime .= " " . FormatTime($rLLCTime);
413 $JITTime .= " " . FormatTime($rJITTime);
414 $OptTime .= " $rOptTime";
415 $BytecodeSize .= " $rBytecodeSize";
416 $MachCodeSize .= " $rMachCodeSize";
419 # Now that we have all of the numbers we want, add them to the running totals
421 AddRecord($NATTime, "running_Olden_nat_time.txt");
422 AddRecord($CBETime, "running_Olden_cbe_time.txt");
423 AddRecord($LLCTime, "running_Olden_llc_time.txt");
424 AddRecord($JITTime, "running_Olden_jit_time.txt");
425 AddRecord($OptTime, "running_Olden_opt_time.txt");
426 AddRecord($BytecodeSize, "running_Olden_bytecode.txt");
427 AddRecord($MachCodeSize, "running_Olden_machcode.txt");
429 system "gzip -f $Prefix-Olden-tests.txt";
436 # Get a list of the previous days that we can link to...
438 my @PrevDays = map {s/.html//; $_} GetDir ".html";
440 splice @PrevDays, 20; # Trim down list to something reasonable...
442 my $PrevDaysList = # Format list for sidebar
443 join "\n ", map { "<a href=\"$_.html\">$_</a><br>" } @PrevDays;
446 # Start outputing files into the web directory
448 chdir $WebDir or die "Could not change into web directory!";
450 # Add information to the files which accumulate information for graphs...
451 AddRecord($LOC, "running_loc.txt");
452 AddRecord($BuildTime, "running_build_time.txt");
455 # Rebuild the graphs now...
457 system "/usr/dcs/software/supported/bin/gnuplot " .
458 "$BuildDir/llvm/utils/NightlyTest.gnuplot";
461 # Remove the cvs tree...
463 system "rm -rf $BuildDir" if (!$NOCHECKOUT and !$NOREMOVE);
468 # Print out information...
471 print "DateString: $DateString\n";
472 print "CVS Checkout: $CVSCheckoutTime seconds\n";
473 print "Files/Dirs/LOC in CVS: $NumFilesInCVS/$NumDirsInCVS/$LOC\n";
475 print "Build Time: $BuildTime seconds\n";
476 print "Libraries/Executables/Objects built: $NumLibraries/$NumExecutables/$NumObjects\n";
478 print "WARNINGS:\n $WarningsList\n";
481 print "Users committed: $UserCommitList\n";
482 print "Added Files: \n $AddedFilesList\n";
483 print "Modified Files: \n $ModifiedFilesList\n";
484 print "Removed Files: \n $RemovedFilesList\n";
486 print "Previous Days =\n $PrevDaysList\n";
491 # Output the files...
496 eval "\$Output = <<ENDOFFILE;$TemplateContents\nENDOFFILE\n";
497 WriteFile "$DATE.html", $Output;
499 # Change the index.html symlink...
500 system "ln -sf $DATE.html index.html";
503 my ($Val, $Filename) = @_;
505 if (open FILE, "$WebDir/$Filename") {
506 @Records = grep !/$DATE/, split "\n", <FILE>;
509 push @Records, "$DATE: $Val";
510 WriteFile "$WebDir/$Filename", (join "\n", @Records) . "\n";