Description:
[grader] better test case for timeout, changed where check_mem_usage is called to reduce inefficiency
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@167 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
r43:b03203ec084a - - 2 files changed: 25 inserted, 11 deleted
@@ -423,15 +423,11 | |||
|
423 | 423 | if (timer_tick) |
|
424 | 424 | { |
|
425 | 425 | check_timeout(); |
|
426 | + check_memory_usage(); | |
|
426 | 427 | timer_tick = 0; |
|
427 | 428 | } |
|
428 | 429 | p = wait4(box_pid, &stat, WUNTRACED, &rus); |
|
429 | 430 | |
|
430 | - if(!WIFEXITED(stat)) { | |
|
431 | - // printf("CHECKING\n"); | |
|
432 | - check_memory_usage(); | |
|
433 | - } | |
|
434 | - | |
|
435 | 431 | if (p < 0) |
|
436 | 432 | { |
|
437 | 433 | if (errno == EINTR) |
@@ -449,9 +445,9 | |||
|
449 | 445 | |
|
450 | 446 | box_pid = 0; |
|
451 | 447 | if (WEXITSTATUS(stat)) |
|
452 | - fprintf(stderr,"Exited with error status %d.", WEXITSTATUS(stat)); | |
|
448 | + fprintf(stderr,"Exited with error status %d.\n", WEXITSTATUS(stat)); | |
|
453 | 449 | else if ((use_wall_clock ? wall : total.tv_sec) > timeout) |
|
454 | - fprintf(stderr,"Time limit exceeded."); | |
|
450 | + fprintf(stderr,"Time limit exceeded.\n"); | |
|
455 | 451 | else |
|
456 | 452 | // report OK and statistics |
|
457 | 453 | fprintf(stderr,"OK\n"); |
@@ -476,7 +472,7 | |||
|
476 | 472 | if (WIFSIGNALED(stat)) |
|
477 | 473 | { |
|
478 | 474 | box_pid = 0; |
|
479 | - fprintf(stderr,"Caught fatal signal %d.", WTERMSIG(stat)); | |
|
475 | + fprintf(stderr,"Caught fatal signal %d.\n", WTERMSIG(stat)); | |
|
480 | 476 | |
|
481 | 477 | struct timeval total; |
|
482 | 478 | int wall; |
@@ -1,6 +1,9 | |||
|
1 | 1 | #include <stdio.h> |
|
2 | 2 | #include <stdlib.h> |
|
3 | 3 | #include <unistd.h> |
|
4 | + #include <sys/time.h> | |
|
5 | + #include <time.h> | |
|
6 | + #include <sys/resource.h> | |
|
4 | 7 | |
|
5 | 8 | int main() |
|
6 | 9 | { |
@@ -11,13 +14,28 | |||
|
11 | 14 | scanf("%d %d",&a,&b); |
|
12 | 15 | printf("%d\n",a+b); |
|
13 | 16 | |
|
14 | - sleep(1); | |
|
17 | + struct rusage ru; | |
|
15 | 18 | |
|
16 | - c = 0; | |
|
17 | - while(c<1000000000) { | |
|
19 | + while(1) { | |
|
20 | + c++; | |
|
21 | + b+=c; | |
|
22 | + while(c<1000000000) { | |
|
23 | + c++; | |
|
24 | + b+=c; | |
|
25 | + } | |
|
26 | + getrusage(RUSAGE_SELF,&ru); | |
|
27 | + if((ru.ru_utime.tv_sec + ru.ru_stime.tv_sec)>=1) | |
|
28 | + break; | |
|
29 | + } | |
|
30 | + printf("%d\n",b); | |
|
31 | + c=0; | |
|
32 | + while(c<100000000) { | |
|
18 | 33 | c++; |
|
19 | 34 | b+=c; |
|
20 | 35 | } |
|
36 | + if(b==10) | |
|
37 | + printf("hello\n"); | |
|
38 | + | |
|
21 | 39 | exit(0); |
|
22 | 40 | } |
|
23 | 41 |
You need to be logged in to leave comments.
Login now