diff --git a/grader b/grader --- a/grader +++ b/grader @@ -167,11 +167,16 @@ grader_proc.report_active if grader_proc!=nil - prob = Problem.find_by_name(ARGV[2]) - if prob==nil - puts "cannot find problem: #{ARGV[2]}" - else - runner.grade_problem(prob) + ARGV.shift + ARGV.shift + + ARGV.each do |prob_name| + prob = Problem.find_by_name(prob_name) + if prob==nil + puts "cannot find problem: #{prob_name}" + else + runner.grade_problem(prob) + end end else diff --git a/std-script/box.cc b/std-script/box.cc --- a/std-script/box.cc +++ b/std-script/box.cc @@ -29,7 +29,7 @@ #define UNUSED __attribute__((unused)) static int filter_syscalls; /* 0=off, 1=liberal, 2=totalitarian */ -static int timeout; +static double timeout; static int pass_environ; static int use_wall_clock; static int file_access; @@ -327,10 +327,10 @@ static void check_timeout(void) { - int sec; + double sec; if (use_wall_clock) - sec = time(NULL) - start_time; + sec = (double)(time(NULL) - start_time); else { char buf[4096], *x; @@ -363,12 +363,12 @@ if (sscanf(x, "%*c %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %d %d", &utime, &stime) != 2) die("proc syntax error 2"); //printf("%s - %d\n",x,ticks_per_sec); - sec = (utime + stime + ticks_per_sec-1)/ticks_per_sec; + sec = ((double)(utime + stime))/(double)ticks_per_sec; } if (verbose > 1) fprintf(stderr, "[timecheck: %d seconds]\n", sec); if (sec > timeout) { - die("Time limit exceeded."); + die("Time limit exceeded.",sec,timeout); } } @@ -466,7 +466,10 @@ box_pid = 0; if (WEXITSTATUS(stat)) fprintf(stderr,"Exited with error status %d.\n", WEXITSTATUS(stat)); - else if ((use_wall_clock ? wall : total.tv_sec) > timeout) + else if ((use_wall_clock ? + wall : + (double) total.tv_sec + + ((double) total.tv_usec/1000000.0)) > timeout) fprintf(stderr,"Time limit exceeded.\n"); else // report OK and statistics @@ -646,7 +649,7 @@ redir_stdout = optarg; break; case 't': - timeout = atol(optarg); + timeout = atof(optarg); break; case 'T': allow_times++; diff --git a/test/data/ev/test_timeout/test_cases/all_tests.cfg b/test/data/ev/test_timeout/test_cases/all_tests.cfg --- a/test/data/ev/test_timeout/test_cases/all_tests.cfg +++ b/test/data/ev/test_timeout/test_cases/all_tests.cfg @@ -5,12 +5,16 @@ mem_limit_each 16 score_each 10 + test 1 do + time_limit 0.5 + end + run 1 do tests 1 end test 2 do - time_limit 2 + time_limit 0.6 end run 2 do diff --git a/test/data/test2_05sec.c b/test/data/test2_05sec.c new file mode 100644 --- /dev/null +++ b/test/data/test2_05sec.c @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#include + +// run it for 1.5 s + +int main() +{ + int a,b; + + int c=0; + + scanf("%d %d",&a,&b); + printf("%d\n",a+b); + + struct rusage ru; + + while(1) { + c++; + b+=c; + while(c<100000) { + c++; + b+=c; + } + getrusage(RUSAGE_SELF,&ru); + double rtime = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec; + rtime += (double)ru.ru_utime.tv_usec / 1000000.0; + rtime += (double)ru.ru_stime.tv_usec / 1000000.0; + if(rtime > 0.5) + break; + } + printf("%d\n",b); + exit(0); +} + diff --git a/test/data/test2_1-5sec.c b/test/data/test2_1-5sec.c deleted file mode 100644 --- a/test/data/test2_1-5sec.c +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include -#include -#include -#include - -int main() -{ - int a,b; - - int c=0; - - scanf("%d %d",&a,&b); - printf("%d\n",a+b); - - struct rusage ru; - - while(1) { - c++; - b+=c; - while(c<1000000000) { - c++; - b+=c; - } - getrusage(RUSAGE_SELF,&ru); - if((ru.ru_utime.tv_sec + ru.ru_stime.tv_sec)>=1) - break; - } - printf("%d\n",b); - c=0; - while(c<100000000) { - c++; - b+=c; - } - if(b==10) - printf("hello\n"); - - exit(0); -} - diff --git a/test/engine_spec.rb b/test/engine_spec.rb --- a/test/engine_spec.rb +++ b/test/engine_spec.rb @@ -48,11 +48,11 @@ :comment => 'FAILED: TT'}) end - it "should produce timeout error correctly when submission runs slower than expected in less than a second" do - @problem_test_timeout = stub(Problem, + it "should produce timeout error correctly with fractional running time and fractional time limits" do + @problem_test_timeout = stub(Problem, :id => 1, :name => 'test_timeout', :full_score => 20) - grader_should(:grade => "test2_1-5sec.c", + grader_should(:grade => "test2_05sec.c", :on => @problem_test_timeout, :and_report => { :score => 10,