Description:
[grader] added fractional timelimit
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@191 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r51:3618759afb50 - - 6 files changed: 66 inserted, 57 deleted
@@ -0,0 +1,38 | |||
|
1 | + #include <stdio.h> | |
|
2 | + #include <stdlib.h> | |
|
3 | + #include <unistd.h> | |
|
4 | + #include <sys/time.h> | |
|
5 | + #include <time.h> | |
|
6 | + #include <sys/resource.h> | |
|
7 | + | |
|
8 | + // run it for 1.5 s | |
|
9 | + | |
|
10 | + int main() | |
|
11 | + { | |
|
12 | + int a,b; | |
|
13 | + | |
|
14 | + int c=0; | |
|
15 | + | |
|
16 | + scanf("%d %d",&a,&b); | |
|
17 | + printf("%d\n",a+b); | |
|
18 | + | |
|
19 | + struct rusage ru; | |
|
20 | + | |
|
21 | + while(1) { | |
|
22 | + c++; | |
|
23 | + b+=c; | |
|
24 | + while(c<100000) { | |
|
25 | + c++; | |
|
26 | + b+=c; | |
|
27 | + } | |
|
28 | + getrusage(RUSAGE_SELF,&ru); | |
|
29 | + double rtime = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec; | |
|
30 | + rtime += (double)ru.ru_utime.tv_usec / 1000000.0; | |
|
31 | + rtime += (double)ru.ru_stime.tv_usec / 1000000.0; | |
|
32 | + if(rtime > 0.5) | |
|
33 | + break; | |
|
34 | + } | |
|
35 | + printf("%d\n",b); | |
|
36 | + exit(0); | |
|
37 | + } | |
|
38 | + |
@@ -164,17 +164,22 | |||
|
164 | 164 | when "prob" |
|
165 | 165 | engine = Grader::Engine.new |
|
166 | 166 | runner = Grader::Runner.new(engine, grader_proc) |
|
167 | 167 | |
|
168 | 168 | grader_proc.report_active if grader_proc!=nil |
|
169 | 169 | |
|
170 | - prob = Problem.find_by_name(ARGV[2]) | |
|
171 | - if prob==nil | |
|
172 | - puts "cannot find problem: #{ARGV[2]}" | |
|
173 | - else | |
|
174 | - runner.grade_problem(prob) | |
|
170 | + ARGV.shift | |
|
171 | + ARGV.shift | |
|
172 | + | |
|
173 | + ARGV.each do |prob_name| | |
|
174 | + prob = Problem.find_by_name(prob_name) | |
|
175 | + if prob==nil | |
|
176 | + puts "cannot find problem: #{prob_name}" | |
|
177 | + else | |
|
178 | + runner.grade_problem(prob) | |
|
179 | + end | |
|
175 | 180 | end |
|
176 | 181 | |
|
177 | 182 | else |
|
178 | 183 | display_manual |
|
179 | 184 | exit(0) |
|
180 | 185 | end |
@@ -26,13 +26,13 | |||
|
26 | 26 | #include <sys/resource.h> |
|
27 | 27 | |
|
28 | 28 | #define NONRET __attribute__((noreturn)) |
|
29 | 29 | #define UNUSED __attribute__((unused)) |
|
30 | 30 | |
|
31 | 31 | static int filter_syscalls; /* 0=off, 1=liberal, 2=totalitarian */ |
|
32 |
- static |
|
|
32 | + static double timeout; | |
|
33 | 33 | static int pass_environ; |
|
34 | 34 | static int use_wall_clock; |
|
35 | 35 | static int file_access; |
|
36 | 36 | static int verbose; |
|
37 | 37 | static int memory_limit; |
|
38 | 38 | static int allow_times; |
@@ -324,16 +324,16 | |||
|
324 | 324 | die("Interrupted."); |
|
325 | 325 | } |
|
326 | 326 | |
|
327 | 327 | static void |
|
328 | 328 | check_timeout(void) |
|
329 | 329 | { |
|
330 |
- |
|
|
330 | + double sec; | |
|
331 | 331 | |
|
332 | 332 | if (use_wall_clock) |
|
333 | - sec = time(NULL) - start_time; | |
|
333 | + sec = (double)(time(NULL) - start_time); | |
|
334 | 334 | else |
|
335 | 335 | { |
|
336 | 336 | char buf[4096], *x; |
|
337 | 337 | int c, utime, stime; |
|
338 | 338 | static int proc_status_fd; |
|
339 | 339 | if (!proc_status_fd) |
@@ -360,18 +360,18 | |||
|
360 | 360 | x++; |
|
361 | 361 | while (*x == ')' || *x == ' ') |
|
362 | 362 | x++; |
|
363 | 363 | if (sscanf(x, "%*c %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %d %d", &utime, &stime) != 2) |
|
364 | 364 | die("proc syntax error 2"); |
|
365 | 365 | //printf("%s - %d\n",x,ticks_per_sec); |
|
366 |
- sec = (utime + stime |
|
|
366 | + sec = ((double)(utime + stime))/(double)ticks_per_sec; | |
|
367 | 367 | } |
|
368 | 368 | if (verbose > 1) |
|
369 | 369 | fprintf(stderr, "[timecheck: %d seconds]\n", sec); |
|
370 | 370 | if (sec > timeout) { |
|
371 | - die("Time limit exceeded."); | |
|
371 | + die("Time limit exceeded.",sec,timeout); | |
|
372 | 372 | } |
|
373 | 373 | } |
|
374 | 374 | |
|
375 | 375 | static void |
|
376 | 376 | check_memory_usage() |
|
377 | 377 | { |
@@ -463,13 +463,16 | |||
|
463 | 463 | wall = time(NULL) - start_time; |
|
464 | 464 | timeradd(&rus.ru_utime, &rus.ru_stime, &total); |
|
465 | 465 | |
|
466 | 466 | box_pid = 0; |
|
467 | 467 | if (WEXITSTATUS(stat)) |
|
468 | 468 | fprintf(stderr,"Exited with error status %d.\n", WEXITSTATUS(stat)); |
|
469 |
- else if ((use_wall_clock ? |
|
|
469 | + else if ((use_wall_clock ? | |
|
470 | + wall : | |
|
471 | + (double) total.tv_sec + | |
|
472 | + ((double) total.tv_usec/1000000.0)) > timeout) | |
|
470 | 473 | fprintf(stderr,"Time limit exceeded.\n"); |
|
471 | 474 | else |
|
472 | 475 | // report OK and statistics |
|
473 | 476 | fprintf(stderr,"OK\n"); |
|
474 | 477 | |
|
475 | 478 | print_running_stat((double) wall, |
@@ -643,13 +646,13 | |||
|
643 | 646 | memory_limit = atol(optarg); |
|
644 | 647 | break; |
|
645 | 648 | case 'o': |
|
646 | 649 | redir_stdout = optarg; |
|
647 | 650 | break; |
|
648 | 651 | case 't': |
|
649 |
- timeout = ato |
|
|
652 | + timeout = atof(optarg); | |
|
650 | 653 | break; |
|
651 | 654 | case 'T': |
|
652 | 655 | allow_times++; |
|
653 | 656 | break; |
|
654 | 657 | case 'v': |
|
655 | 658 | verbose++; |
@@ -2,18 +2,22 | |||
|
2 | 2 | num_tests 2 |
|
3 | 3 | full_score 20 |
|
4 | 4 | time_limit_each 1 |
|
5 | 5 | mem_limit_each 16 |
|
6 | 6 | score_each 10 |
|
7 | 7 | |
|
8 | + test 1 do | |
|
9 | + time_limit 0.5 | |
|
10 | + end | |
|
11 | + | |
|
8 | 12 | run 1 do |
|
9 | 13 | tests 1 |
|
10 | 14 | end |
|
11 | 15 | |
|
12 | 16 | test 2 do |
|
13 |
- time_limit |
|
|
17 | + time_limit 0.6 | |
|
14 | 18 | end |
|
15 | 19 | |
|
16 | 20 | run 2 do |
|
17 | 21 | tests 2 |
|
18 | 22 | end |
|
19 | 23 |
@@ -45,17 +45,17 | |||
|
45 | 45 | :on => @problem_test_timeout, |
|
46 | 46 | :and_report => { |
|
47 | 47 | :score => 0, |
|
48 | 48 | :comment => 'FAILED: TT'}) |
|
49 | 49 | end |
|
50 | 50 | |
|
51 |
- it "should produce timeout error correctly w |
|
|
52 | - @problem_test_timeout = stub(Problem, | |
|
51 | + it "should produce timeout error correctly with fractional running time and fractional time limits" do | |
|
52 | + @problem_test_timeout = stub(Problem, | |
|
53 | 53 | :id => 1, :name => 'test_timeout', |
|
54 | 54 | :full_score => 20) |
|
55 |
- grader_should(:grade => "test2_ |
|
|
55 | + grader_should(:grade => "test2_05sec.c", | |
|
56 | 56 | :on => @problem_test_timeout, |
|
57 | 57 | :and_report => { |
|
58 | 58 | :score => 10, |
|
59 | 59 | :comment => 'FAILED: TP'}) |
|
60 | 60 | end |
|
61 | 61 |
deleted file |
You need to be logged in to leave comments.
Login now