#!/usr/local/bin/perl # # Timeout wrapper # $SIG{ALRM} = sub { die "timeout" }; my @sc; my $sname; @sc = split("\/",$ARGV[3]); $sname = pop @sc; if ($ARGV[3] =~ /stress/) { $t = 250 } else { $t = 15 } eval { die "== Proj 2 grading test cannot fork: $!" unless defined($pid = open(KID_TO_READ, "-|")); if ($pid) { # parent my $result; alarm($t); while () { print; } close(KID_TO_READ) or warn "kid exited $?"; } else { # child # reconfigure, then exec(@ARGV) or die "== Proj 2 grading test cannot exec program: $!"; } }; if ($@) { if ($@ =~ /timeout/) { # printf("\n== Proj 2 grading test case failed. (timeout)\n"); printf("== Proj 2 grading script $sname failed. (timeout)\n"); } kill 9 => $pid; }