2010-03-23 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / tests / test-driver
index b2f083ae7b4f7ebc9d6ceab82df467b754882a43..93812abd7d1a234746de695902b29fff78f1f311 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env perl 
+#!/usr/bin/env perl
 
 my $interpreter = shift;
 my $test = shift;
@@ -12,12 +12,34 @@ $output =~ s/\.exe$/.output/;
 $| = 0;
 print "Testing $test... ";
 
-if (index ($disabled_tests, $test) >= 0) {
-       print "disabled.\n";
-       exit (0);
+foreach $disabled (split (/ /, $disabled_tests)) {
+       if ($disabled eq $test) {
+               print "disabled.\n";
+               exit (0);
+       }
 }
 
-my $res = system("$interpreter @ARGV $test 2>$stderr 1>$stdout");
+my $res;
+my $cpid = fork ();
+if (!defined ($cpid)) {
+       $res = system("$interpreter @ARGV $test 2>$stderr 1>$stdout");
+} elsif ($cpid == 0) {
+       exec ("$interpreter @ARGV $test 2>$stderr 1>$stdout") || die "Cannot exec: $!";
+} else {
+       # in the parent, setup the alarm
+       # test must complete in 2 minutes or it is considered buggy
+       my $timeout = 2*60;
+       alarm ($timeout);
+       $SIG{ALRM} = sub {
+               print "failed after $timeout seconds timeout.\n";
+               # process group kill
+               kill (-9, $cpid);
+               exit (3);
+       };
+       $res = wait ();
+       $SIG{ALRM} = sub {};
+       $res = $? >> 8;
+}
 
 if ($res) {
        printf ("failed $? (%d) signal (%d).\n", $? >> 8, $? & 127);
@@ -26,13 +48,14 @@ if ($res) {
        } else {
                exit (1);
        }
-} elsif (-f $output) {
-       print "failed output.\n" if (read_file ($output) ne read_file ($stdout));
+}
+if (-f $output && (read_file ($output) ne read_file ($stdout))) {
+       print "failed output.\n";
        exit (1);
-} else {
-       print "pass.\n";
-       unlink ($stderr);
 }
+
+print "pass.\n";
+unlink ($stderr);
 exit (0);
 
 sub read_file {