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>Build error: compilation <a href=\"$DATE-Build-Log.txt\">"
202 . "aborted</a></h3>";
207 # Get warnings from the build
209 my @Warn = split "\n", `egrep 'warning:|Entering dir' $Prefix-Build-Log.txt`;
213 foreach $Warning (@Warn) {
214 if ($Warning =~ m/Entering directory \`([^\`]+)\'/) {
215 $CurDir = $1; # Keep track of directory warning is in...
216 if ($CurDir =~ m#$BuildDir/llvm/(.*)#) { # Remove buildir prefix if included
220 push @Warnings, "$CurDir/$Warning"; # Add directory to warning...
223 my $WarningsFile = join "\n", @Warnings;
224 my $WarningsList = AddPreTag $WarningsFile;
225 $WarningsFile =~ s/:[0-9]+:/::/g;
227 # Emit the warnings file, so we can diff...
228 WriteFile "$WebDir/$DATE-Warnings.txt", $WarningsFile . "\n";
229 my ($WarningsAdded, $WarningsRemoved) = DiffFiles "-Warnings.txt";
230 $WarningsAdded = AddPreTag $WarningsAdded;
231 $WarningsRemoved = AddPreTag $WarningsRemoved;
235 # Get some statistics about CVS commits over the current day...
237 @CVSHistory = split "\n", `cvs history -D '1 day ago' -a -xAMROCGUW`;
238 #print join "\n", @CVSHistory; print "\n";
240 # Extract some information from the CVS history... use a hash so no duplicate
242 my (%AddedFiles, %ModifiedFiles, %RemovedFiles, %UsersCommitted, %UsersUpdated);
244 my $DateRE = "[-:0-9 ]+\\+[0-9]+";
246 # Loop over every record from the CVS history, filling in the hashes.
247 foreach $File (@CVSHistory) {
248 my ($Type, $Date, $UID, $Rev, $Filename);
249 if ($File =~ /([AMRUGC]) ($DateRE) ([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+)/) {
250 ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, $4, "$6/$5");
251 } elsif ($File =~ /([W]) ($DateRE) ([^ ]+) +([^ ]+) +([^ ]+)/) {
252 ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, $4, "$6/$5");
253 } elsif ($File =~ /([O]) ($DateRE) ([^ ]+) +([^ ]+)/) {
254 ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", "$4/");
256 print "UNMATCHABLE: $File\n";
258 # print "$File\nTy = $Type Date = '$Date' UID=$UID Rev=$Rev File = '$Filename'\n";
260 if ($Filename =~ /^llvm/) {
261 if ($Type eq 'M') { # Modified
262 $ModifiedFiles{$Filename} = 1;
263 $UsersCommitted{$UID} = 1;
264 } elsif ($Type eq 'A') { # Added
265 $AddedFiles{$Filename} = 1;
266 $UsersCommitted{$UID} = 1;
267 } elsif ($Type eq 'R') { # Removed
268 $RemovedFiles{$Filename} = 1;
269 $UsersCommitted{$UID} = 1;
271 $UsersUpdated{$UID} = 1;
276 my $UserCommitList = join "\n", keys %UsersCommitted;
277 my $UserUpdateList = join "\n", keys %UsersUpdated;
278 my $AddedFilesList = AddPreTag join "\n", sort keys %AddedFiles;
279 my $ModifiedFilesList = AddPreTag join "\n", sort keys %ModifiedFiles;
280 my $RemovedFilesList = AddPreTag join "\n", sort keys %RemovedFiles;
283 my $SingleSourceProgramsTable;
284 my $MultiSourceProgramsTable;
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 system "cat $Prefix-SingleSource-Tests.txt $Prefix-MultiSource-Tests.txt ".
331 " | sort > $Prefix-Tests.txt";
334 my ($TestsAdded, $TestsRemoved, $TestsFixed, $TestsBroken) = ("","","","");
337 $TestsAdded = "<b>error testing</b><br>";
338 $TestsRemoved = "<b>error testing</b><br>";
339 $TestsFixed = "<b>error testing</b><br>";
340 $TestsBroken = "<b>error testing</b><br>";
342 my ($RTestsAdded, $RTestsRemoved) = DiffFiles "-Tests.txt";
344 my @RawTestsAddedArray = split '\n', $RTestsAdded;
345 my @RawTestsRemovedArray = split '\n', $RTestsRemoved;
347 my %OldTests = map {GetRegex('TEST-....: (.+)', $_)=>$_}
348 @RawTestsRemovedArray;
349 my %NewTests = map {GetRegex('TEST-....: (.+)', $_)=>$_}
352 foreach $Test (keys %NewTests) {
353 if (!exists $OldTests{$Test}) { # TestAdded if in New but not old
354 $TestsAdded = "$TestsAdded$Test\n";
356 if ($OldTests{$Test} =~ /TEST-PASS/) { # Was the old one a pass?
357 $TestsBroken = "$TestsBroken$Test\n"; # New one must be a failure
359 $TestsFixed = "$TestsFixed$Test\n"; # No, new one is a pass.
363 foreach $Test (keys %OldTests) { # TestRemoved if in Old but not New
364 $TestsRemoved = "$TestsRemoved$Test\n" if (!exists $NewTests{$Test});
367 $TestsAdded = AddPreTag $TestsAdded;
368 $TestsRemoved = AddPreTag $TestsRemoved;
369 $TestsFixed = AddPreTag $TestsFixed;
370 $TestsBroken = AddPreTag $TestsBroken;
373 # If we built the tree successfully, runs of the Olden suite with
374 # LARGE_PROBLEM_SIZE on so that we can get some "running" statistics.
375 if ($BuildError eq "") {
376 my ($NATTime, $CBETime, $LLCTime, $JITTime, $OptTime, $BytecodeSize,
377 $MachCodeSize) = ("","","","","","","");
378 if (!$NORUNNINGTESTS) {
379 chdir "test/Programs/MultiSource/Olden" or die "Olden tests moved?";
381 # Clean out previous results...
382 system "gmake $MAKEOPTS clean > /dev/null 2>&1";
384 # Run the nightly test in this directory, with LARGE_PROBLEM_SIZE enabled!
385 system "gmake $MAKEOPTS report.nightly.raw.out TEST=nightly " .
386 " LARGE_PROBLEM_SIZE=1 > /dev/null 2>&1";
387 system "cp report.nightly.raw.out $Prefix-Olden-tests.txt";
389 system "gunzip $Prefix-Olden-tests.txt.gz";
392 # Now we know we have $Prefix-Olden-tests.txt as the raw output file. Split
393 # it up into records and read the useful information.
394 my @Records = split />>> ========= /, ReadFile "$Prefix-Olden-tests.txt";
395 shift @Records; # Delete the first (garbage) record
397 # Loop over all of the records, summarizing them into rows for the running
399 my $WallTimeRE = "[A-Za-z0-9.: ]+\\(([0-9.]+) wall clock";
400 foreach $Rec (@Records) {
401 my $rNATTime = GetRegex 'TEST-RESULT-nat-time: real\s*([.0-9m]+)', $Rec;
402 my $rCBETime = GetRegex 'TEST-RESULT-cbe-time: real\s*([.0-9m]+)', $Rec;
403 my $rLLCTime = GetRegex 'TEST-RESULT-llc-time: real\s*([.0-9m]+)', $Rec;
404 my $rJITTime = GetRegex 'TEST-RESULT-jit-time: real\s*([.0-9m]+)', $Rec;
405 my $rOptTime = GetRegex "TEST-RESULT-compile: $WallTimeRE", $Rec;
406 my $rBytecodeSize = GetRegex 'TEST-RESULT-compile: *([0-9]+)', $Rec;
407 my $rMachCodeSize = GetRegex 'TEST-RESULT-jit-machcode: *([0-9]+).*bytes of machine code', $Rec;
409 $NATTime .= " " . FormatTime($rNATTime);
410 $CBETime .= " " . FormatTime($rCBETime);
411 $LLCTime .= " " . FormatTime($rLLCTime);
412 $JITTime .= " " . FormatTime($rJITTime);
413 $OptTime .= " $rOptTime";
414 $BytecodeSize .= " $rBytecodeSize";
415 $MachCodeSize .= " $rMachCodeSize";
418 # Now that we have all of the numbers we want, add them to the running totals
420 AddRecord($NATTime, "running_Olden_nat_time.txt");
421 AddRecord($CBETime, "running_Olden_cbe_time.txt");
422 AddRecord($LLCTime, "running_Olden_llc_time.txt");
423 AddRecord($JITTime, "running_Olden_jit_time.txt");
424 AddRecord($OptTime, "running_Olden_opt_time.txt");
425 AddRecord($BytecodeSize, "running_Olden_bytecode.txt");
426 AddRecord($MachCodeSize, "running_Olden_machcode.txt");
428 system "gzip -f $Prefix-Olden-tests.txt";
435 # Get a list of the previous days that we can link to...
437 my @PrevDays = map {s/.html//; $_} GetDir ".html";
439 splice @PrevDays, 20; # Trim down list to something reasonable...
441 my $PrevDaysList = # Format list for sidebar
442 join "\n ", map { "<a href=\"$_.html\">$_</a><br>" } @PrevDays;
445 # Start outputing files into the web directory
447 chdir $WebDir or die "Could not change into web directory!";
449 # Add information to the files which accumulate information for graphs...
450 AddRecord($LOC, "running_loc.txt");
451 AddRecord($BuildTime, "running_build_time.txt");
454 # Rebuild the graphs now...
456 system "/usr/dcs/software/supported/bin/gnuplot " .
457 "$BuildDir/llvm/utils/NightlyTest.gnuplot";
460 # Remove the cvs tree...
462 system "rm -rf $BuildDir" if (!$NOCHECKOUT and !$NOREMOVE);
467 # Print out information...
470 print "DateString: $DateString\n";
471 print "CVS Checkout: $CVSCheckoutTime seconds\n";
472 print "Files/Dirs/LOC in CVS: $NumFilesInCVS/$NumDirsInCVS/$LOC\n";
474 print "Build Time: $BuildTime seconds\n";
475 print "Libraries/Executables/Objects built: $NumLibraries/$NumExecutables/$NumObjects\n";
477 print "WARNINGS:\n $WarningsList\n";
480 print "Users committed: $UserCommitList\n";
481 print "Added Files: \n $AddedFilesList\n";
482 print "Modified Files: \n $ModifiedFilesList\n";
483 print "Removed Files: \n $RemovedFilesList\n";
485 print "Previous Days =\n $PrevDaysList\n";
490 # Output the files...
495 eval "\$Output = <<ENDOFFILE;$TemplateContents\nENDOFFILE\n";
496 WriteFile "$DATE.html", $Output;
498 # Change the index.html symlink...
499 system "ln -sf $DATE.html index.html";
502 my ($Val, $Filename) = @_;
504 if (open FILE, "$WebDir/$Filename") {
505 @Records = grep !/$DATE/, split "\n", <FILE>;
508 push @Records, "$DATE: $Val";
509 WriteFile "$WebDir/$Filename", (join "\n", @Records) . "\n";