blob: 2e0204c92212eb86f99b234a55dbd917f090056b [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
14# Command line argument settings...
15my $NOCHECKOUT = 0;
16my $NOREMOVE = 0;
17my $MAKEOPTS = "";
18
19# Parse arguments...
20while (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
32die "Must specify 0 or 4 options!" if (@ARGV != 0 and @ARGV != 4);
33
34my $HOME = $ENV{HOME};
35my $CVSRootDir = "/home/vadve/vadve/Research/DynOpt/CVSRepository";
36my $BuildDir = "$HOME/buildtest";
37my $WebDir = "$HOME/cvs/testresults-X86";
38
39# FIXME: This should just be utils/...
40my $Template = "$HOME/llvm/utils/NightlyTestTemplate.html";
41
42if (@ARGV == 3) {
43 $CVSRootDir = $ARGV[0];
44 $BuildDir = $ARGV[1];
45 $WebDir = $ARGV[2];
46}
47
48# Calculate the date prefix...
49@TIME = localtime;
50my $DATE = sprintf "%4d-%02d-%02d", $TIME[5]+1900, $TIME[4]+1, $TIME[3];
51my $DateString = strftime "%B %d, %Y", localtime;
52
53my $Prefix = "$WebDir/$DATE";
54
55if (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
63if (!$NOCHECKOUT) {
64 mkdir $BuildDir or die "Could not create CVS checkout directory!";
65}
66chdir $BuildDir or die "Could not change to CVS checkout directory!";
67
68# Check out the llvm tree, saving CVS messages to the cvs log...
69system "(time -p cvs -d $CVSRootDir co llvm) > $Prefix-CVS-Log.txt 2>&1"
70 if (!$NOCHECKOUT);
71
72chdir "llvm" or die "Could not change into llvm directory!";
73
74# Read in the HTML template file...
75undef $/;
76open (TEMPLATEFILE, $Template) or die "Could not open file 'llvm/$Template'!";
77my $TemplateContents = <TEMPLATEFILE>;
78close(TEMPLATEFILE);
79
80sub GetRegex {
81 $_[1] =~ /$_[0]/;
82 return $1;
83}
84
85# Get some static statistics about the current state of CVS
86my $CVSCheckoutTime = GetRegex "([0-9.]+)", `grep '^real' $Prefix-CVS-Log.txt`;
87my $NumFilesInCVS = `grep ^U $Prefix-CVS-Log.txt | wc -l` + 0;
88my $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
92if (!$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...
107my @Linked = split '\n', `grep Linking $Prefix-Build-Log.txt`;
108my $NumExecutables = scalar(grep(/executable/, @Linked));
109my $NumLibraries = scalar(grep(!/executable/, @Linked));
110my $NumObjects = `grep '^Compiling' $Prefix-Build-Log.txt | wc -l` + 0;
111my $BuildTime = GetRegex "([0-9.]+)", `grep '^real' $Prefix-Build-Log.txt`;
112
113
114sub 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
120my @Warn = split "\n", `grep -E 'warning:|Entering dir' $Prefix-Build-Log.txt`;
121my @Warnings;
122my $CurDir = "";
123
124foreach $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}
134my $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.
143my (%AddedFiles, %ModifiedFiles, %RemovedFiles,
144 %UsersCommitted, %UsersUpdated);
145
146# Loop over every record from the CVS history, filling in the hashes.
147foreach $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
170my $UserCommitList = join "\n ", keys %UsersCommitted;
171my $UserUpdateList = join "\n ", keys %UsersUpdated;
172my $AddedFilesList = AddPreTag join "\n ", keys %AddedFiles;
173my $ModifiedFilesList = AddPreTag join "\n ", keys %ModifiedFiles;
174my $RemovedFilesList = AddPreTag join "\n ", keys %RemovedFiles;
175
176# Get a list of the previous days that we can link to...
177system "rm -f $WebDir/$DATE.html"; # Don't relist self if regenerating...
178opendir DH, $WebDir;
179my @PrevDays =
180 map {s/.html//; $_} reverse sort grep /[-0-9]+.html/, readdir DH;
181closedir DH;
182
183splice @PrevDays, 20; # Trim down list to something reasonable...
184
185my $PrevDaysList = # Format list for sidebar
186 join "\n ", map { "<a href=\"$_.html\">$_</a><br>" } @PrevDays;
187
188#
189# Remove the cvs tree...
190#
191system "rm -rf $BuildDir" if (!$NOCHECKOUT and !$NOREMOVE);
192
193# Print out information...
194if (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...
214chdir $WebDir or die "Could not change into web directory!";
215my $Output;
216eval "\$Output = <<ENDOFFILE;$TemplateContents\nENDOFFILE\n";
217open(OUTFILE, ">$DATE.html") or die "Cannot open output file!";
218print OUTFILE $Output;
219close(OUTFILE);
220
221# Change the index.html symlink...
222system "ln -sf $DATE.html index.html";
223
224sub 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...
239AddRecord($LOC, "running_loc.txt");
240AddRecord($BuildTime, "running_build_time.txt");