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;
24 sub WriteFile { # (filename, contents)
25 open (FILE, ">$_[0]") or die "Could not open file '$_[0]' for writing!";
30 sub GetRegex { # (Regex with ()'s, value)
35 sub AddPreTag { # Add pre tags around nonempty list, or convert to "none"
37 if (length) { return "<ul><pre>$_</pre></ul>"; } else { "<b>none</b><br>"; }
43 my @Result = reverse sort grep !/$DATE/, grep /[-0-9]+$Suffix/, readdir DH;
48 # DiffFiles - Diff the current version of the file against the last version of
49 # the file, reporting things added and removed. This is used to report, for
50 # example, added and removed warnings. This returns a pair (added, removed)
54 my @Others = GetDir $Suffix;
55 if (@Others == 0) { # No other files? We added all entries...
56 return (`cat $WebDir/$DATE$Suffix`, "");
58 # Diff the files now...
59 my @Diffs = split "\n", `diff $WebDir/$DATE$Suffix $WebDir/$Others[0]`;
60 my $Added = join "\n", grep /^</, @Diffs;
61 my $Removed = join "\n", grep /^>/, @Diffs;
63 $Removed =~ s/^> //gm;
64 return ($Added, $Removed);
68 # Command line argument settings...
74 while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
76 last if /^--$/; # Stop processing arguments on --
78 # List command line options here...
79 if (/^-nocheckout$/) { $NOCHECKOUT = 1; next; }
80 if (/^-noremove$/) { $NOREMOVE = 1; next; }
81 if (/^-parallel$/) { $MAKEOPTS = "-j2 -l3.0"; next; }
83 print "Unknown option: $_ : ignoring!\n";
86 die "Must specify 0 or 3 options!" if (@ARGV != 0 and @ARGV != 3);
88 # FIXME: This should just be utils/...
89 my $Template = "$HOME/llvm/utils/NightlyTestTemplate.html";
92 $CVSRootDir = $ARGV[0];
97 my $Prefix = "$WebDir/$DATE";
100 print "CVS Root = $CVSRootDir\n";
101 print "BuildDir = $BuildDir\n";
102 print "WebDir = $WebDir\n";
103 print "Prefix = $Prefix\n";
106 # Create the CVS repository directory
108 mkdir $BuildDir or die "Could not create CVS checkout directory!";
110 chdir $BuildDir or die "Could not change to CVS checkout directory!";
112 # Check out the llvm tree, saving CVS messages to the cvs log...
113 system "(time -p cvs -d $CVSRootDir co llvm) > $Prefix-CVS-Log.txt 2>&1"
116 chdir "llvm" or die "Could not change into llvm directory!";
118 # Read in the HTML template file...
120 open (TEMPLATEFILE, $Template) or die "Could not open file 'llvm/$Template'!";
121 my $TemplateContents = <TEMPLATEFILE>;
124 # Get some static statistics about the current state of CVS
125 my $CVSCheckoutTime = GetRegex "([0-9.]+)", `grep '^real' $Prefix-CVS-Log.txt`;
126 my $NumFilesInCVS = `grep ^U $Prefix-CVS-Log.txt | wc -l` + 0;
127 my $NumDirsInCVS = `grep '^cvs checkout' $Prefix-CVS-Log.txt | wc -l` + 0;
128 $LOC = GetRegex "([0-9]+) +total", `wc -l \`utils/getsrcs.sh\` | grep total`;
130 # Build the entire tree, saving build messages to the build log
132 # Change the Makefile.config to build into the local directory...
133 rename "Makefile.config", "Makefile.config.orig";
134 system "sed '/^LLVM_OBJ_DIR/d' < Makefile.config.orig > Makefile.config";
135 system "echo >> Makefile.config";
136 system "echo 'LLVM_OBJ_DIR := .' >> Makefile.config";
138 # Change the Makefile.config to not strip executables...
139 system "echo 'KEEP_SYMBOLS := 1' >> Makefile.config";
141 # Build the entire tree, capturing the output into $Prefix-Build-Log.txt
142 system "(time -p gmake $MAKEOPTS) > $Prefix-Build-Log.txt 2>&1";
145 # Get some statistics about the build...
146 my @Linked = split '\n', `grep Linking $Prefix-Build-Log.txt`;
147 my $NumExecutables = scalar(grep(/executable/, @Linked));
148 my $NumLibraries = scalar(grep(!/executable/, @Linked));
149 my $NumObjects = `grep '^Compiling' $Prefix-Build-Log.txt | wc -l` + 0;
150 my $BuildTime = GetRegex "([0-9.]+)", `grep '^real' $Prefix-Build-Log.txt`;
153 # Get warnings from the build
154 my @Warn = split "\n", `grep -E 'warning:|Entering dir' $Prefix-Build-Log.txt`;
158 foreach $Warning (@Warn) {
159 if ($Warning =~ m/Entering directory \`([^\`]+)\'/) {
160 $CurDir = $1; # Keep track of directory warning is in...
161 if ($CurDir =~ m|$BuildDir/llvm/(.*)|) { # Remove buildir prefix if included
165 push @Warnings, "$CurDir/$Warning"; # Add directory to warning...
168 my $WarningsFile = join "\n", @Warnings;
169 my $WarningsList = AddPreTag $WarningsFile;
170 $WarningsFile =~ s/:[0-9]+:/::/g;
172 # Emit the warnings file, so we can diff...
173 WriteFile "$WebDir/$DATE-Warnings.txt", $WarningsFile . "\n";
174 my ($WarningsAdded, $WarningsRemoved) = DiffFiles "-Warnings.txt";
175 $WarningsAdded = AddPreTag $WarningsAdded;
176 $WarningsRemoved = AddPreTag $WarningsRemoved;
178 # Get some statistics about CVS commits over the current day...
179 @CVSHistory = split "\n", `cvs history -D '1 day ago' -a -xAMROCGUW`;
180 #print join "\n", @CVSHistory; print "\n";
182 # Extract some information from the CVS history... use a hash so no duplicate
184 my (%AddedFiles, %ModifiedFiles, %RemovedFiles,
185 %UsersCommitted, %UsersUpdated);
187 # Loop over every record from the CVS history, filling in the hashes.
188 foreach $File (@CVSHistory) {
189 my ($Type, $Date, $UID, $Rev, $Filename);
190 if ($File =~ /([AMR]) ([-:0-9 ]+\+[0-9]+) ([^ ]+) ([0-9.]+) +([^ ]+) +([^ ]+)/) {
191 ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, $4, "$6/$5");
192 } elsif ($File =~ /([OCGUW]) ([-:0-9 ]+\+[0-9]+) ([^ ]+)/) {
193 ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", "");
195 #print "Ty = $Type Date = '$Date' UID=$UID Rev=$Rev File = '$Filename'\n";
197 if ($Type eq 'M') { # Modified
198 $ModifiedFiles{$Filename} = 1;
199 $UsersCommitted{$UID} = 1;
200 } elsif ($Type eq 'A') { # Added
201 $AddedFiles{$Filename} = 1;
202 $UsersCommitted{$UID} = 1;
203 } elsif ($Type eq 'R') { # Removed
204 $RemovedFiles{$Filename} = 1;
205 $UsersCommitted{$UID} = 1;
207 $UsersUpdated{$UID} = 1;
211 my $UserCommitList = join "\n", keys %UsersCommitted;
212 my $UserUpdateList = join "\n", keys %UsersUpdated;
213 my $AddedFilesList = AddPreTag join "\n", keys %AddedFiles;
214 my $ModifiedFilesList = AddPreTag join "\n", keys %ModifiedFiles;
215 my $RemovedFilesList = AddPreTag join "\n", keys %RemovedFiles;
217 # Get a list of the previous days that we can link to...
218 my @PrevDays = map {s/.html//; $_} GetDir ".html";
220 splice @PrevDays, 20; # Trim down list to something reasonable...
222 my $PrevDaysList = # Format list for sidebar
223 join "\n ", map { "<a href=\"$_.html\">$_</a><br>" } @PrevDays;
226 # Remove the cvs tree...
228 system "rm -rf $BuildDir" if (!$NOCHECKOUT and !$NOREMOVE);
230 # Print out information...
232 print "DateString: $DateString\n";
233 print "CVS Checkout: $CVSCheckoutTime seconds\n";
234 print "Files/Dirs/LOC in CVS: $NumFilesInCVS/$NumDirsInCVS/$LOC\n";
236 print "Build Time: $BuildTime seconds\n";
237 print "Libraries/Executables/Objects built: $NumLibraries/$NumExecutables/$NumObjects\n";
239 print "WARNINGS:\n $WarningsList\n";
242 print "Users committed: $UserCommitList\n";
243 print "Added Files: \n $AddedFilesList\n";
244 print "Modified Files: \n $ModifiedFilesList\n";
245 print "Removed Files: \n $RemovedFilesList\n";
247 print "Previous Days =\n $PrevDaysList\n";
251 # Output the files...
255 chdir $WebDir or die "Could not change into web directory!";
257 eval "\$Output = <<ENDOFFILE;$TemplateContents\nENDOFFILE\n";
258 WriteFile "$DATE.html", $Output;
260 # Change the index.html symlink...
261 system "ln -sf $DATE.html index.html";
264 my ($Val, $Filename) = @_;
266 if (open FILE, $Filename) {
267 @Records = grep !/$DATE/, split "\n", <FILE>;
270 push @Records, "$DATE: $Val";
271 WriteFile $Filename, (join "\n", @Records) . "\n";
275 # Add information to the files which accumulate information for graphs...
276 AddRecord($LOC, "running_loc.txt");
277 AddRecord($BuildTime, "running_build_time.txt");