NNT: Add -parallel-test option, which runs llvm-test with
[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 #  -parallel-test   Allow parallel execution of llvm-test
81 #  -verbose         Turn on some debug output
82 #  -nice            Checkout/Configure/Build with "nice" to reduce impact
83 #                   on busy servers.
84 #  -f2c             Next argument specifies path to F2C utility
85 #  -gccpath         Path to gcc/g++ used to build LLVM
86 #  -target          Specify the target triplet
87 #  -cflags          Next argument specifies that C compilation options that
88 #                   override the default.
89 #  -cxxflags        Next argument specifies that C++ compilation options that
90 #                   override the default.
91 #  -ldflags         Next argument specifies that linker options that override
92 #                   the default.
93 #
94 # CVSROOT is ignored, it is passed for backwards compatibility.
95 # BUILDDIR is the directory where sources for this test run will be checked out
96 #  AND objects for this test run will be built. This directory MUST NOT
97 #  exist before the script is run; it will be created by the svn checkout
98 #  process and erased (unless -noremove is specified; see above.)
99 # WEBDIR is the directory into which the test results web page will be written,
100 #  AND in which the "index.html" is assumed to be a symlink to the most recent
101 #  copy of the results. This directory will be created if it does not exist.
102 # LLVMGCCDIR is the directory in which the LLVM GCC Front End is installed
103 #  to. This is the same as you would have for a normal LLVM build.
104 #
105 ##############################################################
106 #
107 # Getting environment variables
108 #
109 ##############################################################
110 my $HOME       = $ENV{'HOME'};
111 my $SVNURL     = $ENV{"SVNURL"};
112 $SVNURL        = 'http://llvm.org/svn/llvm-project' unless $SVNURL;
113 my $TestSVNURL = $ENV{"TestSVNURL"};
114 $TestSVNURL    = 'http://llvm.org/svn/llvm-project' unless $TestSVNURL;
115 my $BuildDir   = $ENV{'BUILDDIR'};
116 my $WebDir     = $ENV{'WEBDIR'};
117
118 my $LLVMSrcDir   = $ENV{'LLVMSRCDIR'};
119 $LLVMSrcDir    = "$BuildDir/llvm" unless $LLVMSrcDir;
120 my $LLVMObjDir   = $ENV{'LLVMOBJDIR'};
121 $LLVMObjDir    = "$BuildDir/llvm" unless $LLVMObjDir;
122 my $LLVMTestDir   = $ENV{'LLVMTESTDIR'};
123 $LLVMTestDir    = "$BuildDir/llvm/projects/llvm-test" unless $LLVMTestDir;
124
125 ##############################################################
126 #
127 # Calculate the date prefix...
128 #
129 ##############################################################
130 @TIME = localtime;
131 my $DATE = sprintf "%4d-%02d-%02d_%02d-%02d", $TIME[5]+1900, $TIME[4]+1, $TIME[3], $TIME[1], $TIME[0];
132
133 ##############################################################
134 #
135 # Parse arguments...
136 #
137 ##############################################################
138 $CONFIG_PATH="";
139 $CONFIGUREARGS="";
140 $nickname="";
141 $NOTEST=0;
142 $MAKECMD="make";
143 $SUBMITSERVER = "llvm.org";
144 $SUBMITSCRIPT = "/nightlytest/NightlyTestAccept.php";
145 $SUBMITAUX="";
146 $SUBMIT = 1;
147 $PARALLELJOBS = "2";
148 my $TESTFLAGS="";
149
150 while (scalar(@ARGV) and ($_ = $ARGV[0], /^[-+]/)) {
151   shift;
152   last if /^--$/;  # Stop processing arguments on --
153
154   # List command line options here...
155   if (/^-config$/)         { $CONFIG_PATH = "$ARGV[0]"; shift; next; }
156   if (/^-nocheckout$/)     { $NOCHECKOUT = 1; next; }
157   if (/^-noremove$/)       { $NOREMOVE = 1; next; }
158   if (/^-noremoveatend$/)  { $NOREMOVEATEND = 1; next; }
159   if (/^-noremoveresults$/){ $NOREMOVERESULTS = 1; next; }
160   if (/^-notest$/)         { $NOTEST = 1; next; }
161   if (/^-norunningtests$/) { next; } # Backward compatibility, ignored.
162   if (/^-parallel-jobs$/)  { $PARALLELJOBS = "$ARGV[0]"; shift; next;}
163   if (/^-parallel$/)       { $MAKEOPTS = "$MAKEOPTS -j$PARALLELJOBS"; next; }
164   if (/^-parallel-test$/)  { $PROGTESTOPTS .= " ENABLE_PARALLEL_REPORT=1"; next; }
165   if (/^-with-clang$/)     { $WITHCLANG = 1; next; }
166   if (/^-release$/)        { $MAKEOPTS = "$MAKEOPTS ENABLE_OPTIMIZED=1 ".
167                              "OPTIMIZE_OPTION=-O2"; $BUILDTYPE="release"; next;}
168   if (/^-release-asserts$/){ $MAKEOPTS = "$MAKEOPTS ENABLE_OPTIMIZED=1 ".
169                              "DISABLE_ASSERTIONS=1 ".
170                              "OPTIMIZE_OPTION=-O2";
171                              $BUILDTYPE="release-asserts"; next;}
172   if (/^-enable-llcbeta$/) { $PROGTESTOPTS .= " ENABLE_LLCBETA=1"; next; }
173   if (/^-disable-pic$/)    { $CONFIGUREARGS .= " --enable-pic=no"; next; }
174   if (/^-enable-lli$/)     { $PROGTESTOPTS .= " ENABLE_LLI=1";
175                              $CONFIGUREARGS .= " --enable-lli"; next; }
176   if (/^-disable-llc$/)    { $PROGTESTOPTS .= " DISABLE_LLC=1";
177                              $CONFIGUREARGS .= " --disable-llc_diffs"; next; }
178   if (/^-disable-jit$/)    { $PROGTESTOPTS .= " DISABLE_JIT=1";
179                              $CONFIGUREARGS .= " --disable-jit"; next; }
180   if (/^-disable-bindings$/)    { $CONFIGUREARGS .= " --disable-bindings"; next; }
181   if (/^-disable-cbe$/)    { $PROGTESTOPTS .= " DISABLE_CBE=1"; next; }
182   if (/^-disable-lto$/)    { $PROGTESTOPTS .= " DISABLE_LTO=1"; next; }
183   if (/^-test-opts$/)      { $PROGTESTOPTS .= " $ARGV[0]"; shift; next; }
184   if (/^-verbose$/)        { $VERBOSE = 1; next; }
185   if (/^-teelogs$/)        { $TEELOGS = 1; next; }
186   if (/^-nice$/)           { $NICE = "nice "; next; }
187   if (/^-f2c$/)            { $CONFIGUREARGS .= " --with-f2c=$ARGV[0]";
188                              shift; next; }
189   if (/^-with-externals$/) { $CONFIGUREARGS .= " --with-externals=$ARGV[0]";
190                              shift; next; }
191   if (/^-configure-args$/) { $CONFIGUREARGS .= " $ARGV[0]";
192                              shift; next; }
193   if (/^-submit-server/)   { $SUBMITSERVER = "$ARGV[0]"; shift; next; }
194   if (/^-submit-script/)   { $SUBMITSCRIPT = "$ARGV[0]"; shift; next; }
195   if (/^-submit-aux/)      { $SUBMITAUX = "$ARGV[0]"; shift; next; }
196   if (/^-nosubmit$/)       { $SUBMIT = 0; next; }
197   if (/^-nickname$/)       { $nickname = "$ARGV[0]"; shift; next; }
198   if (/^-gccpath/)         { $CONFIGUREARGS .=
199                              " CC=$ARGV[0]/gcc CXX=$ARGV[0]/g++";
200                              $GCCPATH=$ARGV[0]; shift;  next; }
201   else                     { $GCCPATH=""; }
202   if (/^-target/)          { $CONFIGUREARGS .= " --target=$ARGV[0]";
203                              shift; next; }
204   if (/^-cflags/)          { $MAKEOPTS = "$MAKEOPTS C.Flags=\'$ARGV[0]\'";
205                              shift; next; }
206   if (/^-cxxflags/)        { $MAKEOPTS = "$MAKEOPTS CXX.Flags=\'$ARGV[0]\'";
207                              shift; next; }
208   if (/^-ldflags/)         { $MAKEOPTS = "$MAKEOPTS LD.Flags=\'$ARGV[0]\'";
209                              shift; next; }
210   if (/^-test-cflags/)     { $TESTFLAGS = "$TESTFLAGS CFLAGS=\'$ARGV[0]\'";
211                              shift; next; }
212   if (/^-test-cxxflags/)   { $TESTFLAGS = "$TESTFLAGS CXXFLAGS=\'$ARGV[0]\'";
213                              shift; next; }
214   if (/^-compileflags/)    { $MAKEOPTS = "$MAKEOPTS $ARGV[0]"; shift; next; }
215   if (/^-use-gmake/)       { $MAKECMD = "gmake"; shift; next; }
216   if (/^-extraflags/)      { $CONFIGUREARGS .=
217                              " --with-extra-options=\'$ARGV[0]\'"; shift; next;}
218   if (/^-noexternals$/)    { $NOEXTERNALS = 1; next; }
219   if (/^-nodejagnu$/)      { $NODEJAGNU = 1; next; }
220   if (/^-nobuild$/)        { $NOBUILD = 1; next; }
221   print "Unknown option: $_ : ignoring!\n";
222 }
223
224 if ($ENV{'LLVMGCCDIR'}) {
225   $CONFIGUREARGS .= " --with-llvmgccdir=" . $ENV{'LLVMGCCDIR'};
226   $LLVMGCCPATH = $ENV{'LLVMGCCDIR'} . '/bin';
227 }
228 else {
229   $LLVMGCCPATH = "";
230 }
231
232 if ($CONFIGUREARGS !~ /--disable-jit/) {
233   $CONFIGUREARGS .= " --enable-jit";
234 }
235
236 if (@ARGV != 0 and @ARGV != 3) {
237   die "error: must specify 0 or 3 options!";
238 }
239
240 if (@ARGV == 3) {
241   if ($CONFIG_PATH ne "") {
242       die "error: arguments are unsupported in -config mode,";
243   }
244
245   # ARGV[0] used to be the CVS root, ignored for backward compatibility.
246   $BuildDir   = $ARGV[1];
247   $WebDir     = $ARGV[2];
248 }
249
250 if ($BuildDir   eq "" or
251     $WebDir     eq "") {
252   die("please specify a build directory, and a web directory");
253  }
254
255 if ($nickname eq "") {
256   die ("Please invoke NewNightlyTest.pl with command line option " .
257        "\"-nickname <nickname>\"");
258 }
259
260 if ($BUILDTYPE ne "release" && $BUILDTYPE ne "release-asserts") {
261   $BUILDTYPE = "debug";
262 }
263
264 if ($CONFIG_PATH ne "") {
265   die "error: -config mode is not yet implemented,";
266 }
267
268 ##############################################################
269 #
270 # Define the file names we'll use
271 #
272 ##############################################################
273 my $Prefix = "$WebDir/$DATE";
274 my $ConfigureLog = "$Prefix-Configure-Log.txt";
275 my $BuildLog = "$Prefix-Build-Log.txt";
276 my $COLog = "$Prefix-CVS-Log.txt";
277 my $SingleSourceLog = "$Prefix-SingleSource-ProgramTest.txt.gz";
278 my $MultiSourceLog = "$Prefix-MultiSource-ProgramTest.txt.gz";
279 my $ExternalLog = "$Prefix-External-ProgramTest.txt.gz";
280 my $DejagnuLog = "$Prefix-Dejagnu-testrun.log";
281 my $DejagnuSum = "$Prefix-Dejagnu-testrun.sum";
282 my $DejagnuLog = "$Prefix-DejagnuTests-Log.txt";
283 if (! -d $WebDir) {
284   mkdir $WebDir, 0777 or die "Unable to create web directory: '$WebDir'.";
285   if($VERBOSE){
286     warn "$WebDir did not exist; creating it.\n";
287   }
288 }
289
290 if ($VERBOSE) {
291   print "INITIALIZED\n";
292   print "SVN URL  = $SVNURL\n";
293   print "COLog    = $COLog\n";
294   print "BuildDir = $BuildDir\n";
295   print "WebDir   = $WebDir\n";
296   print "Prefix   = $Prefix\n";
297   print "BuildLog = $BuildLog\n";
298 }
299
300 ##############################################################
301 #
302 # Helper functions
303 #
304 ##############################################################
305
306 sub GetDir {
307   my $Suffix = shift;
308   opendir DH, $WebDir;
309   my @Result = reverse sort grep !/$DATE/, grep /[-0-9]+$Suffix/, readdir DH;
310   closedir DH;
311   return @Result;
312 }
313
314 sub RunLoggedCommand {
315   my $Command = shift;
316   my $Log = shift;
317   my $Title = shift;
318   if ($TEELOGS) {
319       if ($VERBOSE) {
320           print "$Title\n";
321           print "$Command 2>&1 | tee $Log\n";
322       }
323       system "$Command 2>&1 | tee $Log";
324   } else {
325       if ($VERBOSE) {
326           print "$Title\n";
327           print "$Command 2>&1 > $Log\n";
328       }
329       system "$Command 2>&1 > $Log";
330   }
331 }
332
333 sub RunAppendingLoggedCommand {
334   my $Command = shift;
335   my $Log = shift;
336   my $Title = shift;
337   if ($TEELOGS) {
338       if ($VERBOSE) {
339           print "$Title\n";
340           print "$Command 2>&1 | tee -a $Log\n";
341       }
342       system "$Command 2>&1 | tee -a $Log";
343   } else {
344       if ($VERBOSE) {
345           print "$Title\n";
346           print "$Command 2>&1 > $Log\n";
347       }
348       system "$Command 2>&1 >> $Log";
349   }
350 }
351
352 sub GetRegex {   # (Regex with ()'s, value)
353   if ($_[1] =~ /$_[0]/m) {
354     return $1;
355   }
356   return "0";
357 }
358
359 sub ChangeDir { # directory, logical name
360   my ($dir,$name) = @_;
361   chomp($dir);
362   if ( $VERBOSE ) { print "Changing To: $name ($dir)\n"; }
363   $result = chdir($dir);
364   if (!$result) {
365     print "ERROR!!! Cannot change directory to: $name ($dir) because $!\n";
366     return false;
367   }
368   return true;
369 }
370
371 sub ReadFile {
372   if (open (FILE, $_[0])) {
373     undef $/;
374     my $Ret = <FILE>;
375     close FILE;
376     $/ = '\n';
377     return $Ret;
378   } else {
379     print "Could not open file '$_[0]' for reading!\n";
380     return "";
381   }
382 }
383
384 sub WriteFile {  # (filename, contents)
385   open (FILE, ">$_[0]") or die "Could not open file '$_[0]' for writing!\n";
386   print FILE $_[1];
387   close FILE;
388 }
389
390 sub CopyFile { #filename, newfile
391   my ($file, $newfile) = @_;
392   chomp($file);
393   if ($VERBOSE) { print "Copying $file to $newfile\n"; }
394   copy($file, $newfile);
395 }
396
397 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
398 #
399 # This function is meant to read in the dejagnu sum file and
400 # return a string with only the results (i.e. PASS/FAIL/XPASS/
401 # XFAIL).
402 #
403 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
404 sub GetDejagnuTestResults { # (filename, log)
405     my ($filename, $DejagnuLog) = @_;
406     my @lines;
407     $/ = "\n"; #Make sure we're going line at a time.
408
409     if( $VERBOSE) { print "DEJAGNU TEST RESULTS:\n"; }
410
411     if (open SRCHFILE, $filename) {
412         # Process test results
413         while ( <SRCHFILE> ) {
414             if ( length($_) > 1 ) {
415                 chomp($_);
416                 if ( m/^(PASS|XPASS|FAIL|XFAIL): .*\/llvm\/test\/(.*)$/ ) {
417                     push(@lines, "$1: test/$2");
418                 }
419             }
420         }
421     }
422     close SRCHFILE;
423
424     my $content = join("\n", @lines);
425     return $content;
426 }
427
428
429
430 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
431 #
432 # This function acts as a mini web browswer submitting data
433 # to our central server via the post method
434 #
435 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
436 sub SendData {
437     $host = $_[0];
438     $file = $_[1];
439     $variables = $_[2];
440
441     # Write out the "...-sentdata.txt" file.
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     if (!($SUBMITAUX eq "")) {
451         system "$SUBMITAUX \"$Prefix-sentdata.txt\"";
452     }
453
454     if (!$SUBMIT) {
455         return "Skipped standard submit.\n";
456     }
457
458     # Create the content to send to the server.
459
460     my $content;
461     foreach $key (keys (%$variables)){
462         $value = $variables->{$key};
463         $value =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
464         $content .= "$key=$value&";
465     }
466
467     # Send the data to the server.
468     #
469     # FIXME: This code should be more robust?
470
471     $port=80;
472     $socketaddr= sockaddr_in $port, inet_aton $host or die "Bad hostname\n";
473     socket SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp') or
474       die "Bad socket\n";
475     connect SOCK, $socketaddr or die "Bad connection\n";
476     select((select(SOCK), $| = 1)[0]);
477
478     $length = length($content);
479
480     my $send= "POST $file HTTP/1.0\n";
481     $send.= "Host: $host\n";
482     $send.= "Content-Type: application/x-www-form-urlencoded\n";
483     $send.= "Content-length: $length\n\n";
484     $send.= "$content";
485
486     print SOCK $send;
487     my $result;
488     while(<SOCK>){
489         $result  .= $_;
490     }
491     close(SOCK);
492
493     return $result;
494 }
495
496 ##############################################################
497 #
498 # Individual Build & Test Functions
499 #
500 ##############################################################
501
502 # Create the source repository directory.
503 sub CheckoutSource {
504   if (-d $BuildDir) {
505     if (!$NOREMOVE) {
506       if ( $VERBOSE ) {
507         print "Build directory exists! Removing it\n";
508       }
509       system "rm -rf $BuildDir";
510       mkdir $BuildDir or die "Could not create checkout directory $BuildDir!";
511     } else {
512       if ( $VERBOSE ) {
513         print "Build directory exists!\n";
514       }
515     }
516   } else {
517     mkdir $BuildDir or die "Could not create checkout directory $BuildDir!";
518   }
519
520   ChangeDir( $BuildDir, "checkout directory" );
521   my $SVNCMD = "$NICE svn co --non-interactive";
522   RunLoggedCommand("( time -p $SVNCMD $SVNURL/llvm/trunk llvm; cd llvm/projects ; " .
523                    "  $SVNCMD $TestSVNURL/test-suite/trunk llvm-test )", $COLog,
524                    "CHECKOUT LLVM");
525   if ($WITHCLANG) {
526       RunLoggedCommand("( cd llvm/tools ; " .
527                        "  $SVNCMD $SVNURL/cfe/trunk clang )", $COLog,
528                        "CHECKOUT CLANG");
529   }
530 }
531
532 # Build the entire tree, saving build messages to the build log. Returns false
533 # on build failure.
534 sub BuildLLVM {
535   my $EXTRAFLAGS = "--enable-spec --with-objroot=.";
536   RunLoggedCommand("(time -p $NICE ./configure $CONFIGUREARGS $EXTRAFLAGS) ",
537                    $ConfigureLog, "CONFIGURE");
538   # Build the entire tree, capturing the output into $BuildLog
539   RunAppendingLoggedCommand("($NICE $MAKECMD $MAKEOPTS clean)", $BuildLog, "BUILD CLEAN");
540   RunAppendingLoggedCommand("(time -p $NICE $MAKECMD $MAKEOPTS)", $BuildLog, "BUILD");
541
542   if (`grep '^$MAKECMD\[^:]*: .*Error' $BuildLog | wc -l` + 0 ||
543       `grep '^$MAKECMD: \*\*\*.*Stop.' $BuildLog | wc -l` + 0) {
544     return 0;
545   }
546
547   return 1;
548 }
549
550 # Running dejagnu tests and save results to log.
551 sub RunDejaGNUTests {
552   # Run the feature and regression tests, results are put into testrun.sum and
553   # the full log in testrun.log.
554   system "rm -f test/testrun.log test/testrun.sum";
555   RunLoggedCommand("(time -p $MAKECMD $MAKEOPTS check)", $DejagnuLog, "DEJAGNU");
556
557   # Copy the testrun.log and testrun.sum to our webdir.
558   CopyFile("test/testrun.log", $DejagnuLog);
559   CopyFile("test/testrun.sum", $DejagnuSum);
560
561   return GetDejagnuTestResults($DejagnuSum, $DejagnuLog);
562 }
563
564 # Run the named tests (i.e. "SingleSource" "MultiSource" "External")
565 sub TestDirectory {
566   my $SubDir = shift;
567   ChangeDir( "$LLVMTestDir/$SubDir",
568              "Programs Test Subdirectory" ) || return ("", "");
569
570   my $ProgramTestLog = "$Prefix-$SubDir-ProgramTest.txt";
571
572   # Run the programs tests... creating a report.nightly.csv file.
573   my $LLCBetaOpts = "";
574   if( $VERBOSE) {
575     print "$MAKECMD -k $MAKEOPTS $PROGTESTOPTS report.nightly.csv ".
576           "$TESTFLAGS TEST=nightly > $ProgramTestLog 2>&1\n";
577   }
578   RunLoggedCommand("$MAKECMD -k $MAKEOPTS $PROGTESTOPTS report.nightly.csv ".
579                    "$TESTFLAGS TEST=nightly",
580                    $ProgramTestLog, "TEST DIRECTORY $SubDir");
581   $LLCBetaOpts = `$MAKECMD print-llcbeta-option`;
582
583   my $ProgramsTable;
584   if (`grep '^$MAKECMD\[^:]: .*Error' $ProgramTestLog | wc -l` + 0) {
585     $ProgramsTable="Error running test $SubDir\n";
586     print "ERROR TESTING\n";
587   } elsif (`grep '^$MAKECMD\[^:]: .*No rule to make target' $ProgramTestLog | wc -l` + 0) {
588     $ProgramsTable="Makefile error running tests $SubDir!\n";
589     print "ERROR TESTING\n";
590   } else {
591     # Create a list of the tests which were run...
592     system "egrep 'TEST-(PASS|FAIL)' < $ProgramTestLog ".
593            "| sort > $Prefix-$SubDir-Tests.txt";
594   }
595   $ProgramsTable = ReadFile "report.nightly.csv";
596
597   ChangeDir( "../../..", "Programs Test Parent Directory" );
598   return ($ProgramsTable, $LLCBetaOpts);
599 }
600
601 # Run all the nightly tests and return the program tables and the list of tests,
602 # passes, fails, and xfails.
603 sub RunNightlyTest() {
604   ($SSProgs, $llcbeta_options) = TestDirectory("SingleSource");
605   WriteFile "$Prefix-SingleSource-Performance.txt", $SSProgs;
606   ($MSProgs, $llcbeta_options) = TestDirectory("MultiSource");
607   WriteFile "$Prefix-MultiSource-Performance.txt", $MSProgs;
608   if ( ! $NOEXTERNALS ) {
609     ($ExtProgs, $llcbeta_options) = TestDirectory("External");
610     WriteFile "$Prefix-External-Performance.txt", $ExtProgs;
611     system "cat $Prefix-SingleSource-Tests.txt " .
612                "$Prefix-MultiSource-Tests.txt ".
613                "$Prefix-External-Tests.txt | sort > $Prefix-Tests.txt";
614     system "cat $Prefix-SingleSource-Performance.txt " .
615                "$Prefix-MultiSource-Performance.txt ".
616                "$Prefix-External-Performance.txt | sort > $Prefix-Performance.txt";
617   } else {
618     $ExtProgs = "External TEST STAGE SKIPPED\n";
619     if ( $VERBOSE ) {
620       print "External TEST STAGE SKIPPED\n";
621     }
622     system "cat $Prefix-SingleSource-Tests.txt " .
623                "$Prefix-MultiSource-Tests.txt ".
624                " | sort > $Prefix-Tests.txt";
625     system "cat $Prefix-SingleSource-Performance.txt " .
626                "$Prefix-MultiSource-Performance.txt ".
627                " | sort > $Prefix-Performance.txt";
628   }
629
630   # Compile passes, fails, xfails.
631   my $All = (ReadFile "$Prefix-Tests.txt");
632   my @TestSuiteResultLines = split "\n", $All;
633   my ($Passes, $Fails, $XFails) = "";
634
635   for ($x=0; $x < @TestSuiteResultLines; $x++) {
636     if (@TestSuiteResultLines[$x] =~ m/^PASS:/) {
637       $Passes .= "$TestSuiteResultLines[$x]\n";
638     }
639     elsif (@TestSuiteResultLines[$x] =~ m/^FAIL:/) {
640       $Fails .= "$TestSuiteResultLines[$x]\n";
641     }
642     elsif (@TestSuiteResultLines[$x] =~ m/^XFAIL:/) {
643       $XFails .= "$TestSuiteResultLines[$x]\n";
644     }
645   }
646
647   return ($SSProgs, $MSProgs, $ExtProgs, $All, $Passes, $Fails, $XFails);
648 }
649
650 ##############################################################
651 #
652 # The actual NewNightlyTest logic.
653 #
654 ##############################################################
655
656 $starttime = `date "+20%y-%m-%d %H:%M:%S"`;
657
658 if (!$NOCHECKOUT) {
659   CheckoutSource();
660 }
661
662 # Build LLVM.
663 my $BuildError = 0, $BuildStatus = "OK";
664 ChangeDir( $LLVMSrcDir , "llvm source directory") ;
665 if ($NOCHECKOUT || $NOBUILD) {
666   $BuildStatus = "Skipped by user";
667 } else {
668   if (!BuildLLVM()) {
669     if( $VERBOSE) { print  "\n***ERROR BUILDING TREE\n\n"; }
670     $BuildError = 1;
671     $BuildStatus = "Error: compilation aborted";
672     $NODEJAGNU=1;
673   }
674 }
675
676 # Run DejaGNU.
677 my $DejagnuTestResults = "Dejagnu skipped by user choice.";
678 if (!$NODEJAGNU && !$BuildError) {
679   $DejagnuTestResults = RunDejaGNUTests();
680 }
681
682 # Run the llvm-test tests.
683 my ($SingleSourceProgramsTable, $MultiSourceProgramsTable, $ExternalProgramsTable,
684     $all_tests, $passes, $fails, $xfails) = "";
685 if (!$NOTEST && !$BuildError) {
686   ($SingleSourceProgramsTable, $MultiSourceProgramsTable, $ExternalProgramsTable,
687    $all_tests, $passes, $fails, $xfails) = RunNightlyTest();
688 }
689
690 $endtime = `date "+20%y-%m-%d %H:%M:%S"`;
691
692 # The last bit of logic is to remove the build and web dirs, after sending data
693 # to the server.
694
695 ##############################################################
696 #
697 # Accumulate the information to send to the server.
698 #
699 ##############################################################
700
701 if ( $VERBOSE ) { print "PREPARING LOGS TO BE SENT TO SERVER\n"; }
702
703 $machine_data = "uname: ".`uname -a`.
704                 "hardware: ".`uname -m`.
705                 "os: ".`uname -sr`.
706                 "name: ".`uname -n`.
707                 "date: ".`date \"+20%y-%m-%d\"`.
708                 "time: ".`date +\"%H:%M:%S\"`;
709
710 # Get gcc version.
711 my $gcc_version_long = "";
712 if ($GCCPATH ne "") {
713   $gcc_version_long = `$GCCPATH/gcc --version`;
714 } elsif ($ENV{"CC"}) {
715   $gcc_version_long = `$ENV{"CC"} --version`;
716 } else {
717   $gcc_version_long = `gcc --version`;
718 }
719 my $gcc_version = (split '\n', $gcc_version_long)[0];
720
721 # Get llvm-gcc target triple.
722 my $llvmgcc_version_long = "";
723 if ($LLVMGCCPATH ne "") {
724   $llvmgcc_version_long = `$LLVMGCCPATH/llvm-gcc -v 2>&1`;
725 } else {
726   $llvmgcc_version_long = `llvm-gcc -v 2>&1`;
727 }
728 (split '\n', $llvmgcc_version_long)[1] =~ /Target: (.+)/;
729 my $targetTriple = $1;
730
731 # Logs.
732 my $ConfigureLogData = ReadFile $ConfigureLog;
733 my $BuildLogData = ReadFile $BuildLog;
734 my $DejagnuLogData = ReadFile $DejagnuLog;
735 my $CheckoutLogData = ReadFile $COLog;
736
737 # Checkout info.
738 my $CheckoutTime_Wall = GetRegex "^real ([0-9.]+)", $CheckoutLogData;
739 my $CheckoutTime_User = GetRegex "^user ([0-9.]+)", $CheckoutLogData;
740 my $CheckoutTime_Sys = GetRegex "^sys ([0-9.]+)", $CheckoutLogData;
741 my $CheckoutTime_CPU = $CVSCheckoutTime_User + $CVSCheckoutTime_Sys;
742
743 # Configure info.
744 my $ConfigTimeU = GetRegex "^user ([0-9.]+)", $ConfigureLogData;
745 my $ConfigTimeS = GetRegex "^sys ([0-9.]+)", $ConfigureLogData;
746 my $ConfigTime  = $ConfigTimeU+$ConfigTimeS;  # ConfigTime = User+System
747 my $ConfigWallTime = GetRegex "^real ([0-9.]+)",$ConfigureLogData;
748 $ConfigTime=-1 unless $ConfigTime;
749 $ConfigWallTime=-1 unless $ConfigWallTime;
750
751 # Build info.
752 my $BuildTimeU = GetRegex "^user ([0-9.]+)", $BuildLogData;
753 my $BuildTimeS = GetRegex "^sys ([0-9.]+)", $BuildLogData;
754 my $BuildTime  = $BuildTimeU+$BuildTimeS;  # BuildTime = User+System
755 my $BuildWallTime = GetRegex "^real ([0-9.]+)", $BuildLogData;
756 $BuildTime=-1 unless $BuildTime;
757 $BuildWallTime=-1 unless $BuildWallTime;
758
759 # DejaGNU info.
760 my $DejagnuTimeU = GetRegex "^user ([0-9.]+)", $DejagnuLogData;
761 my $DejagnuTimeS = GetRegex "^sys ([0-9.]+)", $DejagnuLogData;
762 $DejagnuTime  = $DejagnuTimeU+$DejagnuTimeS;  # DejagnuTime = User+System
763 $DejagnuWallTime = GetRegex "^real ([0-9.]+)", $DejagnuLogData;
764 $DejagnuTime     = "0.0" unless $DejagnuTime;
765 $DejagnuWallTime = "0.0" unless $DejagnuWallTime;
766
767 if ( $VERBOSE ) { print "SEND THE DATA VIA THE POST REQUEST\n"; }
768
769 my %hash_of_data = (
770   'machine_data' => $machine_data,
771   'build_data' => $ConfigureLogData . $BuildLogData,
772   'gcc_version' => $gcc_version,
773   'nickname' => $nickname,
774   'dejagnutime_wall' => $DejagnuWallTime,
775   'dejagnutime_cpu' => $DejagnuTime,
776   'cvscheckouttime_wall' => $CheckoutTime_Wall,
777   'cvscheckouttime_cpu' => $CheckoutTime_CPU,
778   'configtime_wall' => $ConfigWallTime,
779   'configtime_cpu'=> $ConfigTime,
780   'buildtime_wall' => $BuildWallTime,
781   'buildtime_cpu' => $BuildTime,
782   'buildstatus' => $BuildStatus,
783   'singlesource_programstable' => $SingleSourceProgramsTable,
784   'multisource_programstable' => $MultiSourceProgramsTable,
785   'externalsource_programstable' => $ExternalProgramsTable,
786   'llcbeta_options' => $llcbeta_options,
787   'passing_tests' => $passes,
788   'expfail_tests' => $xfails,
789   'unexpfail_tests' => $fails,
790   'all_tests' => $all_tests,
791   'dejagnutests_results' => $DejagnuTestResults,
792   'dejagnutests_log' => $DejagnuLogData,
793   'starttime' => $starttime,
794   'endtime' => $endtime,
795   'target_triple' => $targetTriple,
796
797   # Unused, but left around for backwards compatability.
798   'warnings' => "",
799   'cvsusercommitlist' => "",
800   'cvsuserupdatelist' => "",
801   'cvsaddedfiles' => "",
802   'cvsmodifiedfiles' => "",
803   'cvsremovedfiles' => "",
804   'lines_of_code' => "",
805   'cvs_file_count' => 0,
806   'cvs_dir_count' => 0,
807   'warnings_removed' => "",
808   'warnings_added' => "",
809   'new_tests' => "",
810   'removed_tests' => "",
811   'o_file_sizes' => "",
812   'a_file_sizes' => ""
813 );
814
815 if ($SUBMIT || !($SUBMITAUX eq "")) {
816   my $response = SendData $SUBMITSERVER,$SUBMITSCRIPT,\%hash_of_data;
817   if( $VERBOSE) { print "============================\n$response"; }
818 } else {
819   print "============================\n";
820   foreach $x(keys %hash_of_data){
821       print "$x  => $hash_of_data{$x}\n";
822   }
823 }
824
825 ##############################################################
826 #
827 # Remove the source tree...
828 #
829 ##############################################################
830 system ( "$NICE rm -rf $BuildDir")
831   if (!$NOCHECKOUT and !$NOREMOVE and !$NOREMOVEATEND);
832 system ( "$NICE rm -rf $WebDir")
833   if (!$NOCHECKOUT and !$NOREMOVE and !$NOREMOVERESULTS);