Description:
[grader] fixed bug #6 and #9 git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@139 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r37:effd16a52c43 - - 5 files changed: 13 inserted, 3 deleted

@@ -21,50 +21,52
21 attr_accessor :grader_hostname
21 attr_accessor :grader_hostname
22
22
23 # If talkative=true, grader would report status to console. If
23 # If talkative=true, grader would report status to console. If
24 # logging=true, grader would report status to a log file located
24 # logging=true, grader would report status to a log file located
25 # in log_dir, in a file name mode.options.pid. TODO: defined
25 # in log_dir, in a file name mode.options.pid. TODO: defined
26 # log file naming.
26 # log file naming.
27 attr_accessor :talkative
27 attr_accessor :talkative
28 attr_accessor :logging
28 attr_accessor :logging
29 attr_accessor :log_dir
29 attr_accessor :log_dir
30
30
31 # These are directories related to the test interface.
31 # These are directories related to the test interface.
32 attr_accessor :test_request_input_base_dir
32 attr_accessor :test_request_input_base_dir
33 attr_accessor :test_request_output_base_dir
33 attr_accessor :test_request_output_base_dir
34 attr_accessor :test_request_problem_templates_dir
34 attr_accessor :test_request_problem_templates_dir
35
35
36 # Comment received from the grading script will be filtered
36 # Comment received from the grading script will be filtered
37 # through Configuration#report_comment. How this method behave
37 # through Configuration#report_comment. How this method behave
38 # depends on this option; right now only two formats, :short and
38 # depends on this option; right now only two formats, :short and
39 # :long
39 # :long
40 attr_accessor :comment_report_style
40 attr_accessor :comment_report_style
41
41
42 def report_comment(comment)
42 def report_comment(comment)
43 case comment_report_style
43 case comment_report_style
44 when :short
44 when :short
45 - if comment.chomp =~ /^P+$/ # all P's
45 + if comment.chomp =~ /^[\[\]P]+$/ # all P's
46 'passed'
46 'passed'
47 + elsif comment.chomp =~ /[Cc]ompil.*[Ee]rror/
48 + 'compilation error'
47 else
49 else
48 'failed'
50 'failed'
49 end
51 end
50
52
51 when :full
53 when :full
52 comment.chomp
54 comment.chomp
53 end
55 end
54 end
56 end
55
57
56 # Codes for singleton
58 # Codes for singleton
57 private_class_method :new
59 private_class_method :new
58
60
59 @@instance = nil
61 @@instance = nil
60
62
61 def self.get_instance
63 def self.get_instance
62 if @@instance==nil
64 if @@instance==nil
63 @@instance = new
65 @@instance = new
64 end
66 end
65 @@instance
67 @@instance
66 end
68 end
67
69
68 private
70 private
69 def initialize
71 def initialize
70 @talkative = false
72 @talkative = false
@@ -66,50 +66,52
66 result_file.close
66 result_file.close
67 rescue
67 rescue
68 result = 0
68 result = 0
69 comment = "error reading result file."
69 comment = "error reading result file."
70 end
70 end
71
71
72 begin
72 begin
73 comment_file = File.open(comment_fname)
73 comment_file = File.open(comment_fname)
74 comment += comment_file.readline.chomp
74 comment += comment_file.readline.chomp
75 comment_file.close
75 comment_file.close
76 rescue
76 rescue
77 comment += ""
77 comment += ""
78 end
78 end
79
79
80 return {:points => result,
80 return {:points => result,
81 :comment => comment,
81 :comment => comment,
82 :cmp_msg => cmp_msg}
82 :cmp_msg => cmp_msg}
83 else
83 else
84 if FileTest.exist?("#{test_result_dir}/a.out")
84 if FileTest.exist?("#{test_result_dir}/a.out")
85 return {:points => 0,
85 return {:points => 0,
86 :comment => 'error during grading',
86 :comment => 'error during grading',
87 :cmp_msg => cmp_msg}
87 :cmp_msg => cmp_msg}
88 else
88 else
89 return {:points => 0,
89 return {:points => 0,
90 - :comment => 'compile error',
90 + :comment => 'compilation error',
91 :cmp_msg => cmp_msg}
91 :cmp_msg => cmp_msg}
92 end
92 end
93 end
93 end
94 end
94 end
95
95
96 def save_result(submission,result)
96 def save_result(submission,result)
97 problem = submission.problem
97 problem = submission.problem
98 submission.graded_at = Time.now
98 submission.graded_at = Time.now
99 points = result[:points]
99 points = result[:points]
100 submission.points = points
100 submission.points = points
101 comment = @config.report_comment(result[:comment])
101 comment = @config.report_comment(result[:comment])
102 if problem == nil
102 if problem == nil
103 submission.grader_comment = 'PASSED: ' + comment + '(problem is nil)'
103 submission.grader_comment = 'PASSED: ' + comment + '(problem is nil)'
104 elsif points == problem.full_score
104 elsif points == problem.full_score
105 submission.grader_comment = 'PASSED: ' + comment
105 submission.grader_comment = 'PASSED: ' + comment
106 + elsif result[:comment].chomp =~ /^[\[\]P]+$/
107 + submission.grader_comment = 'PASSED: ' + comment + '(inconsistent score)'
106 else
108 else
107 submission.grader_comment = 'FAILED: ' + comment
109 submission.grader_comment = 'FAILED: ' + comment
108 end
110 end
109 submission.compiler_message = result[:cmp_msg] or ''
111 submission.compiler_message = result[:cmp_msg] or ''
110 submission.save
112 submission.save
111 end
113 end
112
114
113 end
115 end
114
116
115 end
117 end
@@ -1,10 +1,13
1 + /*
2 + LANG: C
3 + */
1 #include <stdio.h>
4 #include <stdio.h>
2
5
3 int main()
6 int main()
4 {
7 {
5 int a,
8 int a,
6 scanf("%d %d",&a,&b);
9 scanf("%d %d",&a,&b);
7 printf("%d\n",a+b);
10 printf("%d\n",a+b);
8 return 0;
11 return 0;
9 }
12 }
10
13
@@ -1,10 +1,13
1 + /*
2 + LANG: C
3 + */
1 #include <stdio.h>
4 #include <stdio.h>
2
5
3 int main()
6 int main()
4 {
7 {
5 int a,b;
8 int a,b;
6 scanf("%d %d",&a,&b);
9 scanf("%d %d",&a,&b);
7 printf("%d\n",a+b);
10 printf("%d\n",a+b);
8 return 0;
11 return 0;
9 }
12 }
10
13
@@ -12,49 +12,49
12 @problem_test_normal = stub(Problem,
12 @problem_test_normal = stub(Problem,
13 :id => 1, :name => 'test_normal',
13 :id => 1, :name => 'test_normal',
14 :full_score => 135)
14 :full_score => 135)
15 @user_user1 = stub(User,
15 @user_user1 = stub(User,
16 :id => 1, :login => 'user1')
16 :id => 1, :login => 'user1')
17
17
18 @engine = Grader::Engine.new
18 @engine = Grader::Engine.new
19 init_sandbox
19 init_sandbox
20 end
20 end
21
21
22 it "should grade normal submission" do
22 it "should grade normal submission" do
23 grader_should(:grade => "test1_correct.c",
23 grader_should(:grade => "test1_correct.c",
24 :on => @problem_test_normal,
24 :on => @problem_test_normal,
25 :and_report => {
25 :and_report => {
26 :score => 135,
26 :score => 135,
27 :comment => /^PASSED/})
27 :comment => /^PASSED/})
28 end
28 end
29
29
30
30
31 it "should produce error message when submission cannot compile" do
31 it "should produce error message when submission cannot compile" do
32 grader_should(:grade => "test1_compile_error.c",
32 grader_should(:grade => "test1_compile_error.c",
33 :on => @problem_test_normal,
33 :on => @problem_test_normal,
34 :and_report => {
34 :and_report => {
35 :score => 0,
35 :score => 0,
36 - :comment => 'FAILED: compile error',
36 + :comment => 'FAILED: compilation error',
37 :compiler_message => /[Ee]rror/})
37 :compiler_message => /[Ee]rror/})
38 end
38 end
39
39
40 it "should produce timeout error when submission runs forever" do
40 it "should produce timeout error when submission runs forever" do
41 @problem_test_timeout = stub(Problem,
41 @problem_test_timeout = stub(Problem,
42 :id => 1, :name => 'test_timeout',
42 :id => 1, :name => 'test_timeout',
43 :full_score => 10)
43 :full_score => 10)
44 grader_should(:grade => "test2_timeout.c",
44 grader_should(:grade => "test2_timeout.c",
45 :on => @problem_test_timeout,
45 :on => @problem_test_timeout,
46 :and_report => {
46 :and_report => {
47 :score => 0,
47 :score => 0,
48 :comment => 'FAILED: TT'})
48 :comment => 'FAILED: TT'})
49 end
49 end
50
50
51 it "should produce timeout error correctly when submission runs slower than expected in less than a second" do
51 it "should produce timeout error correctly when submission runs slower than expected in less than a second" do
52 @problem_test_timeout = stub(Problem,
52 @problem_test_timeout = stub(Problem,
53 :id => 1, :name => 'test_timeout',
53 :id => 1, :name => 'test_timeout',
54 :full_score => 20)
54 :full_score => 20)
55 grader_should(:grade => "test2_1-5sec.c",
55 grader_should(:grade => "test2_1-5sec.c",
56 :on => @problem_test_timeout,
56 :on => @problem_test_timeout,
57 :and_report => {
57 :and_report => {
58 :score => 10,
58 :score => 10,
59 :comment => 'FAILED: TP'})
59 :comment => 'FAILED: TP'})
60 end
60 end
You need to be logged in to leave comments. Login now