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;
25 if (open (FILE, $_[0])) {
30 print "Could not open file '$_[0]' for reading!";
35 sub WriteFile { # (filename, contents)
36 open (FILE, ">$_[0]") or die "Could not open file '$_[0]' for writing!";
41 sub GetRegex { # (Regex with ()'s, value)
46 sub AddPreTag { # Add pre tags around nonempty list, or convert to "none"
48 if (length) { return "<ul><pre>$_</pre></ul>"; } else { "<b>none</b><br>"; }
54 my @Result = reverse sort grep !/$DATE/, grep /[-0-9]+$Suffix/, readdir DH;
59 # DiffFiles - Diff the current version of the file against the last version of
60 # the file, reporting things added and removed. This is used to report, for
61 # example, added and removed warnings. This returns a pair (added, removed)
65 my @Others = GetDir $Suffix;
66 if (@Others == 0) { # No other files? We added all entries...
67 return (`cat $WebDir/$DATE$Suffix`, "");
69 # Diff the files now...
70 my @Diffs = split "\n", `diff $WebDir/$DATE$Suffix $WebDir/$Others[0]`;
71 my $Added = join "\n", grep /^</, @Diffs;
72 my $Removed = join "\n", grep /^>/, @Diffs;
74 $Removed =~ s/^> //gm;
75 return ($Added, $Removed);
79 # Command line argument settings...
86 while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
88 last if /^--$/; # Stop processing arguments on --
90 # List command line options here...
91 if (/^-nocheckout$/) { $NOCHECKOUT = 1; next; }
92 if (/^-noremove$/) { $NOREMOVE = 1; next; }
93 if (/^-notest$/) { $NOTEST = 1; next; }
94 if (/^-parallel$/) { $MAKEOPTS = "-j2 -l3.0"; next; }
96 print "Unknown option: $_ : ignoring!\n";
99 die "Must specify 0 or 3 options!" if (@ARGV != 0 and @ARGV != 3);
101 # FIXME: This should just be utils/...
102 my $Template = "$HOME/llvm/utils/NightlyTestTemplate.html";
105 $CVSRootDir = $ARGV[0];
106 $BuildDir = $ARGV[1];
110 my $Prefix = "$WebDir/$DATE";
113 print "CVS Root = $CVSRootDir\n";
114 print "BuildDir = $BuildDir\n";
115 print "WebDir = $WebDir\n";
116 print "Prefix = $Prefix\n";
121 # Create the CVS repository directory
124 mkdir $BuildDir or die "Could not create CVS checkout directory!";
126 chdir $BuildDir or die "Could not change to CVS checkout directory!";
130 # Check out the llvm tree, saving CVS messages to the cvs log...
132 system "(time -p cvs -d $CVSRootDir co llvm) > $Prefix-CVS-Log.txt 2>&1"
135 chdir "llvm" or die "Could not change into llvm directory!";
137 system "cvs up -P -d > /dev/null 2>&1" if (!$NOCHECKOUT);
139 # Read in the HTML template file...
141 my $TemplateContents = ReadFile $Template;
145 # Get some static statistics about the current state of CVS
147 my $CVSCheckoutTime = GetRegex "([0-9.]+)", `grep '^real' $Prefix-CVS-Log.txt`;
148 my $NumFilesInCVS = `grep ^U $Prefix-CVS-Log.txt | wc -l` + 0;
149 my $NumDirsInCVS = `grep '^cvs checkout' $Prefix-CVS-Log.txt | wc -l` + 0;
150 $LOC = GetRegex "([0-9]+) +total", `wc -l \`utils/getsrcs.sh\` | grep total`;
153 # Build the entire tree, saving build messages to the build log
156 # Change the Makefile.config to build into the local directory...
157 rename "Makefile.config", "Makefile.config.orig";
158 system "sed '/^LLVM_OBJ_DIR/d' < Makefile.config.orig > Makefile.config";
159 system "echo >> Makefile.config";
160 system "echo 'LLVM_OBJ_DIR := .' >> Makefile.config";
162 # Change the Makefile.config to not strip executables...
163 system "echo 'KEEP_SYMBOLS := 1' >> Makefile.config";
165 # Build the entire tree, capturing the output into $Prefix-Build-Log.txt
166 system "(time -p gmake $MAKEOPTS) > $Prefix-Build-Log.txt 2>&1";
171 # Get some statistics about the build...
173 my @Linked = split '\n', `grep Linking $Prefix-Build-Log.txt`;
174 my $NumExecutables = scalar(grep(/executable/, @Linked));
175 my $NumLibraries = scalar(grep(!/executable/, @Linked));
176 my $NumObjects = `grep '^Compiling' $Prefix-Build-Log.txt | wc -l` + 0;
177 my $BuildTimeU = GetRegex "([0-9.]+)", `grep '^user' $Prefix-Build-Log.txt`;
178 my $BuildTimeS = GetRegex "([0-9.]+)", `grep '^sys' $Prefix-Build-Log.txt`;
179 my $BuildWallTime = GetRegex "([0-9.]+)", `grep '^real' $Prefix-Build-Log.txt`;
180 my $BuildTime = $BuildTimeU+$BuildTimeS; # BuildTime = User+System
182 if (`grep '^gmake: .*Error' $Prefix-Build-Log.txt | wc -l` + 0) {
183 $BuildError = "<h3>Build error: compilation <a href=\"$DATE-Build-Log.txt\">"
184 . "aborted</a></h3>";
189 # Get warnings from the build
191 my @Warn = split "\n", `grep -E 'warning:|Entering dir' $Prefix-Build-Log.txt`;
195 foreach $Warning (@Warn) {
196 if ($Warning =~ m/Entering directory \`([^\`]+)\'/) {
197 $CurDir = $1; # Keep track of directory warning is in...
198 if ($CurDir =~ m|$BuildDir/llvm/(.*)|) { # Remove buildir prefix if included
202 push @Warnings, "$CurDir/$Warning"; # Add directory to warning...
205 my $WarningsFile = join "\n", @Warnings;
206 my $WarningsList = AddPreTag $WarningsFile;
207 $WarningsFile =~ s/:[0-9]+:/::/g;
209 # Emit the warnings file, so we can diff...
210 WriteFile "$WebDir/$DATE-Warnings.txt", $WarningsFile . "\n";
211 my ($WarningsAdded, $WarningsRemoved) = DiffFiles "-Warnings.txt";
212 $WarningsAdded = AddPreTag $WarningsAdded;
213 $WarningsRemoved = AddPreTag $WarningsRemoved;
217 # Get some statistics about CVS commits over the current day...
219 @CVSHistory = split "\n", `cvs history -D '1 day ago' -a -xAMROCGUW`;
220 #print join "\n", @CVSHistory; print "\n";
222 # Extract some information from the CVS history... use a hash so no duplicate
224 my (%AddedFiles, %ModifiedFiles, %RemovedFiles,
225 %UsersCommitted, %UsersUpdated);
227 my $DateRE = "[-:0-9 ]+\\+[0-9]+";
229 # Loop over every record from the CVS history, filling in the hashes.
230 foreach $File (@CVSHistory) {
231 my ($Type, $Date, $UID, $Rev, $Filename);
232 if ($File =~ /([AMRUGC])\s($DateRE)\s([^\s]+)\s+([0-9.]+)\s+([^\s]+)\s+([^\s]+)/) {
233 ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, $4, "$6/$5");
234 } elsif ($File =~ /([W])\s($DateRE)\s([^\s]+) +([^\s]+)\s+([^\s]+)/) {
235 ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, $4, "$6/$5");
236 } elsif ($File =~ /([O]) ($DateRE) ([^ ]+) +([^\s]+)/) {
237 ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", "$4/");
239 print "UNMATCHABLE: $File\n";
241 # print "$File\nTy = $Type Date = '$Date' UID=$UID Rev=$Rev File = '$Filename'\n";
243 if ($Filename =~ /^llvm/) {
244 if ($Type eq 'M') { # Modified
245 $ModifiedFiles{$Filename} = 1;
246 $UsersCommitted{$UID} = 1;
247 } elsif ($Type eq 'A') { # Added
248 $AddedFiles{$Filename} = 1;
249 $UsersCommitted{$UID} = 1;
250 } elsif ($Type eq 'R') { # Removed
251 $RemovedFiles{$Filename} = 1;
252 $UsersCommitted{$UID} = 1;
254 $UsersUpdated{$UID} = 1;
259 my $UserCommitList = join "\n", keys %UsersCommitted;
260 my $UserUpdateList = join "\n", keys %UsersUpdated;
261 my $AddedFilesList = AddPreTag join "\n", keys %AddedFiles;
262 my $ModifiedFilesList = AddPreTag join "\n", keys %ModifiedFiles;
263 my $RemovedFilesList = AddPreTag join "\n", keys %RemovedFiles;
268 # If we build the tree successfully, the nightly programs tests...
269 if ($BuildError eq "") {
270 chdir "test/Programs" or die "Could not change into programs testdir!";
272 # Run the programs tests... creating a report.nightly.html file
274 system "gmake $MAKEOPTS report.nightly.html TEST=nightly "
275 . "RUNTIMELIMIT=300 > $Prefix-ProgramTest.txt 2>&1";
277 system "gunzip $Prefix-ProgramTest.txt.gz";
280 if (`grep '^gmake: .*Error' $Prefix-ProgramTest.txt | wc -l` + 0) {
282 $ProgramsTable = "<font color=white><h2>Error running tests!</h2></font>";
283 } elsif (`grep '^gmake: .*No rule to make target' $Prefix-ProgramTest.txt | wc -l` + 0) {
286 "<font color=white><h2>Makefile error running tests!</h2></font>";
289 $ProgramsTable = ReadFile "report.nightly.html";
292 # Create a list of the tests which were run...
294 system "grep -E 'TEST-(PASS|FAIL)' < $Prefix-ProgramTest.txt "
295 . "| sort > $Prefix-Tests.txt";
298 # Compress the test output
299 system "gzip -f $Prefix-ProgramTest.txt";
302 my ($TestsAdded, $TestsRemoved, $TestsFixed, $TestsBroken) = ("","","","");
305 $TestsAdded = "<b>error testing</b><br>";
306 $TestsRemoved = "<b>error testing</b><br>";
307 $TestsFixed = "<b>error testing</b><br>";
308 $TestsBroken = "<b>error testing</b><br>";
310 my ($RTestsAdded, $RTestsRemoved) = DiffFiles "-Tests.txt";
312 my @RawTestsAddedArray = split '\n', $RTestsAdded;
313 my @RawTestsRemovedArray = split '\n', $RTestsRemoved;
315 my %OldTests = map {GetRegex('TEST-....: (.+)', $_)=>$_}
316 @RawTestsRemovedArray;
317 my %NewTests = map {GetRegex('TEST-....: (.+)', $_)=>$_}
320 foreach $Test (keys %NewTests) {
321 if (!exists $OldTests{$Test}) { # TestAdded if in New but not old
322 $TestsAdded = "$TestsAdded$Test\n";
324 if ($OldTests{$Test} =~ /TEST-PASS/) { # Was the old one a pass?
325 $TestsBroken = "$TestsBroken$Test\n"; # New one must be a failure
327 $TestsFixed = "$TestsFixed$Test\n"; # No, new one is a pass.
331 foreach $Test (keys %OldTests) { # TestRemoved if in Old but not New
332 $TestsRemoved = "$TestsRemoved$Test\n" if (!exists $NewTests{$Test});
335 $TestsAdded = AddPreTag $TestsAdded;
336 $TestsRemoved = AddPreTag $TestsRemoved;
337 $TestsFixed = AddPreTag $TestsFixed;
338 $TestsBroken = AddPreTag $TestsBroken;
342 # Get a list of the previous days that we can link to...
344 my @PrevDays = map {s/.html//; $_} GetDir ".html";
346 splice @PrevDays, 20; # Trim down list to something reasonable...
348 my $PrevDaysList = # Format list for sidebar
349 join "\n ", map { "<a href=\"$_.html\">$_</a><br>" } @PrevDays;
353 # Remove the cvs tree...
355 chdir $WebDir or die "Could not change into web directory!";
356 system "rm -rf $BuildDir" if (!$NOCHECKOUT and !$NOREMOVE);
360 # Print out information...
363 print "DateString: $DateString\n";
364 print "CVS Checkout: $CVSCheckoutTime seconds\n";
365 print "Files/Dirs/LOC in CVS: $NumFilesInCVS/$NumDirsInCVS/$LOC\n";
367 print "Build Time: $BuildTime seconds\n";
368 print "Libraries/Executables/Objects built: $NumLibraries/$NumExecutables/$NumObjects\n";
370 print "WARNINGS:\n $WarningsList\n";
373 print "Users committed: $UserCommitList\n";
374 print "Added Files: \n $AddedFilesList\n";
375 print "Modified Files: \n $ModifiedFilesList\n";
376 print "Removed Files: \n $RemovedFilesList\n";
378 print "Previous Days =\n $PrevDaysList\n";
383 # Output the files...
388 eval "\$Output = <<ENDOFFILE;$TemplateContents\nENDOFFILE\n";
389 WriteFile "$DATE.html", $Output;
391 # Change the index.html symlink...
392 system "ln -sf $DATE.html index.html";
395 my ($Val, $Filename) = @_;
397 if (open FILE, $Filename) {
398 @Records = grep !/$DATE/, split "\n", <FILE>;
401 push @Records, "$DATE: $Val";
402 WriteFile $Filename, (join "\n", @Records) . "\n";
406 # Add information to the files which accumulate information for graphs...
407 AddRecord($LOC, "running_loc.txt");
408 AddRecord($BuildTime, "running_build_time.txt");