blob: f3170b974341c30450c3bcfd91d470dd7504629e [file] [log] [blame]
Chris Lattner4c7e3032003-01-20 06:11:03 +00001#!/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#
12use POSIX qw(strftime);
13
Chris Lattner2f8cb572003-01-20 18:05:27 +000014my $HOME = $ENV{HOME};
15my $CVSRootDir = "/home/vadve/vadve/Research/DynOpt/CVSRepository";
16my $BuildDir = "$HOME/buildtest";
17my $WebDir = "$HOME/cvs/testresults-X86";
18
19# Calculate the date prefix...
20@TIME = localtime;
21my $DATE = sprintf "%4d-%02d-%02d", $TIME[5]+1900, $TIME[4]+1, $TIME[3];
22my $DateString = strftime "%B %d, %Y", localtime;
23
24sub 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
30sub GetRegex { # (Regex with ()'s, value)
31 $_[1] =~ /$_[0]/;
32 return $1;
33}
34
35sub AddPreTag { # Add pre tags around nonempty list, or convert to "none"
36 $_ = shift;
Chris Lattner1cbc0a62003-01-20 19:18:44 +000037 if (length) { return "<ul><pre>$_</pre></ul>"; } else { "<b>none</b><br>"; }
Chris Lattner2f8cb572003-01-20 18:05:27 +000038}
39
40sub 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#
52sub 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;
Chris Lattner1cbc0a62003-01-20 19:18:44 +000062 $Added =~ s/^< //gm;
63 $Removed =~ s/^> //gm;
Chris Lattner2f8cb572003-01-20 18:05:27 +000064 return ($Added, $Removed);
65}
66
67
Chris Lattner4c7e3032003-01-20 06:11:03 +000068# Command line argument settings...
69my $NOCHECKOUT = 0;
70my $NOREMOVE = 0;
71my $MAKEOPTS = "";
72
73# Parse arguments...
74while (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 Lattner2f8cb572003-01-20 18:05:27 +000086die "Must specify 0 or 3 options!" if (@ARGV != 0 and @ARGV != 3);
Chris Lattner4c7e3032003-01-20 06:11:03 +000087
88# FIXME: This should just be utils/...
89my $Template = "$HOME/llvm/utils/NightlyTestTemplate.html";
90
91if (@ARGV == 3) {
92 $CVSRootDir = $ARGV[0];
93 $BuildDir = $ARGV[1];
94 $WebDir = $ARGV[2];
95}
96
Chris Lattner4c7e3032003-01-20 06:11:03 +000097my $Prefix = "$WebDir/$DATE";
98
99if (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
107if (!$NOCHECKOUT) {
108 mkdir $BuildDir or die "Could not create CVS checkout directory!";
109}
110chdir $BuildDir or die "Could not change to CVS checkout directory!";
111
112# Check out the llvm tree, saving CVS messages to the cvs log...
113system "(time -p cvs -d $CVSRootDir co llvm) > $Prefix-CVS-Log.txt 2>&1"
114 if (!$NOCHECKOUT);
115
116chdir "llvm" or die "Could not change into llvm directory!";
117
118# Read in the HTML template file...
119undef $/;
120open (TEMPLATEFILE, $Template) or die "Could not open file 'llvm/$Template'!";
121my $TemplateContents = <TEMPLATEFILE>;
122close(TEMPLATEFILE);
123
Chris Lattner4c7e3032003-01-20 06:11:03 +0000124# Get some static statistics about the current state of CVS
125my $CVSCheckoutTime = GetRegex "([0-9.]+)", `grep '^real' $Prefix-CVS-Log.txt`;
126my $NumFilesInCVS = `grep ^U $Prefix-CVS-Log.txt | wc -l` + 0;
127my $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
131if (!$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...
146my @Linked = split '\n', `grep Linking $Prefix-Build-Log.txt`;
147my $NumExecutables = scalar(grep(/executable/, @Linked));
148my $NumLibraries = scalar(grep(!/executable/, @Linked));
149my $NumObjects = `grep '^Compiling' $Prefix-Build-Log.txt | wc -l` + 0;
150my $BuildTime = GetRegex "([0-9.]+)", `grep '^real' $Prefix-Build-Log.txt`;
151
152
Chris Lattner4c7e3032003-01-20 06:11:03 +0000153# Get warnings from the build
154my @Warn = split "\n", `grep -E 'warning:|Entering dir' $Prefix-Build-Log.txt`;
155my @Warnings;
156my $CurDir = "";
157
158foreach $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}
Chris Lattner1cbc0a62003-01-20 19:18:44 +0000168my $WarningsFile = join "\n", @Warnings;
169my $WarningsList = AddPreTag $WarningsFile;
170$WarningsFile =~ s/:[0-9]+:/::/g;
Chris Lattner4c7e3032003-01-20 06:11:03 +0000171
Chris Lattner2f8cb572003-01-20 18:05:27 +0000172# Emit the warnings file, so we can diff...
173WriteFile "$WebDir/$DATE-Warnings.txt", $WarningsFile . "\n";
174my ($WarningsAdded, $WarningsRemoved) = DiffFiles "-Warnings.txt";
175$WarningsAdded = AddPreTag $WarningsAdded;
176$WarningsRemoved = AddPreTag $WarningsRemoved;
Chris Lattner4c7e3032003-01-20 06:11:03 +0000177
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";
181
182# Extract some information from the CVS history... use a hash so no duplicate
183# stuff is stored.
184my (%AddedFiles, %ModifiedFiles, %RemovedFiles,
185 %UsersCommitted, %UsersUpdated);
186
187# Loop over every record from the CVS history, filling in the hashes.
188foreach $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, "", "");
194 }
195 #print "Ty = $Type Date = '$Date' UID=$UID Rev=$Rev File = '$Filename'\n";
196
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;
206 } else {
207 $UsersUpdated{$UID} = 1;
208 }
209}
210
Chris Lattner1cbc0a62003-01-20 19:18:44 +0000211my $UserCommitList = join "\n", keys %UsersCommitted;
212my $UserUpdateList = join "\n", keys %UsersUpdated;
213my $AddedFilesList = AddPreTag join "\n", keys %AddedFiles;
214my $ModifiedFilesList = AddPreTag join "\n", keys %ModifiedFiles;
215my $RemovedFilesList = AddPreTag join "\n", keys %RemovedFiles;
Chris Lattner4c7e3032003-01-20 06:11:03 +0000216
217# Get a list of the previous days that we can link to...
Chris Lattner2f8cb572003-01-20 18:05:27 +0000218my @PrevDays = map {s/.html//; $_} GetDir ".html";
Chris Lattner4c7e3032003-01-20 06:11:03 +0000219
220splice @PrevDays, 20; # Trim down list to something reasonable...
221
222my $PrevDaysList = # Format list for sidebar
223 join "\n ", map { "<a href=\"$_.html\">$_</a><br>" } @PrevDays;
224
225#
226# Remove the cvs tree...
227#
228system "rm -rf $BuildDir" if (!$NOCHECKOUT and !$NOREMOVE);
229
230# Print out information...
231if (0) {
232 print "DateString: $DateString\n";
233 print "CVS Checkout: $CVSCheckoutTime seconds\n";
234 print "Files/Dirs/LOC in CVS: $NumFilesInCVS/$NumDirsInCVS/$LOC\n";
235
236 print "Build Time: $BuildTime seconds\n";
237 print "Libraries/Executables/Objects built: $NumLibraries/$NumExecutables/$NumObjects\n";
238
239 print "WARNINGS:\n $WarningsList\n";
240
241
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";
246
247 print "Previous Days =\n $PrevDaysList\n";
248}
249
Chris Lattner2f8cb572003-01-20 18:05:27 +0000250#
251# Output the files...
252#
253
254# Main HTML file...
Chris Lattner4c7e3032003-01-20 06:11:03 +0000255chdir $WebDir or die "Could not change into web directory!";
256my $Output;
257eval "\$Output = <<ENDOFFILE;$TemplateContents\nENDOFFILE\n";
Chris Lattner2f8cb572003-01-20 18:05:27 +0000258WriteFile "$DATE.html", $Output;
Chris Lattner4c7e3032003-01-20 06:11:03 +0000259
260# Change the index.html symlink...
261system "ln -sf $DATE.html index.html";
262
263sub AddRecord {
264 my ($Val, $Filename) = @_;
265 my @Records;
266 if (open FILE, $Filename) {
267 @Records = grep !/$DATE/, split "\n", <FILE>;
268 close FILE;
269 }
270 push @Records, "$DATE: $Val";
Chris Lattner2f8cb572003-01-20 18:05:27 +0000271 WriteFile $Filename, (join "\n", @Records) . "\n";
Chris Lattner4c7e3032003-01-20 06:11:03 +0000272 return @Records;
273}
274
275# Add information to the files which accumulate information for graphs...
276AddRecord($LOC, "running_loc.txt");
277AddRecord($BuildTime, "running_build_time.txt");