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 # Command line argument settings...
20 while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
22 last if /^--$/; # Stop processing arguments on --
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; }
29 print "Unknown option: $_ : ignoring!\n";
32 die "Must specify 0 or 4 options!" if (@ARGV != 0 and @ARGV != 4);
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";
39 # FIXME: This should just be utils/...
40 my $Template = "$HOME/llvm/utils/NightlyTestTemplate.html";
43 $CVSRootDir = $ARGV[0];
48 # Calculate the date prefix...
50 my $DATE = sprintf "%4d-%02d-%02d", $TIME[5]+1900, $TIME[4]+1, $TIME[3];
51 my $DateString = strftime "%B %d, %Y", localtime;
53 my $Prefix = "$WebDir/$DATE";
56 print "CVS Root = $CVSRootDir\n";
57 print "BuildDir = $BuildDir\n";
58 print "WebDir = $WebDir\n";
59 print "Prefix = $Prefix\n";
62 # Create the CVS repository directory
64 mkdir $BuildDir or die "Could not create CVS checkout directory!";
66 chdir $BuildDir or die "Could not change to CVS checkout directory!";
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"
72 chdir "llvm" or die "Could not change into llvm directory!";
74 # Read in the HTML template file...
76 open (TEMPLATEFILE, $Template) or die "Could not open file 'llvm/$Template'!";
77 my $TemplateContents = <TEMPLATEFILE>;
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`;
91 # Build the entire tree, saving build messages to the build log
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";
99 # Change the Makefile.config to not strip executables...
100 system "echo 'KEEP_SYMBOLS := 1' >> Makefile.config";
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";
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`;
114 sub AddPreTag { # Add pre tags around nonempty list, or convert to "none"
116 if (length) { return "<pre> $_</pre>"; } else { "<b>none</b><br>"; }
119 # Get warnings from the build
120 my @Warn = split "\n", `grep -E 'warning:|Entering dir' $Prefix-Build-Log.txt`;
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
131 push @Warnings, "$CurDir/$Warning"; # Add directory to warning...
134 my $WarningsList = AddPreTag join "\n ", @Warnings;
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";
141 # Extract some information from the CVS history... use a hash so no duplicate
143 my (%AddedFiles, %ModifiedFiles, %RemovedFiles,
144 %UsersCommitted, %UsersUpdated);
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, "", "");
154 #print "Ty = $Type Date = '$Date' UID=$UID Rev=$Rev File = '$Filename'\n";
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;
166 $UsersUpdated{$UID} = 1;
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;
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...
180 map {s/.html//; $_} reverse sort grep /[-0-9]+.html/, readdir DH;
183 splice @PrevDays, 20; # Trim down list to something reasonable...
185 my $PrevDaysList = # Format list for sidebar
186 join "\n ", map { "<a href=\"$_.html\">$_</a><br>" } @PrevDays;
189 # Remove the cvs tree...
191 system "rm -rf $BuildDir" if (!$NOCHECKOUT and !$NOREMOVE);
193 # Print out information...
195 print "DateString: $DateString\n";
196 print "CVS Checkout: $CVSCheckoutTime seconds\n";
197 print "Files/Dirs/LOC in CVS: $NumFilesInCVS/$NumDirsInCVS/$LOC\n";
199 print "Build Time: $BuildTime seconds\n";
200 print "Libraries/Executables/Objects built: $NumLibraries/$NumExecutables/$NumObjects\n";
202 print "WARNINGS:\n $WarningsList\n";
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";
210 print "Previous Days =\n $PrevDaysList\n";
214 chdir $WebDir or die "Could not change into web directory!";
216 eval "\$Output = <<ENDOFFILE;$TemplateContents\nENDOFFILE\n";
217 open(OUTFILE, ">$DATE.html") or die "Cannot open output file!";
218 print OUTFILE $Output;
221 # Change the index.html symlink...
222 system "ln -sf $DATE.html index.html";
225 my ($Val, $Filename) = @_;
227 if (open FILE, $Filename) {
228 @Records = grep !/$DATE/, split "\n", <FILE>;
231 push @Records, "$DATE: $Val";
232 open FILE, ">$Filename" or die "Couldn't open data file $Filename";
233 print FILE (join "\n", @Records), "\n";
238 # Add information to the files which accumulate information for graphs...
239 AddRecord($LOC, "running_loc.txt");
240 AddRecord($BuildTime, "running_build_time.txt");