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