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 | |
| 14 | # Command line argument settings... |
| 15 | my $NOCHECKOUT = 0; |
| 16 | my $NOREMOVE = 0; |
| 17 | my $MAKEOPTS = ""; |
| 18 | |
| 19 | # Parse arguments... |
| 20 | while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) { |
| 21 | shift; |
| 22 | last if /^--$/; # Stop processing arguments on -- |
| 23 | |
| 24 | # List command line options here... |
| 25 | if (/^-nocheckout$/) { $NOCHECKOUT = 1; next; } |
| 26 | if (/^-noremove$/) { $NOREMOVE = 1; next; } |
| 27 | if (/^-parallel$/) { $MAKEOPTS = "-j2 -l3.0"; next; } |
| 28 | |
| 29 | print "Unknown option: $_ : ignoring!\n"; |
| 30 | } |
| 31 | |
| 32 | die "Must specify 0 or 4 options!" if (@ARGV != 0 and @ARGV != 4); |
| 33 | |
| 34 | my $HOME = $ENV{HOME}; |
| 35 | my $CVSRootDir = "/home/vadve/vadve/Research/DynOpt/CVSRepository"; |
| 36 | my $BuildDir = "$HOME/buildtest"; |
| 37 | my $WebDir = "$HOME/cvs/testresults-X86"; |
| 38 | |
| 39 | # FIXME: This should just be utils/... |
| 40 | my $Template = "$HOME/llvm/utils/NightlyTestTemplate.html"; |
| 41 | |
| 42 | if (@ARGV == 3) { |
| 43 | $CVSRootDir = $ARGV[0]; |
| 44 | $BuildDir = $ARGV[1]; |
| 45 | $WebDir = $ARGV[2]; |
| 46 | } |
| 47 | |
| 48 | # Calculate the date prefix... |
| 49 | @TIME = localtime; |
| 50 | my $DATE = sprintf "%4d-%02d-%02d", $TIME[5]+1900, $TIME[4]+1, $TIME[3]; |
| 51 | my $DateString = strftime "%B %d, %Y", localtime; |
| 52 | |
| 53 | my $Prefix = "$WebDir/$DATE"; |
| 54 | |
| 55 | if (0) { |
| 56 | print "CVS Root = $CVSRootDir\n"; |
| 57 | print "BuildDir = $BuildDir\n"; |
| 58 | print "WebDir = $WebDir\n"; |
| 59 | print "Prefix = $Prefix\n"; |
| 60 | } |
| 61 | |
| 62 | # Create the CVS repository directory |
| 63 | if (!$NOCHECKOUT) { |
| 64 | mkdir $BuildDir or die "Could not create CVS checkout directory!"; |
| 65 | } |
| 66 | chdir $BuildDir or die "Could not change to CVS checkout directory!"; |
| 67 | |
| 68 | # Check out the llvm tree, saving CVS messages to the cvs log... |
| 69 | system "(time -p cvs -d $CVSRootDir co llvm) > $Prefix-CVS-Log.txt 2>&1" |
| 70 | if (!$NOCHECKOUT); |
| 71 | |
| 72 | chdir "llvm" or die "Could not change into llvm directory!"; |
| 73 | |
| 74 | # Read in the HTML template file... |
| 75 | undef $/; |
| 76 | open (TEMPLATEFILE, $Template) or die "Could not open file 'llvm/$Template'!"; |
| 77 | my $TemplateContents = <TEMPLATEFILE>; |
| 78 | close(TEMPLATEFILE); |
| 79 | |
| 80 | sub GetRegex { |
| 81 | $_[1] =~ /$_[0]/; |
| 82 | return $1; |
| 83 | } |
| 84 | |
| 85 | # Get some static statistics about the current state of CVS |
| 86 | my $CVSCheckoutTime = GetRegex "([0-9.]+)", `grep '^real' $Prefix-CVS-Log.txt`; |
| 87 | my $NumFilesInCVS = `grep ^U $Prefix-CVS-Log.txt | wc -l` + 0; |
| 88 | my $NumDirsInCVS = `grep '^cvs checkout' $Prefix-CVS-Log.txt | wc -l` + 0; |
| 89 | $LOC = GetRegex "([0-9]+) +total", `wc -l \`utils/getsrcs.sh\` | grep total`; |
| 90 | |
| 91 | # Build the entire tree, saving build messages to the build log |
| 92 | if (!$NOCHECKOUT) { |
| 93 | # Change the Makefile.config to build into the local directory... |
| 94 | rename "Makefile.config", "Makefile.config.orig"; |
| 95 | system "sed '/^LLVM_OBJ_DIR/d' < Makefile.config.orig > Makefile.config"; |
| 96 | system "echo >> Makefile.config"; |
| 97 | system "echo 'LLVM_OBJ_DIR := .' >> Makefile.config"; |
| 98 | |
| 99 | # Change the Makefile.config to not strip executables... |
| 100 | system "echo 'KEEP_SYMBOLS := 1' >> Makefile.config"; |
| 101 | |
| 102 | # Build the entire tree, capturing the output into $Prefix-Build-Log.txt |
| 103 | system "(time -p gmake $MAKEOPTS) > $Prefix-Build-Log.txt 2>&1"; |
| 104 | } |
| 105 | |
| 106 | # Get some statistics about the build... |
| 107 | my @Linked = split '\n', `grep Linking $Prefix-Build-Log.txt`; |
| 108 | my $NumExecutables = scalar(grep(/executable/, @Linked)); |
| 109 | my $NumLibraries = scalar(grep(!/executable/, @Linked)); |
| 110 | my $NumObjects = `grep '^Compiling' $Prefix-Build-Log.txt | wc -l` + 0; |
| 111 | my $BuildTime = GetRegex "([0-9.]+)", `grep '^real' $Prefix-Build-Log.txt`; |
| 112 | |
| 113 | |
| 114 | sub AddPreTag { # Add pre tags around nonempty list, or convert to "none" |
| 115 | $_ = shift; |
| 116 | if (length) { return "<pre> $_</pre>"; } else { "<b>none</b><br>"; } |
| 117 | } |
| 118 | |
| 119 | # Get warnings from the build |
| 120 | my @Warn = split "\n", `grep -E 'warning:|Entering dir' $Prefix-Build-Log.txt`; |
| 121 | my @Warnings; |
| 122 | my $CurDir = ""; |
| 123 | |
| 124 | foreach $Warning (@Warn) { |
| 125 | if ($Warning =~ m/Entering directory \`([^\`]+)\'/) { |
| 126 | $CurDir = $1; # Keep track of directory warning is in... |
| 127 | if ($CurDir =~ m|$BuildDir/llvm/(.*)|) { # Remove buildir prefix if included |
| 128 | $CurDir = $1; |
| 129 | } |
| 130 | } else { |
| 131 | push @Warnings, "$CurDir/$Warning"; # Add directory to warning... |
| 132 | } |
| 133 | } |
| 134 | my $WarningsList = AddPreTag join "\n ", @Warnings; |
| 135 | |
| 136 | |
| 137 | # Get some statistics about CVS commits over the current day... |
| 138 | @CVSHistory = split "\n", `cvs history -D '1 day ago' -a -xAMROCGUW`; |
| 139 | #print join "\n", @CVSHistory; print "\n"; |
| 140 | |
| 141 | # Extract some information from the CVS history... use a hash so no duplicate |
| 142 | # stuff is stored. |
| 143 | my (%AddedFiles, %ModifiedFiles, %RemovedFiles, |
| 144 | %UsersCommitted, %UsersUpdated); |
| 145 | |
| 146 | # Loop over every record from the CVS history, filling in the hashes. |
| 147 | foreach $File (@CVSHistory) { |
| 148 | my ($Type, $Date, $UID, $Rev, $Filename); |
| 149 | if ($File =~ /([AMR]) ([-:0-9 ]+\+[0-9]+) ([^ ]+) ([0-9.]+) +([^ ]+) +([^ ]+)/) { |
| 150 | ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, $4, "$6/$5"); |
| 151 | } elsif ($File =~ /([OCGUW]) ([-:0-9 ]+\+[0-9]+) ([^ ]+)/) { |
| 152 | ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", ""); |
| 153 | } |
| 154 | #print "Ty = $Type Date = '$Date' UID=$UID Rev=$Rev File = '$Filename'\n"; |
| 155 | |
| 156 | if ($Type eq 'M') { # Modified |
| 157 | $ModifiedFiles{$Filename} = 1; |
| 158 | $UsersCommitted{$UID} = 1; |
| 159 | } elsif ($Type eq 'A') { # Added |
| 160 | $AddedFiles{$Filename} = 1; |
| 161 | $UsersCommitted{$UID} = 1; |
| 162 | } elsif ($Type eq 'R') { # Removed |
| 163 | $RemovedFiles{$Filename} = 1; |
| 164 | $UsersCommitted{$UID} = 1; |
| 165 | } else { |
| 166 | $UsersUpdated{$UID} = 1; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | my $UserCommitList = join "\n ", keys %UsersCommitted; |
| 171 | my $UserUpdateList = join "\n ", keys %UsersUpdated; |
| 172 | my $AddedFilesList = AddPreTag join "\n ", keys %AddedFiles; |
| 173 | my $ModifiedFilesList = AddPreTag join "\n ", keys %ModifiedFiles; |
| 174 | my $RemovedFilesList = AddPreTag join "\n ", keys %RemovedFiles; |
| 175 | |
| 176 | # Get a list of the previous days that we can link to... |
| 177 | system "rm -f $WebDir/$DATE.html"; # Don't relist self if regenerating... |
| 178 | opendir DH, $WebDir; |
| 179 | my @PrevDays = |
| 180 | map {s/.html//; $_} reverse sort grep /[-0-9]+.html/, readdir DH; |
| 181 | closedir DH; |
| 182 | |
| 183 | splice @PrevDays, 20; # Trim down list to something reasonable... |
| 184 | |
| 185 | my $PrevDaysList = # Format list for sidebar |
| 186 | join "\n ", map { "<a href=\"$_.html\">$_</a><br>" } @PrevDays; |
| 187 | |
| 188 | # |
| 189 | # Remove the cvs tree... |
| 190 | # |
| 191 | system "rm -rf $BuildDir" if (!$NOCHECKOUT and !$NOREMOVE); |
| 192 | |
| 193 | # Print out information... |
| 194 | if (0) { |
| 195 | print "DateString: $DateString\n"; |
| 196 | print "CVS Checkout: $CVSCheckoutTime seconds\n"; |
| 197 | print "Files/Dirs/LOC in CVS: $NumFilesInCVS/$NumDirsInCVS/$LOC\n"; |
| 198 | |
| 199 | print "Build Time: $BuildTime seconds\n"; |
| 200 | print "Libraries/Executables/Objects built: $NumLibraries/$NumExecutables/$NumObjects\n"; |
| 201 | |
| 202 | print "WARNINGS:\n $WarningsList\n"; |
| 203 | |
| 204 | |
| 205 | print "Users committed: $UserCommitList\n"; |
| 206 | print "Added Files: \n $AddedFilesList\n"; |
| 207 | print "Modified Files: \n $ModifiedFilesList\n"; |
| 208 | print "Removed Files: \n $RemovedFilesList\n"; |
| 209 | |
| 210 | print "Previous Days =\n $PrevDaysList\n"; |
| 211 | } |
| 212 | |
| 213 | # Output the file... |
| 214 | chdir $WebDir or die "Could not change into web directory!"; |
| 215 | my $Output; |
| 216 | eval "\$Output = <<ENDOFFILE;$TemplateContents\nENDOFFILE\n"; |
| 217 | open(OUTFILE, ">$DATE.html") or die "Cannot open output file!"; |
| 218 | print OUTFILE $Output; |
| 219 | close(OUTFILE); |
| 220 | |
| 221 | # Change the index.html symlink... |
| 222 | system "ln -sf $DATE.html index.html"; |
| 223 | |
| 224 | sub AddRecord { |
| 225 | my ($Val, $Filename) = @_; |
| 226 | my @Records; |
| 227 | if (open FILE, $Filename) { |
| 228 | @Records = grep !/$DATE/, split "\n", <FILE>; |
| 229 | close FILE; |
| 230 | } |
| 231 | push @Records, "$DATE: $Val"; |
| 232 | open FILE, ">$Filename" or die "Couldn't open data file $Filename"; |
| 233 | print FILE (join "\n", @Records), "\n"; |
| 234 | close FILE; |
| 235 | return @Records; |
| 236 | } |
| 237 | |
| 238 | # Add information to the files which accumulate information for graphs... |
| 239 | AddRecord($LOC, "running_loc.txt"); |
| 240 | AddRecord($BuildTime, "running_build_time.txt"); |