Improve handling of SelectInst.
[oota-llvm.git] / utils / NewNightlyTest.pl
1 #!/usr/bin/perl
2 use POSIX qw(strftime);
3 use File::Copy;
4 use Socket;
5
6 #
7 # Program:  NewNightlyTest.pl
8 #
9 # Synopsis: Perform a series of tests which are designed to be run nightly.
10 #           This is used to keep track of the status of the LLVM tree, tracking
11 #           regressions and performance changes. Submits this information 
12 #           to llvm.org where it is placed into the nightlytestresults database.
13 #
14 # Modified heavily by Patrick Jenkins, July 2006
15 #
16 # Syntax:   NightlyTest.pl [OPTIONS] [CVSROOT BUILDDIR WEBDIR]
17 #   where
18 # OPTIONS may include one or more of the following:
19 #  -nocheckout      Do not create, checkout, update, or configure
20 #                   the source tree.
21 #  -noremove        Do not remove the BUILDDIR after it has been built.
22 #  -noremoveresults Do not remove the WEBDIR after it has been built.
23 #  -nobuild         Do not build llvm. If tests are enabled perform them
24 #                   on the llvm build specified in the build directory
25 #  -notest          Do not even attempt to run the test programs. Implies
26 #                   -norunningtests.
27 #  -norunningtests  Do not run the Olden benchmark suite with
28 #                   LARGE_PROBLEM_SIZE enabled.
29 #  -nodejagnu       Do not run feature or regression tests
30 #  -parallel        Run two parallel jobs with GNU Make.
31 #  -release         Build an LLVM Release version
32 #  -enable-llcbeta  Enable testing of beta features in llc.
33 #  -disable-llc     Disable LLC tests in the nightly tester.
34 #  -disable-jit     Disable JIT tests in the nightly tester.
35 #  -disable-cbe     Disable C backend tests in the nightly tester.
36 #  -verbose         Turn on some debug output
37 #  -debug           Print information useful only to maintainers of this script.
38 #  -nice            Checkout/Configure/Build with "nice" to reduce impact
39 #                   on busy servers.
40 #  -f2c             Next argument specifies path to F2C utility
41 #  -nickname        The next argument specifieds the nickname this script
42 #                   will submit to the nightlytest results repository.
43 #  -gccpath         Path to gcc/g++ used to build LLVM
44 #  -cvstag          Check out a specific CVS tag to build LLVM (useful for
45 #                   testing release branches)
46 #  -target          Specify the target triplet
47 #  -cflags          Next argument specifies that C compilation options that
48 #                   override the default.
49 #  -cxxflags        Next argument specifies that C++ compilation options that
50 #                   override the default.
51 #  -ldflags         Next argument specifies that linker options that override
52 #                   the default.
53 #  -compileflags    Next argument specifies extra options passed to make when
54 #                   building LLVM.
55 #  -use-gmake       Use gmake instead of the default make command to build
56 #                   llvm and run tests.
57 #
58 #  ---------------- Options to configure llvm-test ----------------------------
59 #  -extraflags      Next argument specifies extra options that are passed to
60 #                   compile the tests.
61 #  -noexternals     Do not run the external tests (for cases where povray
62 #                   or SPEC are not installed)
63 #  -with-externals  Specify a directory where the external tests are located.
64 #  -submit-server   Specifies a server to submit the test results too. If this
65 #                   option is not specified it defaults to 
66 #                   llvm.org. This is basically just the address of the 
67 #                   webserver
68 #  -submit-script   Specifies which script to call on the submit server. If
69 #                   this option is not specified it defaults to
70 #                   /nightlytest/NightlyTestAccept.cgi. This is basically 
71 #                   everything after the www.yourserver.org.
72 #
73 # CVSROOT is the CVS repository from which the tree will be checked out,
74 #  specified either in the full :method:user@host:/dir syntax, or
75 #  just /dir if using a local repo.
76 # BUILDDIR is the directory where sources for this test run will be checked out
77 #  AND objects for this test run will be built. This directory MUST NOT
78 #  exist before the script is run; it will be created by the cvs checkout
79 #  process and erased (unless -noremove is specified; see above.)
80 # WEBDIR is the directory into which the test results web page will be written,
81 #  AND in which the "index.html" is assumed to be a symlink to the most recent
82 #  copy of the results. This directory will be created if it does not exist.
83 # LLVMGCCDIR is the directory in which the LLVM GCC Front End is installed
84 #  to. This is the same as you would have for a normal LLVM build.
85 #
86 ##############################################################
87 #
88 # Getting environment variables
89 #
90 ##############################################################
91 my $HOME       = $ENV{'HOME'};
92 my $CVSRootDir = $ENV{'CVSROOT'};
93 $CVSRootDir    = "/home/vadve/shared/PublicCVS" unless $CVSRootDir;
94 my $BuildDir   = $ENV{'BUILDDIR'};
95 $BuildDir      = "$HOME/buildtest" unless $BuildDir;
96 my $WebDir     = $ENV{'WEBDIR'};
97 $WebDir        = "$HOME/cvs/testresults-X86" unless $WebDir;
98
99 ##############################################################
100 #
101 # Calculate the date prefix...
102 #
103 ##############################################################
104 @TIME = localtime;
105 my $DATE = sprintf "%4d-%02d-%02d", $TIME[5]+1900, $TIME[4]+1, $TIME[3];
106 my $DateString = strftime "%B %d, %Y", localtime;
107 my $TestStartTime = gmtime() . "GMT<br>" . localtime() . " (local)";
108
109 ##############################################################
110 #
111 # Parse arguments...
112 #
113 ##############################################################
114 $CONFIGUREARGS="";
115 $nickname="";
116 $NOTEST=0;
117 $NORUNNINGTESTS=0;
118 $MAKECMD="make";
119 $SUBMITSERVER = "llvm.org";
120 $SUBMITSCRIPT = "/nightlytest/NightlyTestAccept.cgi";
121
122 while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
123   shift;
124   last if /^--$/;  # Stop processing arguments on --
125
126   # List command line options here...
127   if (/^-nocheckout$/)     { $NOCHECKOUT = 1; next; }
128   if (/^-nocvsstats$/)     { $NOCVSSTATS = 1; next; }
129   if (/^-noremove$/)       { $NOREMOVE = 1; next; }
130   if (/^-noremoveresults$/){ $NOREMOVERESULTS = 1; next; }
131   if (/^-notest$/)         { $NOTEST = 1; $NORUNNINGTESTS = 1; next; }
132   if (/^-norunningtests$/) { $NORUNNINGTESTS = 1; next; }
133   if (/^-parallel$/)       { $MAKEOPTS = "$MAKEOPTS -j2 -l3.0"; next; }
134   if (/^-release$/)        { $MAKEOPTS = "$MAKEOPTS ENABLE_OPTIMIZED=1 ".
135                              "OPTIMIZE_OPTION=-O2"; $BUILDTYPE="release"; next;}
136   if (/^-enable-llcbeta$/) { $PROGTESTOPTS .= " ENABLE_LLCBETA=1"; next; }
137   if (/^-disable-llc$/)    { $PROGTESTOPTS .= " DISABLE_LLC=1";
138                              $CONFIGUREARGS .= " --disable-llc_diffs"; next; } 
139   if (/^-disable-jit$/)    { $PROGTESTOPTS .= " DISABLE_JIT=1";
140                              $CONFIGUREARGS .= " --disable-jit"; next; }
141   if (/^-disable-cbe$/)    { $PROGTESTOPTS .= " DISABLE_CBE=1"; next; }
142   if (/^-verbose$/)        { $VERBOSE = 1; next; }
143   if (/^-debug$/)          { $DEBUG = 1; next; }
144   if (/^-nice$/)           { $NICE = "nice "; next; }
145   if (/^-f2c$/)            { $CONFIGUREARGS .= " --with-f2c=$ARGV[0]"; 
146                              shift; next; }
147   if (/^-with-externals$/) { $CONFIGUREARGS .= " --with-externals=$ARGV[0]"; 
148                              shift; next; }
149   if (/^-submit-server/)   { $SUBMITSERVER = "$ARGV[0]"; shift; next; }
150   if (/^-submit-script/)   { $SUBMITSCRIPT = "$ARGV[0]"; shift; next; }
151   if (/^-nickname$/)       { $nickname = "$ARGV[0]"; shift; next; } 
152   if (/^-gccpath/)         { $CONFIGUREARGS .= 
153                              " CC=$ARGV[0]/gcc CXX=$ARGV[0]/g++"; 
154                              $GCCPATH=$ARGV[0]; shift;  next; }
155   else                     { $GCCPATH=""; }
156   if (/^-cvstag/)          { $CVSCOOPT .= " -r $ARGV[0]"; shift; next; } 
157   else                     { $CVSCOOPT="";}
158   if (/^-target/)          { $CONFIGUREARGS .= " --target=$ARGV[0]"; 
159                              shift; next; }
160   if (/^-cflags/)          { $MAKEOPTS = "$MAKEOPTS C.Flags=\'$ARGV[0]\'"; 
161                              shift; next; }
162   if (/^-cxxflags/)        { $MAKEOPTS = "$MAKEOPTS CXX.Flags=\'$ARGV[0]\'"; 
163                              shift; next; }
164   if (/^-ldflags/)         { $MAKEOPTS = "$MAKEOPTS LD.Flags=\'$ARGV[0]\'"; 
165                              shift; next; }
166   if (/^-compileflags/)    { $MAKEOPTS = "$MAKEOPTS $ARGV[0]"; shift; next; }
167   if (/^-use-gmake/)       { $MAKECMD = "gmake"; shift; next; }
168   if (/^-compileflags/)    { $MAKEOPTS = "$MAKEOPTS $ARGV[0]"; shift; next; }
169   if (/^-extraflags/)      { $CONFIGUREARGS .= 
170                              " --with-extra-options=\'$ARGV[0]\'"; shift; next;}
171   if (/^-noexternals$/)    { $NOEXTERNALS = 1; next; }
172   if (/^-nodejagnu$/)      { $NODEJAGNU = 1; next; }
173   if (/^-nobuild$/)        { $NOBUILD = 1; next; }
174   print "Unknown option: $_ : ignoring!\n";
175 }
176
177 if ($ENV{'LLVMGCCDIR'}) {
178   $CONFIGUREARGS .= " --with-llvmgccdir=" . $ENV{'LLVMGCCDIR'};
179 }
180 if ($CONFIGUREARGS !~ /--disable-jit/) {
181   $CONFIGUREARGS .= " --enable-jit";
182 }
183
184 if (@ARGV != 0 and @ARGV != 3 and $VERBOSE) {
185   foreach $x (@ARGV) {
186     print "$x\n";
187   }
188   print "Must specify 0 or 3 options!";
189 }
190
191 if (@ARGV == 3) {
192   $CVSRootDir = $ARGV[0];
193   $BuildDir   = $ARGV[1];
194   $WebDir     = $ARGV[2];
195 }
196
197 if ($CVSRootDir eq "" or
198     $BuildDir   eq "" or
199     $WebDir     eq "") {
200   die("please specify a cvs root directory, a build directory, and a ".
201        "web directory");
202  }
203  
204 if ($nickname eq "") {
205   die ("Please invoke NewNightlyTest.pl with command line option " . 
206        "\"-nickname <nickname>\"");
207 }
208
209 if ($BUILDTYPE ne "release") {
210   $BUILDTYPE = "debug";
211 }
212
213 ##############################################################
214 #
215 #define the file names we'll use
216 #
217 ##############################################################
218 my $Prefix = "$WebDir/$DATE";
219 my $BuildLog = "$Prefix-Build-Log.txt";
220 my $CVSLog = "$Prefix-CVS-Log.txt";
221 my $OldenTestsLog = "$Prefix-Olden-tests.txt";
222 my $SingleSourceLog = "$Prefix-SingleSource-ProgramTest.txt.gz";
223 my $MultiSourceLog = "$Prefix-MultiSource-ProgramTest.txt.gz";
224 my $ExternalLog = "$Prefix-External-ProgramTest.txt.gz";
225 my $DejagnuLog = "$Prefix-Dejagnu-testrun.log";
226 my $DejagnuSum = "$Prefix-Dejagnu-testrun.sum";
227 my $DejagnuTestsLog = "$Prefix-DejagnuTests-Log.txt";
228 if (! -d $WebDir) {
229   mkdir $WebDir, 0777;
230   if($VERBOSE){
231     warn "$WebDir did not exist; creating it.\n";
232   }
233 }
234
235 if ($VERBOSE) {
236   print "INITIALIZED\n";
237   print "CVS Root = $CVSRootDir\n";
238   print "BuildDir = $BuildDir\n";
239   print "WebDir   = $WebDir\n";
240   print "Prefix   = $Prefix\n";
241   print "CVSLog   = $CVSLog\n";
242   print "BuildLog = $BuildLog\n";
243 }
244
245 ##############################################################
246 #
247 # Helper functions
248 #
249 ##############################################################
250 sub GetDir {
251   my $Suffix = shift;
252   opendir DH, $WebDir;
253   my @Result = reverse sort grep !/$DATE/, grep /[-0-9]+$Suffix/, readdir DH;
254   closedir DH;
255   return @Result;
256 }
257
258 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
259 #
260 # DiffFiles - Diff the current version of the file against the last version of
261 # the file, reporting things added and removed.  This is used to report, for
262 # example, added and removed warnings.  This returns a pair (added, removed)
263 #
264 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
265 sub DiffFiles {
266   my $Suffix = shift;
267   my @Others = GetDir $Suffix;
268   if (@Others == 0) {  # No other files?  We added all entries...
269     return (`cat $WebDir/$DATE$Suffix`, "");
270   }
271 # Diff the files now...
272   my @Diffs = split "\n", `diff $WebDir/$DATE$Suffix $WebDir/$Others[0]`;
273   my $Added   = join "\n", grep /^</, @Diffs;
274   my $Removed = join "\n", grep /^>/, @Diffs;
275   $Added =~ s/^< //gm;
276   $Removed =~ s/^> //gm;
277   return ($Added, $Removed);
278 }
279
280 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
281 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
282 sub GetRegex {   # (Regex with ()'s, value)
283   $_[1] =~ /$_[0]/m;
284   return $1 
285     if (defined($1));
286   return "0";
287 }
288
289 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
290 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
291 sub GetRegexNum {
292   my ($Regex, $Num, $Regex2, $File) = @_;
293   my @Items = split "\n", `grep '$Regex' $File`;
294   return GetRegex $Regex2, $Items[$Num];
295 }
296
297 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
298 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
299 sub ChangeDir { # directory, logical name
300   my ($dir,$name) = @_;
301   chomp($dir);
302   if ( $VERBOSE ) { print "Changing To: $name ($dir)\n"; }
303   $result = chdir($dir);
304   if (!$result) {
305     print "ERROR!!! Cannot change directory to: $name ($dir) because $!"; 
306     return false;
307   }
308   return true;
309 }
310
311 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
312 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
313 sub ReadFile {
314   if (open (FILE, $_[0])) {
315     undef $/;
316     my $Ret = <FILE>;
317     close FILE;
318     $/ = '\n';
319     return $Ret;
320   } else {
321     print "Could not open file '$_[0]' for reading!\n";
322     return "";
323   }
324 }
325
326 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
327 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
328 sub WriteFile {  # (filename, contents)
329   open (FILE, ">$_[0]") or die "Could not open file '$_[0]' for writing!\n";
330   print FILE $_[1];
331   close FILE;
332 }
333
334 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
335 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
336 sub CopyFile { #filename, newfile
337   my ($file, $newfile) = @_;
338   chomp($file);
339   if ($VERBOSE) { print "Copying $file to $newfile\n"; }
340   copy($file, $newfile);
341 }
342
343 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
344 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
345 sub AddRecord {
346   my ($Val, $Filename,$WebDir) = @_;
347   my @Records;
348   if (open FILE, "$WebDir/$Filename") {
349     @Records = grep !/$DATE/, split "\n", <FILE>;
350     close FILE;
351   }
352   push @Records, "$DATE: $Val";
353   WriteFile "$WebDir/$Filename", (join "\n", @Records) . "\n";
354 }
355
356 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
357 #
358 # FormatTime - Convert a time from 1m23.45 into 83.45
359 #
360 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
361 sub FormatTime {
362   my $Time = shift;
363   if ($Time =~ m/([0-9]+)m([0-9.]+)/) {
364     $Time = sprintf("%7.4f", $1*60.0+$2);
365   }
366   return $Time;
367 }
368
369 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
370 #
371 # This function is meant to read in the dejagnu sum file and 
372 # return a string with only the results (i.e. PASS/FAIL/XPASS/
373 # XFAIL).
374 #
375 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
376 sub GetDejagnuTestResults { # (filename, log)
377     my ($filename, $DejagnuLog) = @_;
378     my @lines;
379     $/ = "\n"; #Make sure we're going line at a time.
380
381     if( $VERBOSE) { print "DEJAGNU TEST RESULTS:\n"; }
382
383     if (open SRCHFILE, $filename) {
384         # Process test results
385         while ( <SRCHFILE> ) {
386             if ( length($_) > 1 ) {
387                 chomp($_);
388                 if ( m/^PASS:/ || m/^XPASS:/ ||
389                      m/^FAIL:/ || m/^XFAIL:/) {
390                     push(@lines, "$_");
391                 }
392             }
393         }
394     }
395     close SRCHFILE;
396
397     my $content = join("\n", @lines);
398     return $content;
399 }
400
401
402
403 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
404 #
405 # This function acts as a mini web browswer submitting data
406 # to our central server via the post method
407 #
408 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
409 sub SendData{
410     $host = $_[0];
411     $file = $_[1];
412     $variables=$_[2];
413
414     $port=80;
415     $socketaddr= sockaddr_in $port, inet_aton $host or die "Bad hostname\n";
416     socket SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp') or 
417       die "Bad socket\n";
418     connect SOCK, $socketaddr or die "Bad connection\n";
419     select((select(SOCK), $| = 1)[0]);
420
421     #creating content here
422     my $content;
423     foreach $key (keys (%$variables)){
424         $value = $variables->{$key};
425         $value =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
426         $content .= "$key=$value&";
427     }
428
429     $length = length($content);
430
431     my $send= "POST $file HTTP/1.0\n";
432     $send.= "Content-Type: application/x-www-form-urlencoded\n";
433     $send.= "Content-length: $length\n\n";
434     $send.= "$content";
435
436     print SOCK $send;
437     my $result;
438     while(<SOCK>){
439         $result  .= $_;
440     }
441     close(SOCK);
442
443     my $sentdata="";
444     foreach $x (keys (%$variables)){
445         $value = $variables->{$x};
446         $sentdata.= "$x  => $value\n";
447     }
448     WriteFile "$Prefix-sentdata.txt", $sentdata;
449     
450
451     return $result;
452 }
453
454 ##############################################################
455 #
456 # Getting Start timestamp
457 #
458 ##############################################################
459 $starttime = `date "+20%y-%m-%d %H:%M:%S"`;
460
461 ##############################################################
462 #
463 # Create the CVS repository directory
464 #
465 ##############################################################
466 if (!$NOCHECKOUT) {
467   if (-d $BuildDir) {
468     if (!$NOREMOVE) {
469       if ( $VERBOSE ) {
470         print "Build directory exists! Removing it\n";
471       }
472       system "rm -rf $BuildDir";
473     } else {
474        die "CVS checkout directory $BuildDir already exists!";
475     }
476   }
477   mkdir $BuildDir or die "Could not create CVS checkout directory $BuildDir!";
478 }
479 ChangeDir( $BuildDir, "CVS checkout directory" );
480
481
482 ##############################################################
483 #
484 # Check out the llvm tree, saving CVS messages to the cvs log...
485 #
486 ##############################################################
487 my $CVSOPT = "";
488 # Use compression if going over ssh.
489 $CVSOPT = "-z3" 
490   if $CVSRootDir =~ /^:ext:/;
491 my $CVSCMD = "$NICE cvs $CVSOPT -d $CVSRootDir co -P $CVSCOOPT";
492 if (!$NOCHECKOUT) {
493   if ( $VERBOSE ) { 
494     print "CHECKOUT STAGE:\n"; 
495     print "( time -p $CVSCMD llvm; cd llvm/projects ; $CVSCMD llvm-test ) " .
496           "> $CVSLog 2>&1\n";
497   }
498   system "( time -p $CVSCMD llvm; cd llvm/projects ; " .
499       "$CVSCMD llvm-test ) > $CVSLog 2>&1";
500   ChangeDir( $BuildDir , "CVS Checkout directory") ;
501 }
502 ChangeDir( "llvm" , "llvm source directory") ;
503
504 ##############################################################
505 #
506 # Get some static statistics about the current state of CVS
507 #
508 # This can probably be put on the server side
509 #
510 ##############################################################
511 my $CVSCheckoutTime_Wall = GetRegex "([0-9.]+)", `grep '^real' $CVSLog`;
512 my $CVSCheckoutTime_User = GetRegex "([0-9.]+)", `grep '^user' $CVSLog`;
513 my $CVSCheckoutTime_Sys = GetRegex "([0-9.]+)", `grep '^sys' $CVSLog`;
514 my $CVSCheckoutTime_CPU = $CVSCheckoutTime_User + $CVSCheckoutTime_Sys;
515
516 my $NumFilesInCVS = `egrep '^U' $CVSLog | wc -l` + 0;
517 my $NumDirsInCVS  = 
518    `egrep '^cvs (checkout|server|update):' $CVSLog | wc -l` + 0;
519
520 ##############################################################
521 #
522 # Extract some information from the CVS history... use a hash so no duplicate
523 # stuff is stored. This gets the history from the previous days worth
524 # of cvs activity and parses it.
525 #
526 ##############################################################
527
528 my (%AddedFiles, %ModifiedFiles, %RemovedFiles, %UsersCommitted, %UsersUpdated);
529
530 if(!$NOCVSSTATS){
531
532   if ($VERBOSE) { print "CVS HISTORY ANALYSIS STAGE\n"; }
533   @CVSHistory = split "\n", `cvs history -D '1 day ago' -a -xAMROCGUW`;
534 #print join "\n", @CVSHistory; print "\n";
535
536   my $DateRE = '[-/:0-9 ]+\+[0-9]+';
537
538 # Loop over every record from the CVS history, filling in the hashes.
539   foreach $File (@CVSHistory) {
540       my ($Type, $Date, $UID, $Rev, $Filename);
541       if ($File =~ /([AMRUGC]) ($DateRE) ([^ ]+) +([^ ]+) +([^ ]+) +([^ ]+)/) {
542           ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, $4, "$6/$5");
543       } elsif ($File =~ /([W]) ($DateRE) ([^ ]+)/) {
544           ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", "");
545       } elsif ($File =~ /([O]) ($DateRE) ([^ ]+) +([^ ]+)/) {
546           ($Type, $Date, $UID, $Rev, $Filename) = ($1, $2, $3, "", "$4/");
547       } else {
548           print "UNMATCHABLE: $File\n";
549           next;
550       }
551       # print "$File\nTy = $Type Date = '$Date' UID=$UID Rev=$Rev File = '$Filename'\n";
552       
553       if ($Filename =~ /^llvm/) {
554           if ($Type eq 'M') {        # Modified
555               $ModifiedFiles{$Filename} = 1;
556               $UsersCommitted{$UID} = 1;
557           } elsif ($Type eq 'A') {   # Added
558               $AddedFiles{$Filename} = 1;
559               $UsersCommitted{$UID} = 1;
560           } elsif ($Type eq 'R') {   # Removed
561               $RemovedFiles{$Filename} = 1;
562               $UsersCommitted{$UID} = 1;
563           } else {
564               $UsersUpdated{$UID} = 1;
565           }
566       }
567   }
568
569   my $TestError = 1;
570
571 }#!NOCVSSTATS
572
573 my $CVSAddedFiles = join "\n", sort keys %AddedFiles;
574 my $CVSModifiedFiles = join "\n", sort keys %ModifiedFiles;
575 my $CVSRemovedFiles = join "\n", sort keys %RemovedFiles;
576 my $UserCommitList = join "\n", sort keys %UsersCommitted;
577 my $UserUpdateList = join "\n", sort keys %UsersUpdated;
578
579 ##############################################################
580 #
581 # Build the entire tree, saving build messages to the build log
582 #
583 ##############################################################
584 if (!$NOCHECKOUT && !$NOBUILD) {
585   my $EXTRAFLAGS = "--enable-spec --with-objroot=.";
586   if ( $VERBOSE ) {
587     print "CONFIGURE STAGE:\n";
588     print "(time -p $NICE ./configure $CONFIGUREARGS $EXTRAFLAGS) " . 
589           "> $BuildLog 2>&1\n";
590   }
591   system "(time -p $NICE ./configure $CONFIGUREARGS $EXTRAFLAGS) " . 
592          "> $BuildLog 2>&1";
593   if ( $VERBOSE ) { 
594     print "BUILD STAGE:\n";
595     print "(time -p $NICE $MAKECMD $MAKEOPTS) >> $BuildLog 2>&1\n";
596   }
597   # Build the entire tree, capturing the output into $BuildLog
598   system "(time -p $NICE $MAKECMD $MAKEOPTS) >> $BuildLog 2>&1";
599 }
600
601 ##############################################################
602 #
603 # Get some statistics about the build...
604 #
605 ##############################################################
606 #this can de done on server
607 #my @Linked = split '\n', `grep Linking $BuildLog`;
608 #my $NumExecutables = scalar(grep(/executable/, @Linked));
609 #my $NumLibraries   = scalar(grep(!/executable/, @Linked));
610 #my $NumObjects     = `grep ']\: Compiling ' $BuildLog | wc -l` + 0;
611
612 # Get the number of lines of source code. Must be here after the build is done
613 # because countloc.sh uses the llvm-config script which must be built.
614 my $LOC = `utils/countloc.sh -topdir $BuildDir/llvm`;
615
616 # Get the time taken by the configure script
617 my $ConfigTimeU = GetRegexNum "^user", 0, "([0-9.]+)", "$BuildLog";
618 my $ConfigTimeS = GetRegexNum "^sys", 0, "([0-9.]+)", "$BuildLog";
619 my $ConfigTime  = $ConfigTimeU+$ConfigTimeS;  # ConfigTime = User+System
620 my $ConfigWallTime = GetRegexNum "^real", 0,"([0-9.]+)","$BuildLog";
621
622 $ConfigTime=-1 unless $ConfigTime;
623 $ConfigWallTime=-1 unless $ConfigWallTime;
624
625 my $BuildTimeU = GetRegexNum "^user", 1, "([0-9.]+)", "$BuildLog";
626 my $BuildTimeS = GetRegexNum "^sys", 1, "([0-9.]+)", "$BuildLog";
627 my $BuildTime  = $BuildTimeU+$BuildTimeS;  # BuildTime = User+System
628 my $BuildWallTime = GetRegexNum "^real", 1, "([0-9.]+)","$BuildLog";
629
630 $BuildTime=-1 unless $BuildTime;
631 $BuildWallTime=-1 unless $BuildWallTime;
632
633 my $BuildError = 0, $BuildStatus = "OK";
634 if ($NOBUILD) {
635   $BuildStatus = "Skipped by user";
636   $BuildError = 1;
637 }
638 elsif (`grep '^$MAKECMD\[^:]*: .*Error' $BuildLog | wc -l` + 0 ||
639   `grep '^$MAKECMD: \*\*\*.*Stop.' $BuildLog | wc -l`+0) {
640   $BuildStatus = "Error: compilation aborted";
641   $BuildError = 1;
642   if( $VERBOSE) { print  "\n***ERROR BUILDING TREE\n\n"; }
643 }
644 if ($BuildError) { $NODEJAGNU=1; }
645
646 my $a_file_sizes="";
647 my $o_file_sizes="";
648 if (!$BuildError) {
649   print "Organizing size of .o and .a files\n" 
650     if ( $VERBOSE );
651   ChangeDir( "$BuildDir/llvm", "Build Directory" );
652   $afiles.= `find utils/ -iname '*.a' -ls`;
653   $afiles.= `find lib/ -iname '*.a' -ls`;
654   $afiles.= `find tools/ -iname '*.a' -ls`;
655   if($BUILDTYPE eq "release"){
656     $afiles.= `find Release/ -iname '*.a' -ls`;
657   } else {
658    $afiles.= `find Debug/ -iname '*.a' -ls`;
659   }
660   
661   $ofiles.= `find utils/ -iname '*.o' -ls`;
662   $ofiles.= `find lib/ -iname '*.o' -ls`;
663   $ofiles.= `find tools/ -iname '*.o' -ls`;
664   if($BUILDTYPE eq "release"){
665     $ofiles.= `find Release/ -iname '*.o' -ls`;
666   } else {
667     $ofiles.= `find Debug/ -iname '*.o' -ls`;
668   }
669   
670   @AFILES = split "\n", $afiles;
671   $a_file_sizes="";
672   foreach $x (@AFILES){
673     $x =~ m/.+\s+.+\s+.+\s+.+\s+.+\s+.+\s+(.+)\s+.+\s+.+\s+.+\s+(.+)/;
674     $a_file_sizes.="$1 $2 $BUILDTYPE\n";
675   }
676   @OFILES = split "\n", $ofiles;
677   $o_file_sizes="";
678   foreach $x (@OFILES){
679     $x =~ m/.+\s+.+\s+.+\s+.+\s+.+\s+.+\s+(.+)\s+.+\s+.+\s+.+\s+(.+)/;
680     $o_file_sizes.="$1 $2 $BUILDTYPE\n";
681   }
682 } else {
683   $a_file_sizes="No data due to a bad build.";
684   $o_file_sizes="No data due to a bad build.";
685 }
686
687 ##############################################################
688 #
689 # Running dejagnu tests
690 #
691 ##############################################################
692 my $DejangnuTestResults=""; # String containing the results of the dejagnu
693 my $dejagnu_output = "$DejagnuTestsLog";
694 if (!$NODEJAGNU) {
695   if($VERBOSE) { 
696     print "DEJAGNU FEATURE/REGRESSION TEST STAGE:\n"; 
697     print "(time -p $MAKECMD $MAKEOPTS check) > $dejagnu_output 2>&1\n";
698   }
699
700   #Run the feature and regression tests, results are put into testrun.sum
701   #Full log in testrun.log
702   system "(time -p $MAKECMD $MAKEOPTS check) > $dejagnu_output 2>&1";
703   
704   #Copy the testrun.log and testrun.sum to our webdir
705   CopyFile("test/testrun.log", $DejagnuLog);
706   CopyFile("test/testrun.sum", $DejagnuSum);
707   #can be done on server
708   $DejagnuTestResults = GetDejagnuTestResults($DejagnuSum, $DejagnuLog);
709   $unexpfail_tests = $DejagnuTestResults;
710 }
711
712 #Extract time of dejagnu tests
713 my $DejagnuTimeU = GetRegexNum "^user", 0, "([0-9.]+)", "$dejagnu_output";
714 my $DejagnuTimeS = GetRegexNum "^sys", 0, "([0-9.]+)", "$dejagnu_output";
715 $DejagnuTime  = $DejagnuTimeU+$DejagnuTimeS;  # DejagnuTime = User+System
716 $DejagnuWallTime = GetRegexNum "^real", 0,"([0-9.]+)","$dejagnu_output"; 
717 $DejagnuTestResults = 
718   "Dejagnu skipped by user choice." unless $DejagnuTestResults;
719 $DejagnuTime     = "0.0" unless $DejagnuTime;
720 $DejagnuWallTime = "0.0" unless $DejagnuWallTime;
721
722 ##############################################################
723 #
724 # Get warnings from the build
725 #
726 ##############################################################
727 if (!$NODEJAGNU) {
728   if ( $VERBOSE ) { print "BUILD INFORMATION COLLECTION STAGE\n"; }
729   my @Warn = split "\n", `egrep 'warning:|Entering dir' $BuildLog`;
730   my @Warnings;
731   my $CurDir = "";
732
733   foreach $Warning (@Warn) {
734     if ($Warning =~ m/Entering directory \`([^\`]+)\'/) {
735       $CurDir = $1;                 # Keep track of directory warning is in...
736       # Remove buildir prefix if included
737       if ($CurDir =~ m#$BuildDir/llvm/(.*)#) { $CurDir = $1; }
738     } else {
739       push @Warnings, "$CurDir/$Warning";     # Add directory to warning...
740     }
741   }
742   my $WarningsFile =  join "\n", @Warnings;
743   $WarningsFile =~ s/:[0-9]+:/::/g;
744
745   # Emit the warnings file, so we can diff...
746   WriteFile "$WebDir/$DATE-Warnings.txt", $WarningsFile . "\n";
747   my ($WarningsAdded, $WarningsRemoved) = DiffFiles "-Warnings.txt";
748
749   # Output something to stdout if something has changed
750   #print "ADDED   WARNINGS:\n$WarningsAdded\n\n" if (length $WarningsAdded);
751   #print "REMOVED WARNINGS:\n$WarningsRemoved\n\n" if (length $WarningsRemoved);
752
753   #my @TmpWarningsAdded = split "\n", $WarningsAdded; ~PJ on upgrade
754   #my @TmpWarningsRemoved = split "\n", $WarningsRemoved; ~PJ on upgrade
755
756 } #endif !NODEGAGNU
757
758 ##############################################################
759 #
760 # If we built the tree successfully, run the nightly programs tests...
761 #
762 # A set of tests to run is passed in (i.e. "SingleSource" "MultiSource" 
763 # "External")
764 #
765 ##############################################################
766 sub TestDirectory {
767   my $SubDir = shift;  
768   ChangeDir( "$BuildDir/llvm/projects/llvm-test/$SubDir", 
769              "Programs Test Subdirectory" ) || return ("", "");
770   
771   my $ProgramTestLog = "$Prefix-$SubDir-ProgramTest.txt";
772   
773   # Run the programs tests... creating a report.nightly.csv file
774   if (!$NOTEST) {
775     if( $VERBOSE) { 
776       print "$MAKECMD -k $MAKEOPTS $PROGTESTOPTS report.nightly.csv ".
777             "TEST=nightly > $ProgramTestLog 2>&1\n"; 
778     }
779     system "$MAKECMD -k $MAKEOPTS $PROGTESTOPTS report.nightly.csv ".
780            "TEST=nightly > $ProgramTestLog 2>&1";
781     $llcbeta_options=`$MAKECMD print-llcbeta-option`;
782   } 
783
784   my $ProgramsTable;
785   if (`grep '^$MAKECMD\[^:]: .*Error' $ProgramTestLog | wc -l` + 0) {
786     $TestError = 1;
787     $ProgramsTable="Error running test $SubDir\n";
788     print "ERROR TESTING\n";
789   } elsif (`grep '^$MAKECMD\[^:]: .*No rule to make target' $ProgramTestLog | wc -l` + 0) {
790     $TestError = 1;
791     $ProgramsTable="Makefile error running tests $SubDir!\n";
792     print "ERROR TESTING\n";
793   } else {
794     $TestError = 0;
795   #
796   # Create a list of the tests which were run...
797   #
798   system "egrep 'TEST-(PASS|FAIL)' < $ProgramTestLog ".
799          "| sort > $Prefix-$SubDir-Tests.txt";
800   }
801   $ProgramsTable = ReadFile "report.nightly.csv";
802
803   ChangeDir( "../../..", "Programs Test Parent Directory" );
804   return ($ProgramsTable, $llcbeta_options);
805 } #end sub TestDirectory
806
807 ##############################################################
808 #
809 # Calling sub TestDirectory
810 #
811 ##############################################################
812 if (!$BuildError) {
813   if ( $VERBOSE ) {
814      print "SingleSource TEST STAGE\n";
815   }
816   ($SingleSourceProgramsTable, $llcbeta_options) = 
817     TestDirectory("SingleSource");
818   WriteFile "$Prefix-SingleSource-Performance.txt", $SingleSourceProgramsTable;
819   if ( $VERBOSE ) {
820     print "MultiSource TEST STAGE\n";
821   }
822   ($MultiSourceProgramsTable, $llcbeta_options) = TestDirectory("MultiSource");
823   WriteFile "$Prefix-MultiSource-Performance.txt", $MultiSourceProgramsTable;
824   if ( ! $NOEXTERNALS ) {
825     if ( $VERBOSE ) {
826       print "External TEST STAGE\n";
827     }
828     ($ExternalProgramsTable, $llcbeta_options) = TestDirectory("External");
829     WriteFile "$Prefix-External-Performance.txt", $ExternalProgramsTable;
830     system "cat $Prefix-SingleSource-Tests.txt " . 
831                "$Prefix-MultiSource-Tests.txt ".
832                "$Prefix-External-Tests.txt | sort > $Prefix-Tests.txt";
833     system "cat $Prefix-SingleSource-Performance.txt " . 
834                "$Prefix-MultiSource-Performance.txt ".
835                "$Prefix-External-Performance.txt | sort > $Prefix-Performance.txt";
836   } else {
837     $ExternalProgramsTable = "External TEST STAGE SKIPPED\n";
838     if ( $VERBOSE ) {
839       print "External TEST STAGE SKIPPED\n";
840     }
841     system "cat $Prefix-SingleSource-Tests.txt " . 
842                "$Prefix-MultiSource-Tests.txt ".
843                " | sort > $Prefix-Tests.txt";
844     system "cat $Prefix-SingleSource-Performance.txt " . 
845                "$Prefix-MultiSource-Performance.txt ".
846                " | sort > $Prefix-Performance.txt";
847   }
848
849   ##############################################################
850   #
851   # 
852   # gathering tests added removed broken information here 
853   #
854   #
855   ##############################################################
856   my $dejagnu_test_list = ReadFile "$Prefix-Tests.txt";
857   my @DEJAGNU = split "\n", $dejagnu_test_list;
858   my ($passes, $fails, $xfails) = "";
859
860   if(!$NODEJAGNU) {
861     for ($x=0; $x<@DEJAGNU; $x++) {
862       if ($DEJAGNU[$x] =~ m/^PASS:/) {
863         $passes.="$DEJAGNU[$x]\n";
864       }
865       elsif ($DEJAGNU[$x] =~ m/^FAIL:/) {
866         $fails.="$DEJAGNU[$x]\n";
867       }
868       elsif ($DEJAGNU[$x] =~ m/^XFAIL:/) {
869         $xfails.="$DEJAGNU[$x]\n";
870       }
871     }
872   }
873   
874 } #end if !$BuildError
875
876
877 ##############################################################
878 #
879 # If we built the tree successfully, runs of the Olden suite with
880 # LARGE_PROBLEM_SIZE on so that we can get some "running" statistics.
881 #
882 ##############################################################
883 if (!$BuildError) {
884   if ( $VERBOSE ) { print "OLDEN TEST SUITE STAGE\n"; }
885   my ($NATTime, $CBETime, $LLCTime, $JITTime, $OptTime, $BytecodeSize,
886   $MachCodeSize) = ("","","","","","","");
887   if (!$NORUNNINGTESTS) {
888     ChangeDir( "$BuildDir/llvm/projects/llvm-test/MultiSource/Benchmarks/Olden",
889                 "Olden Test Directory");
890
891     # Clean out previous results...
892     system "$NICE $MAKECMD $MAKEOPTS clean > /dev/null 2>&1";
893
894     # Run the nightly test in this directory, with LARGE_PROBLEM_SIZE and
895     # GET_STABLE_NUMBERS enabled!
896     if( $VERBOSE ) { 
897       print "$MAKECMD -k $MAKEOPTS $PROGTESTOPTS report.nightly.csv.out " .
898             "TEST=nightly  LARGE_PROBLEM_SIZE=1 GET_STABLE_NUMBERS=1 " .
899             "> /dev/null 2>&1\n"; 
900     }
901     system "$MAKECMD -k $MAKEOPTS $PROGTESTOPTS report.nightly.csv.out " .
902            "TEST=nightly LARGE_PROBLEM_SIZE=1 GET_STABLE_NUMBERS=1 " .
903            "> /dev/null 2>&1";
904     system "cp report.nightly.csv $OldenTestsLog";
905   }  
906 }
907
908 ##############################################################
909 #
910 # Getting end timestamp
911 #
912 ##############################################################
913 $endtime = `date "+20%y-%m-%d %H:%M:%S"`;
914
915
916 ##############################################################
917 #
918 # Place all the logs neatly into one humungous file
919 #
920 ##############################################################
921 if ( $VERBOSE ) { print "PREPARING LOGS TO BE SENT TO SERVER\n"; }
922
923 $machine_data = "uname: ".`uname -a`. 
924                 "hardware: ".`uname -m`.
925                 "os: ".`uname -sr`.
926                 "name: ".`uname -n`.
927                 "date: ".`date \"+20%y-%m-%d\"`.
928                 "time: ".`date +\"%H:%M:%S\"`; 
929
930 my @CVS_DATA;
931 my $cvs_data;
932 @CVS_DATA = ReadFile "$CVSLog";
933 $cvs_data = join("\n", @CVS_DATA);
934
935 my @BUILD_DATA;
936 my $build_data;
937 @BUILD_DATA = ReadFile "$BuildLog";
938 $build_data = join("\n", @BUILD_DATA);
939
940 my (@DEJAGNU_LOG, @DEJAGNU_SUM, @DEJAGNULOG_FULL, @GCC_VERSION);
941 my ($dejagnutests_log ,$dejagnutests_sum, $dejagnulog_full) = "";
942 my ($gcc_version, $gcc_version_long) = "";
943
944 $gcc_version_long="";
945 if ($GCCPATH ne "") {
946         $gcc_version_long = `$GCCPATH/gcc --version`;
947 } else {
948         $gcc_version_long = `gcc --version`;
949 }
950 @GCC_VERSION = split '\n', $gcc_version_long;
951 $gcc_version = $GCC_VERSION[0];
952
953 if(!$BuildError){
954   @DEJAGNU_LOG = ReadFile "$DejagnuLog";
955   @DEJAGNU_SUM = ReadFile "$DejagnuSum";
956   $dejagnutests_log = join("\n", @DEJAGNU_LOG);
957   $dejagnutests_sum = join("\n", @DEJAGNU_SUM);
958
959   @DEJAGNULOG_FULL = ReadFile "$DejagnuTestsLog";
960   $dejagnulog_full = join("\n", @DEJAGNULOG_FULL);
961 }
962
963 ##############################################################
964 #
965 # Send data via a post request
966 #
967 ##############################################################
968
969 if ( $VERBOSE ) { print "SEND THE DATA VIA THE POST REQUEST\n"; }
970
971 my %hash_of_data = (
972   'machine_data' => $machine_data,
973   'build_data' => $build_data,
974   'gcc_version' => $gcc_version,
975   'nickname' => $nickname,
976   'dejagnutime_wall' => $DejagnuWallTime,
977   'dejagnutime_cpu' => $DejagnuTime,
978   'cvscheckouttime_wall' => $CVSCheckoutTime_Wall,
979   'cvscheckouttime_cpu' => $CVSCheckoutTime_CPU,
980   'configtime_wall' => $ConfigWallTime,
981   'configtime_cpu'=> $ConfigTime,
982   'buildtime_wall' => $BuildWallTime,
983   'buildtime_cpu' => $BuildTime,
984   'warnings' => $WarningsFile,
985   'cvsusercommitlist' => $UserCommitList,
986   'cvsuserupdatelist' => $UserUpdateList,
987   'cvsaddedfiles' => $CVSAddedFiles,
988   'cvsmodifiedfiles' => $CVSModifiedFiles,
989   'cvsremovedfiles' => $CVSRemovedFiles,
990   'lines_of_code' => $LOC,
991   'cvs_file_count' => $NumFilesInCVS,
992   'cvs_dir_count' => $NumDirsInCVS,
993   'buildstatus' => $BuildStatus,
994   'singlesource_programstable' => $SingleSourceProgramsTable,
995   'multisource_programstable' => $MultiSourceProgramsTable,
996   'externalsource_programstable' => $ExternalProgramsTable,
997   'llcbeta_options' => $multisource_llcbeta_options,
998   'warnings_removed' => $WarningsRemoved,
999   'warnings_added' => $WarningsAdded,
1000   'passing_tests' => $passes,
1001   'expfail_tests' => $xfails,
1002   'unexpfail_tests' => $fails,
1003   'all_tests' => $dejagnu_test_list,
1004   'new_tests' => "",
1005   'removed_tests' => "",
1006   'dejagnutests_results' => $DejagnuTestResults,
1007   'dejagnutests_log' => $dejagnulog_full,
1008   'starttime' => $starttime,
1009   'endtime' => $endtime,
1010   'o_file_sizes' => $o_file_sizes,
1011   'a_file_sizes' => $a_file_sizes
1012 );
1013
1014 $TESTING = 0;
1015
1016 if ($TESTING) {
1017   print "============================\n";
1018   foreach $x(keys %hash_of_data){
1019       print "$x  => $hash_of_data{$x}\n";
1020   }
1021 } else {
1022   my $response = SendData $SUBMITSERVER,$SUBMITSCRIPT,\%hash_of_data;
1023   if( $VERBOSE) { print "============================\n$response"; }
1024 }
1025
1026 ##############################################################
1027 #
1028 # Remove the cvs tree...
1029 #
1030 ##############################################################
1031 system ( "$NICE rm -rf $BuildDir") 
1032   if (!$NOCHECKOUT and !$NOREMOVE);
1033 system ( "$NICE rm -rf $WebDir") 
1034   if (!$NOCHECKOUT and !$NOREMOVE and !$NOREMOVERESULTS);