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