summaryrefslogtreecommitdiff
path: root/common/tests/run-test.pl
diff options
context:
space:
mode:
authorschodet2007-10-24 12:04:51 +0000
committerschodet2007-10-24 12:04:51 +0000
commit657fa3aa5f1c8edcc0ac0e5c70636bef93bcb9f0 (patch)
tree6854648953015f3de2619837ad4b795dcb742479 /common/tests/run-test.pl
parentba79c72b768b7924e2953969f4ebb06d2bab9bc9 (diff)
Added test timeout.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@876 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'common/tests/run-test.pl')
-rwxr-xr-xcommon/tests/run-test.pl69
1 files changed, 60 insertions, 9 deletions
diff --git a/common/tests/run-test.pl b/common/tests/run-test.pl
index b2a5da4bea..0fcddea122 100755
--- a/common/tests/run-test.pl
+++ b/common/tests/run-test.pl
@@ -6,12 +6,20 @@ use strict;
use warnings;
use Cwd;
+my $timeout = 5 * 60;
+
# Initialise signal number to name table.
use Config;
my @signame;
+my %signum;;
my $i = 0;
defined $Config{sig_name} || die "No sigs?";
-$signame[$i++] = $_ foreach split (' ', $Config{sig_name});
+foreach (split (' ', $Config{sig_name}))
+{
+ $signame[$i] = $_;
+ $signum{$_} = $i;
+ $i++;
+}
my $base = getcwd . '/' . shift @ARGV;
my $dir;
@@ -71,7 +79,7 @@ while (<STDIN>)
# Start test.
my $t = "=> $dir - $name";
print "\n$t\n";
- system ($cmd);
+ my $status = timed_system ($cmd);
# Check result.
if ($dontcare)
{
@@ -79,18 +87,18 @@ while (<STDIN>)
}
else
{
- if ($? != 0)
+ if ($status != 0)
{
$fail++ unless $expected;
- if ($? == -1) {
+ if ($status == -1 || $status == 128 << 8) {
print "=$t: FAIL$expected command not found\n";
- } elsif ($? & 127) {
+ } elsif ($status & 127) {
printf "=$t: FAIL$expected killed with signal %s\n",
- $signame[$? & 127];
- die "interrupted" if ($signame[$? & 127] eq 'INT');
+ $signame[$status & 127];
+ die "interrupted" if ($signame[$status & 127] eq 'INT');
} else {
printf "=$t: FAIL$expected exited with value %d\n",
- ($? >> 8);
+ ($status >> 8);
}
}
else
@@ -140,5 +148,48 @@ sub cov_macro
sub cov_target_macro
{
my ($name, $arg, $cmd) = @_;
- return cov_macro ($name, $arg, $cmd, '.', " -g $ENV{CROSS_COMPILE_}gcov");
+ if (exists $ENV{CROSS_COMPILE_})
+ {
+ return cov_macro ($name, $arg, $cmd, '.', " -g $ENV{CROSS_COMPILE_}gcov");
+ }
+ else
+ {
+ return ('run', $cmd);
+ }
+}
+
+sub timed_system
+{
+ my $cmd = shift;
+ my $pid = fork;
+ defined $pid or die "fork: $!,";
+ if ($pid == 0)
+ {
+ # Son.
+ exec $cmd;
+ exit 128;
+ }
+ else
+ {
+ # Father.
+ eval {
+ local $SIG{ALRM} = sub { die "alarm\n" };
+ alarm $timeout;
+ do { $_ = wait } until $_ == $pid;
+ alarm 0;
+ };
+ if ($@)
+ {
+ die unless $@ eq "alarm\n";
+ kill INT => $pid;
+ sleep 3;
+ kill KILL => $pid;
+ print "Timed out!\n";
+ return $signum{ALRM};
+ }
+ else
+ {
+ return $?;
+ }
+ }
}