Chris Lattner | 4c7e303 | 2003-01-20 06:11:03 +0000 | [diff] [blame] | 1 | #!/usr/dcs/software/supported/bin/perl -w |
| 2 | # |
| 3 | # Program: NightlyTest.pl |
| 4 | # |
| 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. |
| 9 | # |
| 10 | # Syntax: NightlyTest.pl <CVSRootDir> <BuildDir> <WebDir> |
| 11 | # |
| 12 | use POSIX qw(strftime); |
| 13 | |
Chris Lattner | 2f8cb57 | 2003-01-20 18:05:27 +0000 | [diff] [blame^] | 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"; |
| 18 | |
| 19 | # Calculate the date prefix... |
| 20 | @TIME = localtime; |
| 21 | my $DATE = sprintf "%4d-%02d-%02d", $TIME[5]+1900, $TIME[4]+1, $TIME[3]; |
| 22 | my $DateString = strftime "%B %d, %Y", localtime; |
| 23 | |
| 24 | sub WriteFile { # (filename, contents) |
| 25 | open (FILE, ">$_[0]") or die "Could not open file '$_[0]' for writing!"; |
| 26 | print FILE $_[1]; |
| 27 | close FILE; |
| 28 | } |
| 29 | |
| 30 | sub GetRegex { # (Regex with ()'s, value) |
| 31 | $_[1] =~ /$_[0]/; |
| 32 | return $1; |
| 33 | } |
| 34 | |
| 35 | sub AddPreTag { # Add pre tags around nonempty list, or convert to "none" |
| 36 | $_ = shift; |
| 37 | if (length) { return "<pre> $_</pre>"; } else { "<b>none</b><br>"; } |
| 38 | } |
| 39 | |
| 40 | sub GetDir { |
| 41 | my $Suffix = shift; |
| 42 | opendir DH, $WebDir; |
| 43 | my @Result = reverse sort grep !/$DATE/, grep /[-0-9]+$Suffix/, readdir DH; |
| 44 | closedir DH; |
| 45 | return @Result; |
| 46 | } |
| 47 | |
| 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) |
| 51 | # |
| 52 | sub DiffFiles { |
| 53 | my $Suffix = shift; |
| 54 | my @Others = GetDir $Suffix; |
| 55 | if (@Others == 0) { # No other files? We added all entries... |
| 56 | return (`cat $WebDir/$DATE$Suffix`, ""); |
| 57 | } |
| 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; |
| 62 | $Added =~ s/^< / /gm; |
| 63 | $Removed =~ s/^> / /gm; |
| 64 | return ($Added, $Removed); |
| 65 | } |
| 66 | |
| 67 | |
Chris Lattner | 4c7e303 | 2003-01-20 06:11:03 +0000 | [diff] [blame] | 68 | # Command line argument settings... |
| 69 | my $NOCHECKOUT = 0; |
| 70 | my $NOREMOVE = 0; |
| 71 | my $MAKEOPTS = ""; |
| 72 | |
| 73 | # Parse arguments... |
| 74 | while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) { |
| 75 | shift; |
| 76 | last if /^--$/; # Stop processing arguments on -- |
| 77 | |
| 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; } |
| 82 | |
| 83 | print "Unknown option: $_ : ignoring!\n"; |
| 84 | } |
| 85 | |
Chris Lattner | 2f8cb57 | 2003-01-20 18:05:27 +0000 | [diff] [blame^] | 86 | die "Must specify 0 or 3 options!" if (@ARGV != 0 and @ARGV != 3); |
Chris Lattner | 4c7e303 | 2003-01-20 06:11:03 +0000 | [diff] [blame] | 87 | |
| 88 | # FIXME: This should just be utils/... |
| 89 | my $Template = "$HOME/llvm/utils/NightlyTestTemplate.html"; |
| 90 | |
| 91 | if (@ARGV == 3) { |
| 92 | $CVSRootDir = $ARGV[0]; |
| 93 | $BuildDir = $ARGV[1]; |
| 94 | $WebDir = $ARGV[2]; |
| 95 | } |
| 96 | |
Chris Lattner | 4c7e303 | 2003-01-20 06:11:03 +0000 | [diff] [blame] | 97 | my $Prefix = "$WebDir/$DATE"; |
| 98 | |
| 99 | if (0) { |
| 100 | print "CVS Root = $CVSRootDir\n"; |
| 101 | print "BuildDir = $BuildDir\n"; |
| 102 | print "WebDir = $WebDir\n"; |
| 103 | print "Prefix = $Prefix\n"; |
| 104 | } |
| 105 | |
| 106 | # Create the CVS repository directory |
| 107 | if (!$NOCHECKOUT) { |
| 108 | mkdir $BuildDir or die "Could not create CVS checkout directory!"; |
| 109 | } |
| 110 | chdir $BuildDir or die "Could not change to CVS checkout directory!"; |
| 111 | |
| 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" |
| 114 | if (!$NOCHECKOUT); |
| 115 | |
| 116 | chdir "llvm" or die "Could not change into llvm directory!"; |
| 117 | |
| 118 | # Read in the HTML template file... |
| 119 | undef $/; |
| 120 | open (TEMPLATEFILE, $Template) or die "Could not open file 'llvm/$Template'!"; |
| 121 | my $TemplateContents = <TEMPLATEFILE>; |
| 122 | close(TEMPLATEFILE); |
| 123 | |
Chris Lattner | 4c7e303 | 2003-01-20 06:11:03 +0000 | [diff] [blame] | 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`; |
| 129 | |
| 130 | # Build the entire tree, saving build messages to the build log |
| 131 | if (!$NOCHECKOUT) { |
| 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"; |
| 137 | |
| 138 | # Change the Makefile.config to not strip executables... |
| 139 | system "echo 'KEEP_SYMBOLS := 1' >> Makefile.config"; |
| 140 | |
| 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"; |
| 143 | } |
| 144 | |
| 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`; |
| 151 | |
| 152 | |
Chris Lattner | 4c7e303 | 2003-01-20 06:11:03 +0000 | [diff] [blame] | 153 | # Get warnings from the build |
| 154 | my @Warn = split "\n", `grep -E 'warning:|Entering dir' $Prefix-Build-Log.txt`; |
| 155 | my @Warnings; |
| 156 | my $CurDir = ""; |
| 157 | |
| 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 |
| 162 | $CurDir = $1; |
| 163 | } |
| 164 | } else { |
| 165 | push @Warnings, "$CurDir/$Warning"; # Add directory to warning... |
| 166 | } |
| 167 | } |
| 168 | my $WarningsList = AddPreTag join "\n ", @Warnings; |
Chris Lattner | 2f8cb57 | 2003-01-20 18:05:27 +0000 | [diff] [blame^] | 169 | my $WarningsFile = join "\n", @Warnings; $WarningsFile =~ s/:[0-9]+:/::/g; |
Chris Lattner | 4c7e303 | 2003-01-20 06:11:03 +0000 | [diff] [blame] | 170 | |
Chris Lattner | 2f8cb57 | 2003-01-20 18:05:27 +0000 | [diff] [blame^] | 171 | # Emit the warnings file, so we can diff... |
| 172 | WriteFile "$WebDir/$DATE-Warnings.txt", $WarningsFile . "\n"; |
| 173 | my ($WarningsAdded, $WarningsRemoved) = DiffFiles "-Warnings.txt"; |
| 174 | $WarningsAdded = AddPreTag $WarningsAdded; |
| 175 | $WarningsRemoved = AddPreTag $WarningsRemoved; |
Chris Lattner | 4c7e303 | 2003-01-20 06:11:03 +0000 | [diff] [blame] | 176 | |
| 177 | # Get some statistics about CVS commits over the current day... |
| 178 | @CVSHistory = split "\n", `cvs history -D '1 day ago' -a -xAMROCGUW`; |
| 179 | #print join "\n", @CVSHistory; print "\n"; |
| 180 | |
| 181 | # Extract some information from the CVS history... use a hash so no duplicate |
| 182 | # stuff is stored. |
| 183 | my (%AddedFiles, %ModifiedFiles, %RemovedFiles, |
| 184 | %UsersCommitted, %UsersUpdated); |
| 185 | |
| 186 | # Loop over every record from the CVS history, filling in the hashes. |
| 187 | foreach $File (@CVSHistory) { |
| 188 | my ($Type, $Date, $UID, $Rev, $Filename); |
| 189 | if ($File =~ /([AMR]) ([-:0-9 ]+\+[0-9]+) ([^ ]+) ([0-9.]+) +([^ ]+) +([^ ]+)/) { |
| 190 | ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, $4, "$6/$5"); |
| 191 | } elsif ($File =~ /([OCGUW]) ([-:0-9 ]+\+[0-9]+) ([^ ]+)/) { |
| 192 | ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", ""); |
| 193 | } |
| 194 | #print "Ty = $Type Date = '$Date' UID=$UID Rev=$Rev File = '$Filename'\n"; |
| 195 | |
| 196 | if ($Type eq 'M') { # Modified |
| 197 | $ModifiedFiles{$Filename} = 1; |
| 198 | $UsersCommitted{$UID} = 1; |
| 199 | } elsif ($Type eq 'A') { # Added |
| 200 | $AddedFiles{$Filename} = 1; |
| 201 | $UsersCommitted{$UID} = 1; |
| 202 | } elsif ($Type eq 'R') { # Removed |
| 203 | $RemovedFiles{$Filename} = 1; |
| 204 | $UsersCommitted{$UID} = 1; |
| 205 | } else { |
| 206 | $UsersUpdated{$UID} = 1; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | my $UserCommitList = join "\n ", keys %UsersCommitted; |
| 211 | my $UserUpdateList = join "\n ", keys %UsersUpdated; |
| 212 | my $AddedFilesList = AddPreTag join "\n ", keys %AddedFiles; |
| 213 | my $ModifiedFilesList = AddPreTag join "\n ", keys %ModifiedFiles; |
| 214 | my $RemovedFilesList = AddPreTag join "\n ", keys %RemovedFiles; |
| 215 | |
| 216 | # Get a list of the previous days that we can link to... |
Chris Lattner | 2f8cb57 | 2003-01-20 18:05:27 +0000 | [diff] [blame^] | 217 | my @PrevDays = map {s/.html//; $_} GetDir ".html"; |
Chris Lattner | 4c7e303 | 2003-01-20 06:11:03 +0000 | [diff] [blame] | 218 | |
| 219 | splice @PrevDays, 20; # Trim down list to something reasonable... |
| 220 | |
| 221 | my $PrevDaysList = # Format list for sidebar |
| 222 | join "\n ", map { "<a href=\"$_.html\">$_</a><br>" } @PrevDays; |
| 223 | |
| 224 | # |
| 225 | # Remove the cvs tree... |
| 226 | # |
| 227 | system "rm -rf $BuildDir" if (!$NOCHECKOUT and !$NOREMOVE); |
| 228 | |
| 229 | # Print out information... |
| 230 | if (0) { |
| 231 | print "DateString: $DateString\n"; |
| 232 | print "CVS Checkout: $CVSCheckoutTime seconds\n"; |
| 233 | print "Files/Dirs/LOC in CVS: $NumFilesInCVS/$NumDirsInCVS/$LOC\n"; |
| 234 | |
| 235 | print "Build Time: $BuildTime seconds\n"; |
| 236 | print "Libraries/Executables/Objects built: $NumLibraries/$NumExecutables/$NumObjects\n"; |
| 237 | |
| 238 | print "WARNINGS:\n $WarningsList\n"; |
| 239 | |
| 240 | |
| 241 | print "Users committed: $UserCommitList\n"; |
| 242 | print "Added Files: \n $AddedFilesList\n"; |
| 243 | print "Modified Files: \n $ModifiedFilesList\n"; |
| 244 | print "Removed Files: \n $RemovedFilesList\n"; |
| 245 | |
| 246 | print "Previous Days =\n $PrevDaysList\n"; |
| 247 | } |
| 248 | |
Chris Lattner | 2f8cb57 | 2003-01-20 18:05:27 +0000 | [diff] [blame^] | 249 | # |
| 250 | # Output the files... |
| 251 | # |
| 252 | |
| 253 | # Main HTML file... |
Chris Lattner | 4c7e303 | 2003-01-20 06:11:03 +0000 | [diff] [blame] | 254 | chdir $WebDir or die "Could not change into web directory!"; |
| 255 | my $Output; |
| 256 | eval "\$Output = <<ENDOFFILE;$TemplateContents\nENDOFFILE\n"; |
Chris Lattner | 2f8cb57 | 2003-01-20 18:05:27 +0000 | [diff] [blame^] | 257 | WriteFile "$DATE.html", $Output; |
Chris Lattner | 4c7e303 | 2003-01-20 06:11:03 +0000 | [diff] [blame] | 258 | |
| 259 | # Change the index.html symlink... |
| 260 | system "ln -sf $DATE.html index.html"; |
| 261 | |
| 262 | sub AddRecord { |
| 263 | my ($Val, $Filename) = @_; |
| 264 | my @Records; |
| 265 | if (open FILE, $Filename) { |
| 266 | @Records = grep !/$DATE/, split "\n", <FILE>; |
| 267 | close FILE; |
| 268 | } |
| 269 | push @Records, "$DATE: $Val"; |
Chris Lattner | 2f8cb57 | 2003-01-20 18:05:27 +0000 | [diff] [blame^] | 270 | WriteFile $Filename, (join "\n", @Records) . "\n"; |
Chris Lattner | 4c7e303 | 2003-01-20 06:11:03 +0000 | [diff] [blame] | 271 | return @Records; |
| 272 | } |
| 273 | |
| 274 | # Add information to the files which accumulate information for graphs... |
| 275 | AddRecord($LOC, "running_loc.txt"); |
| 276 | AddRecord($BuildTime, "running_build_time.txt"); |