blob: 33c2035643106bca8fab40c276a3de6bfbdae799 [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
Chris Lattnerb3440302003-01-22 16:14:05 +000024sub ReadFile {
25 if (open (FILE, $_[0])) {
26 my $Ret = <FILE>;
27 close FILE;
28 return $Ret;
29 } else {
30 print "Could not open file '$_[0]' for reading!";
31 return "";
32 }
33}
34
Chris Lattner2f8cb572003-01-20 18:05:27 +000035sub WriteFile { # (filename, contents)
36 open (FILE, ">$_[0]") or die "Could not open file '$_[0]' for writing!";
37 print FILE $_[1];
38 close FILE;
39}
40
41sub GetRegex { # (Regex with ()'s, value)
42 $_[1] =~ /$_[0]/;
43 return $1;
44}
45
46sub AddPreTag { # Add pre tags around nonempty list, or convert to "none"
47 $_ = shift;
Chris Lattner1cbc0a62003-01-20 19:18:44 +000048 if (length) { return "<ul><pre>$_</pre></ul>"; } else { "<b>none</b><br>"; }
Chris Lattner2f8cb572003-01-20 18:05:27 +000049}
50
51sub GetDir {
52 my $Suffix = shift;
53 opendir DH, $WebDir;
54 my @Result = reverse sort grep !/$DATE/, grep /[-0-9]+$Suffix/, readdir DH;
55 closedir DH;
56 return @Result;
57}
58
59# DiffFiles - Diff the current version of the file against the last version of
60# the file, reporting things added and removed. This is used to report, for
61# example, added and removed warnings. This returns a pair (added, removed)
62#
63sub DiffFiles {
64 my $Suffix = shift;
65 my @Others = GetDir $Suffix;
66 if (@Others == 0) { # No other files? We added all entries...
67 return (`cat $WebDir/$DATE$Suffix`, "");
68 }
69 # Diff the files now...
70 my @Diffs = split "\n", `diff $WebDir/$DATE$Suffix $WebDir/$Others[0]`;
71 my $Added = join "\n", grep /^</, @Diffs;
72 my $Removed = join "\n", grep /^>/, @Diffs;
Chris Lattner1cbc0a62003-01-20 19:18:44 +000073 $Added =~ s/^< //gm;
74 $Removed =~ s/^> //gm;
Chris Lattner2f8cb572003-01-20 18:05:27 +000075 return ($Added, $Removed);
76}
77
78
Chris Lattner4c7e3032003-01-20 06:11:03 +000079# Command line argument settings...
80my $NOCHECKOUT = 0;
81my $NOREMOVE = 0;
Chris Lattnerb3440302003-01-22 16:14:05 +000082my $NOTEST = 0;
Chris Lattner4c7e3032003-01-20 06:11:03 +000083my $MAKEOPTS = "";
84
85# Parse arguments...
86while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
87 shift;
88 last if /^--$/; # Stop processing arguments on --
89
90 # List command line options here...
91 if (/^-nocheckout$/) { $NOCHECKOUT = 1; next; }
92 if (/^-noremove$/) { $NOREMOVE = 1; next; }
Chris Lattnerb3440302003-01-22 16:14:05 +000093 if (/^-notest$/) { $NOTEST = 1; next; }
Chris Lattner4c7e3032003-01-20 06:11:03 +000094 if (/^-parallel$/) { $MAKEOPTS = "-j2 -l3.0"; next; }
95
96 print "Unknown option: $_ : ignoring!\n";
97}
98
Chris Lattner2f8cb572003-01-20 18:05:27 +000099die "Must specify 0 or 3 options!" if (@ARGV != 0 and @ARGV != 3);
Chris Lattner4c7e3032003-01-20 06:11:03 +0000100
101# FIXME: This should just be utils/...
102my $Template = "$HOME/llvm/utils/NightlyTestTemplate.html";
103
104if (@ARGV == 3) {
105 $CVSRootDir = $ARGV[0];
106 $BuildDir = $ARGV[1];
107 $WebDir = $ARGV[2];
108}
109
Chris Lattner4c7e3032003-01-20 06:11:03 +0000110my $Prefix = "$WebDir/$DATE";
111
112if (0) {
113 print "CVS Root = $CVSRootDir\n";
114 print "BuildDir = $BuildDir\n";
115 print "WebDir = $WebDir\n";
116 print "Prefix = $Prefix\n";
117}
118
Chris Lattnerb3440302003-01-22 16:14:05 +0000119
120#
Chris Lattner4c7e3032003-01-20 06:11:03 +0000121# Create the CVS repository directory
Chris Lattnerb3440302003-01-22 16:14:05 +0000122#
Chris Lattner4c7e3032003-01-20 06:11:03 +0000123if (!$NOCHECKOUT) {
124 mkdir $BuildDir or die "Could not create CVS checkout directory!";
125}
126chdir $BuildDir or die "Could not change to CVS checkout directory!";
127
Chris Lattnerb3440302003-01-22 16:14:05 +0000128
129#
Chris Lattner4c7e3032003-01-20 06:11:03 +0000130# Check out the llvm tree, saving CVS messages to the cvs log...
Chris Lattnerb3440302003-01-22 16:14:05 +0000131#
Chris Lattner4c7e3032003-01-20 06:11:03 +0000132system "(time -p cvs -d $CVSRootDir co llvm) > $Prefix-CVS-Log.txt 2>&1"
133 if (!$NOCHECKOUT);
134
135chdir "llvm" or die "Could not change into llvm directory!";
136
137# Read in the HTML template file...
138undef $/;
Chris Lattnerb3440302003-01-22 16:14:05 +0000139my $TemplateContents = ReadFile $Template;
Chris Lattner4c7e3032003-01-20 06:11:03 +0000140
Chris Lattnerb3440302003-01-22 16:14:05 +0000141
142#
Chris Lattner4c7e3032003-01-20 06:11:03 +0000143# Get some static statistics about the current state of CVS
Chris Lattnerb3440302003-01-22 16:14:05 +0000144#
Chris Lattner4c7e3032003-01-20 06:11:03 +0000145my $CVSCheckoutTime = GetRegex "([0-9.]+)", `grep '^real' $Prefix-CVS-Log.txt`;
146my $NumFilesInCVS = `grep ^U $Prefix-CVS-Log.txt | wc -l` + 0;
147my $NumDirsInCVS = `grep '^cvs checkout' $Prefix-CVS-Log.txt | wc -l` + 0;
148$LOC = GetRegex "([0-9]+) +total", `wc -l \`utils/getsrcs.sh\` | grep total`;
149
Chris Lattnerb3440302003-01-22 16:14:05 +0000150#
Chris Lattner4c7e3032003-01-20 06:11:03 +0000151# Build the entire tree, saving build messages to the build log
Chris Lattnerb3440302003-01-22 16:14:05 +0000152#
Chris Lattner4c7e3032003-01-20 06:11:03 +0000153if (!$NOCHECKOUT) {
154 # Change the Makefile.config to build into the local directory...
155 rename "Makefile.config", "Makefile.config.orig";
156 system "sed '/^LLVM_OBJ_DIR/d' < Makefile.config.orig > Makefile.config";
157 system "echo >> Makefile.config";
158 system "echo 'LLVM_OBJ_DIR := .' >> Makefile.config";
159
160 # Change the Makefile.config to not strip executables...
161 system "echo 'KEEP_SYMBOLS := 1' >> Makefile.config";
162
163 # Build the entire tree, capturing the output into $Prefix-Build-Log.txt
164 system "(time -p gmake $MAKEOPTS) > $Prefix-Build-Log.txt 2>&1";
165}
166
Chris Lattnerb3440302003-01-22 16:14:05 +0000167
168#
Chris Lattner4c7e3032003-01-20 06:11:03 +0000169# Get some statistics about the build...
Chris Lattnerb3440302003-01-22 16:14:05 +0000170#
Chris Lattner4c7e3032003-01-20 06:11:03 +0000171my @Linked = split '\n', `grep Linking $Prefix-Build-Log.txt`;
172my $NumExecutables = scalar(grep(/executable/, @Linked));
173my $NumLibraries = scalar(grep(!/executable/, @Linked));
174my $NumObjects = `grep '^Compiling' $Prefix-Build-Log.txt | wc -l` + 0;
175my $BuildTime = GetRegex "([0-9.]+)", `grep '^real' $Prefix-Build-Log.txt`;
Chris Lattnerb3440302003-01-22 16:14:05 +0000176my $BuildError = "";
177if (`grep '^gmake: .*Error' $Prefix-Build-Log.txt | wc -l` + 0) {
178 $BuildError = "<h3>Build error: compilation <a href=\"$DATE-Build-Log.txt\">"
179 . "aborted</a></h3>";
180}
Chris Lattner4c7e3032003-01-20 06:11:03 +0000181
182
Chris Lattnerb3440302003-01-22 16:14:05 +0000183#
Chris Lattner4c7e3032003-01-20 06:11:03 +0000184# Get warnings from the build
Chris Lattnerb3440302003-01-22 16:14:05 +0000185#
Chris Lattner4c7e3032003-01-20 06:11:03 +0000186my @Warn = split "\n", `grep -E 'warning:|Entering dir' $Prefix-Build-Log.txt`;
187my @Warnings;
188my $CurDir = "";
189
190foreach $Warning (@Warn) {
191 if ($Warning =~ m/Entering directory \`([^\`]+)\'/) {
192 $CurDir = $1; # Keep track of directory warning is in...
193 if ($CurDir =~ m|$BuildDir/llvm/(.*)|) { # Remove buildir prefix if included
194 $CurDir = $1;
195 }
196 } else {
197 push @Warnings, "$CurDir/$Warning"; # Add directory to warning...
198 }
199}
Chris Lattner1cbc0a62003-01-20 19:18:44 +0000200my $WarningsFile = join "\n", @Warnings;
201my $WarningsList = AddPreTag $WarningsFile;
202$WarningsFile =~ s/:[0-9]+:/::/g;
Chris Lattner4c7e3032003-01-20 06:11:03 +0000203
Chris Lattner2f8cb572003-01-20 18:05:27 +0000204# Emit the warnings file, so we can diff...
205WriteFile "$WebDir/$DATE-Warnings.txt", $WarningsFile . "\n";
206my ($WarningsAdded, $WarningsRemoved) = DiffFiles "-Warnings.txt";
207$WarningsAdded = AddPreTag $WarningsAdded;
208$WarningsRemoved = AddPreTag $WarningsRemoved;
Chris Lattner4c7e3032003-01-20 06:11:03 +0000209
Chris Lattnerb3440302003-01-22 16:14:05 +0000210
211#
Chris Lattner4c7e3032003-01-20 06:11:03 +0000212# Get some statistics about CVS commits over the current day...
Chris Lattnerb3440302003-01-22 16:14:05 +0000213#
Chris Lattner4c7e3032003-01-20 06:11:03 +0000214@CVSHistory = split "\n", `cvs history -D '1 day ago' -a -xAMROCGUW`;
215#print join "\n", @CVSHistory; print "\n";
216
217# Extract some information from the CVS history... use a hash so no duplicate
218# stuff is stored.
219my (%AddedFiles, %ModifiedFiles, %RemovedFiles,
220 %UsersCommitted, %UsersUpdated);
221
222# Loop over every record from the CVS history, filling in the hashes.
223foreach $File (@CVSHistory) {
224 my ($Type, $Date, $UID, $Rev, $Filename);
225 if ($File =~ /([AMR]) ([-:0-9 ]+\+[0-9]+) ([^ ]+) ([0-9.]+) +([^ ]+) +([^ ]+)/) {
226 ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, $4, "$6/$5");
227 } elsif ($File =~ /([OCGUW]) ([-:0-9 ]+\+[0-9]+) ([^ ]+)/) {
228 ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", "");
229 }
230 #print "Ty = $Type Date = '$Date' UID=$UID Rev=$Rev File = '$Filename'\n";
231
232 if ($Type eq 'M') { # Modified
233 $ModifiedFiles{$Filename} = 1;
234 $UsersCommitted{$UID} = 1;
235 } elsif ($Type eq 'A') { # Added
236 $AddedFiles{$Filename} = 1;
237 $UsersCommitted{$UID} = 1;
238 } elsif ($Type eq 'R') { # Removed
239 $RemovedFiles{$Filename} = 1;
240 $UsersCommitted{$UID} = 1;
241 } else {
242 $UsersUpdated{$UID} = 1;
243 }
244}
245
Chris Lattner1cbc0a62003-01-20 19:18:44 +0000246my $UserCommitList = join "\n", keys %UsersCommitted;
247my $UserUpdateList = join "\n", keys %UsersUpdated;
248my $AddedFilesList = AddPreTag join "\n", keys %AddedFiles;
249my $ModifiedFilesList = AddPreTag join "\n", keys %ModifiedFiles;
250my $RemovedFilesList = AddPreTag join "\n", keys %RemovedFiles;
Chris Lattner4c7e3032003-01-20 06:11:03 +0000251
Chris Lattnerb3440302003-01-22 16:14:05 +0000252#
253# Run the nightly programs tests...
254#
255chdir "test/Programs" or die "Could not change into programs testdir!";
256
257# Run the programs tests... creating a report.nightly.html file
258system "gmake $MAKEOPTS report.nightly.html TEST=nightly "
259 . "> $Prefix-ProgramTest.txt 2>&1" if (!$NOTEST);
260
261my $ProgramsTable = ReadFile "report.nightly.html";
262
263#
Chris Lattner4c7e3032003-01-20 06:11:03 +0000264# Get a list of the previous days that we can link to...
Chris Lattnerb3440302003-01-22 16:14:05 +0000265#
Chris Lattner2f8cb572003-01-20 18:05:27 +0000266my @PrevDays = map {s/.html//; $_} GetDir ".html";
Chris Lattner4c7e3032003-01-20 06:11:03 +0000267
268splice @PrevDays, 20; # Trim down list to something reasonable...
269
270my $PrevDaysList = # Format list for sidebar
271 join "\n ", map { "<a href=\"$_.html\">$_</a><br>" } @PrevDays;
272
Chris Lattnerb3440302003-01-22 16:14:05 +0000273
Chris Lattner4c7e3032003-01-20 06:11:03 +0000274#
275# Remove the cvs tree...
276#
Chris Lattnerb3440302003-01-22 16:14:05 +0000277chdir $WebDir or die "Could not change into web directory!";
Chris Lattner4c7e3032003-01-20 06:11:03 +0000278system "rm -rf $BuildDir" if (!$NOCHECKOUT and !$NOREMOVE);
279
Chris Lattnerb3440302003-01-22 16:14:05 +0000280
281#
Chris Lattner4c7e3032003-01-20 06:11:03 +0000282# Print out information...
Chris Lattnerb3440302003-01-22 16:14:05 +0000283#
Chris Lattner4c7e3032003-01-20 06:11:03 +0000284if (0) {
285 print "DateString: $DateString\n";
286 print "CVS Checkout: $CVSCheckoutTime seconds\n";
287 print "Files/Dirs/LOC in CVS: $NumFilesInCVS/$NumDirsInCVS/$LOC\n";
288
289 print "Build Time: $BuildTime seconds\n";
290 print "Libraries/Executables/Objects built: $NumLibraries/$NumExecutables/$NumObjects\n";
291
292 print "WARNINGS:\n $WarningsList\n";
293
294
295 print "Users committed: $UserCommitList\n";
296 print "Added Files: \n $AddedFilesList\n";
297 print "Modified Files: \n $ModifiedFilesList\n";
298 print "Removed Files: \n $RemovedFilesList\n";
299
300 print "Previous Days =\n $PrevDaysList\n";
301}
302
Chris Lattnerb3440302003-01-22 16:14:05 +0000303
Chris Lattner2f8cb572003-01-20 18:05:27 +0000304#
305# Output the files...
306#
307
308# Main HTML file...
Chris Lattner4c7e3032003-01-20 06:11:03 +0000309my $Output;
310eval "\$Output = <<ENDOFFILE;$TemplateContents\nENDOFFILE\n";
Chris Lattner2f8cb572003-01-20 18:05:27 +0000311WriteFile "$DATE.html", $Output;
Chris Lattner4c7e3032003-01-20 06:11:03 +0000312
313# Change the index.html symlink...
314system "ln -sf $DATE.html index.html";
315
316sub AddRecord {
317 my ($Val, $Filename) = @_;
318 my @Records;
319 if (open FILE, $Filename) {
320 @Records = grep !/$DATE/, split "\n", <FILE>;
321 close FILE;
322 }
323 push @Records, "$DATE: $Val";
Chris Lattner2f8cb572003-01-20 18:05:27 +0000324 WriteFile $Filename, (join "\n", @Records) . "\n";
Chris Lattner4c7e3032003-01-20 06:11:03 +0000325 return @Records;
326}
327
328# Add information to the files which accumulate information for graphs...
329AddRecord($LOC, "running_loc.txt");
330AddRecord($BuildTime, "running_build_time.txt");