Description:
[grader] engine_spec: fix reg-ex new line problem, change test case for 1.5 sec submission (as the machine is a little faster)
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@150 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
r39:7a9b64601b9d - - 3 files changed: 3 inserted, 3 deleted
@@ -1,21 +1,21 | |||||
|
1 | #include <stdio.h> |
|
1 | #include <stdio.h> |
|
2 | #include <stdlib.h> |
|
2 | #include <stdlib.h> |
|
3 |
|
3 | ||
|
4 | int main() |
|
4 | int main() |
|
5 | { |
|
5 | { |
|
6 | int a,b; |
|
6 | int a,b; |
|
7 |
|
7 | ||
|
8 | int c=0; |
|
8 | int c=0; |
|
9 |
|
9 | ||
|
10 | scanf("%d %d",&a,&b); |
|
10 | scanf("%d %d",&a,&b); |
|
11 | printf("%d\n",a+b); |
|
11 | printf("%d\n",a+b); |
|
12 |
|
12 | ||
|
13 | for(a=0; a<2; a++) { |
|
13 | for(a=0; a<2; a++) { |
|
14 |
- while(c<1 |
|
14 | + while(c<1550000000) { |
|
15 | c++; |
|
15 | c++; |
|
16 | b+=c; |
|
16 | b+=c; |
|
17 | } |
|
17 | } |
|
18 | } |
|
18 | } |
|
19 | exit(0); |
|
19 | exit(0); |
|
20 | } |
|
20 | } |
|
21 |
|
21 |
@@ -43,238 +43,238 | |||||
|
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 |
|
61 |
|
61 | ||
|
62 | it "should produce runtime error when submission uses too much static memory" do |
|
62 | it "should produce runtime error when submission uses too much static memory" do |
|
63 | @problem_test_memory = stub(Problem, |
|
63 | @problem_test_memory = stub(Problem, |
|
64 | :id => 1, :name => 'test_memory', |
|
64 | :id => 1, :name => 'test_memory', |
|
65 | :full_score => 20) |
|
65 | :full_score => 20) |
|
66 | grader_should(:grade => "add_too_much_memory_static.c", |
|
66 | grader_should(:grade => "add_too_much_memory_static.c", |
|
67 | :on => @problem_test_memory, |
|
67 | :on => @problem_test_memory, |
|
68 | :and_report => { |
|
68 | :and_report => { |
|
69 | :score => 10, |
|
69 | :score => 10, |
|
70 | :comment => /FAILED: [^P]P/}) |
|
70 | :comment => /FAILED: [^P]P/}) |
|
71 | end |
|
71 | end |
|
72 |
|
72 | ||
|
73 | it "should not allow submission to allocate too much dynamic memory" do |
|
73 | it "should not allow submission to allocate too much dynamic memory" do |
|
74 | @problem_test_memory = stub(Problem, |
|
74 | @problem_test_memory = stub(Problem, |
|
75 | :id => 1, :name => 'test_memory', |
|
75 | :id => 1, :name => 'test_memory', |
|
76 | :full_score => 20) |
|
76 | :full_score => 20) |
|
77 | grader_should(:grade => "add_too_much_memory_dynamic.c", |
|
77 | grader_should(:grade => "add_too_much_memory_dynamic.c", |
|
78 | :on => @problem_test_memory, |
|
78 | :on => @problem_test_memory, |
|
79 | :and_report => { |
|
79 | :and_report => { |
|
80 | :score => 10, |
|
80 | :score => 10, |
|
81 | :comment => /FAILED: [^P]P/}) |
|
81 | :comment => /FAILED: [^P]P/}) |
|
82 | end |
|
82 | end |
|
83 |
|
83 | ||
|
84 | it "should score test runs correctly when submission fails in some test case" do |
|
84 | it "should score test runs correctly when submission fails in some test case" do |
|
85 | grader_should(:grade => "add_fail_test_case_1.c", |
|
85 | grader_should(:grade => "add_fail_test_case_1.c", |
|
86 | :on => @problem_test_normal, |
|
86 | :on => @problem_test_normal, |
|
87 | :and_report => { |
|
87 | :and_report => { |
|
88 | :score => 105, |
|
88 | :score => 105, |
|
89 | :comment => /^FAILED:/}) |
|
89 | :comment => /^FAILED:/}) |
|
90 | end |
|
90 | end |
|
91 |
|
91 | ||
|
92 | it "should fail submission with non-zero exit status" do |
|
92 | it "should fail submission with non-zero exit status" do |
|
93 | grader_should(:grade => "add_nonzero_exit_status.c", |
|
93 | grader_should(:grade => "add_nonzero_exit_status.c", |
|
94 | :on => @problem_test_normal, |
|
94 | :on => @problem_test_normal, |
|
95 | :and_report => { |
|
95 | :and_report => { |
|
96 | :score => 0, |
|
96 | :score => 0, |
|
97 | :comment => /^FAILED:/}) |
|
97 | :comment => /^FAILED:/}) |
|
98 | end |
|
98 | end |
|
99 |
|
99 | ||
|
100 | it "should not allow malicious submission to see PROBLEM_HOME" do |
|
100 | it "should not allow malicious submission to see PROBLEM_HOME" do |
|
101 | problem_test_yesno = stub(Problem, |
|
101 | problem_test_yesno = stub(Problem, |
|
102 | :id => 1, :name => 'test_yesno', |
|
102 | :id => 1, :name => 'test_yesno', |
|
103 | :full_score => 10) |
|
103 | :full_score => 10) |
|
104 | grader_should(:grade => "yesno_access_problem_home.c", |
|
104 | grader_should(:grade => "yesno_access_problem_home.c", |
|
105 | :on => problem_test_yesno, |
|
105 | :on => problem_test_yesno, |
|
106 | :and_report => { |
|
106 | :and_report => { |
|
107 | :score => 0, |
|
107 | :score => 0, |
|
108 | :comment => /^FAILED:/}) |
|
108 | :comment => /^FAILED:/}) |
|
109 | end |
|
109 | end |
|
110 |
|
110 | ||
|
111 | it "should not allow malicious submission to open files" do |
|
111 | it "should not allow malicious submission to open files" do |
|
112 | problem_test_yesno = stub(Problem, |
|
112 | problem_test_yesno = stub(Problem, |
|
113 | :id => 1, :name => 'test_yesno', |
|
113 | :id => 1, :name => 'test_yesno', |
|
114 | :full_score => 10) |
|
114 | :full_score => 10) |
|
115 | grader_should(:grade => "yesno_open_file.c", |
|
115 | grader_should(:grade => "yesno_open_file.c", |
|
116 | :on => problem_test_yesno, |
|
116 | :on => problem_test_yesno, |
|
117 | :and_report => { |
|
117 | :and_report => { |
|
118 | :score => 0, |
|
118 | :score => 0, |
|
119 | :comment => /^FAILED:/}) |
|
119 | :comment => /^FAILED:/}) |
|
120 | end |
|
120 | end |
|
121 |
|
121 | ||
|
122 | def grader_should(args) |
|
122 | def grader_should(args) |
|
123 | @user1 = stub(User, |
|
123 | @user1 = stub(User, |
|
124 | :id => 1, :login => 'user1') |
|
124 | :id => 1, :login => 'user1') |
|
125 | submission = |
|
125 | submission = |
|
126 | create_submission_from_file(1, @user1, args[:on], args[:grade]) |
|
126 | create_submission_from_file(1, @user1, args[:on], args[:grade]) |
|
127 | submission.should_receive(:graded_at=) |
|
127 | submission.should_receive(:graded_at=) |
|
128 |
|
128 | ||
|
129 | expected_score = args[:and_report][:score] |
|
129 | expected_score = args[:and_report][:score] |
|
130 | expected_comment = args[:and_report][:comment] |
|
130 | expected_comment = args[:and_report][:comment] |
|
131 | if args[:and_report][:compiler_message]!=nil |
|
131 | if args[:and_report][:compiler_message]!=nil |
|
132 | expected_compiler_message = args[:and_report][:compiler_message] |
|
132 | expected_compiler_message = args[:and_report][:compiler_message] |
|
133 | else |
|
133 | else |
|
134 | expected_compiler_message = '' |
|
134 | expected_compiler_message = '' |
|
135 | end |
|
135 | end |
|
136 |
|
136 | ||
|
137 | submission.should_receive(:points=).with(expected_score) |
|
137 | submission.should_receive(:points=).with(expected_score) |
|
138 | submission.should_receive(:grader_comment=).with(expected_comment) |
|
138 | submission.should_receive(:grader_comment=).with(expected_comment) |
|
139 | submission.should_receive(:compiler_message=).with(expected_compiler_message) |
|
139 | submission.should_receive(:compiler_message=).with(expected_compiler_message) |
|
140 | submission.should_receive(:save) |
|
140 | submission.should_receive(:save) |
|
141 |
|
141 | ||
|
142 | @engine.grade(submission) |
|
142 | @engine.grade(submission) |
|
143 | end |
|
143 | end |
|
144 |
|
144 | ||
|
145 | protected |
|
145 | protected |
|
146 |
|
146 | ||
|
147 | def create_normal_submission_mock_from_file(source_fname) |
|
147 | def create_normal_submission_mock_from_file(source_fname) |
|
148 | create_submission_from_file(1, @user_user1, @problem_test_normal, source_fname) |
|
148 | create_submission_from_file(1, @user_user1, @problem_test_normal, source_fname) |
|
149 | end |
|
149 | end |
|
150 |
|
150 | ||
|
151 | end |
|
151 | end |
|
152 |
|
152 | ||
|
153 | describe "A grader engine, when grading test requests" do |
|
153 | describe "A grader engine, when grading test requests" do |
|
154 |
|
154 | ||
|
155 | include GraderEngineHelperMethods |
|
155 | include GraderEngineHelperMethods |
|
156 |
|
156 | ||
|
157 | before(:each) do |
|
157 | before(:each) do |
|
158 | @config = Grader::Configuration.get_instance |
|
158 | @config = Grader::Configuration.get_instance |
|
159 | @engine = Grader::Engine.new(Grader::TestRequestRoomMaker.new, |
|
159 | @engine = Grader::Engine.new(Grader::TestRequestRoomMaker.new, |
|
160 | Grader::TestRequestReporter.new) |
|
160 | Grader::TestRequestReporter.new) |
|
161 | init_sandbox |
|
161 | init_sandbox |
|
162 | end |
|
162 | end |
|
163 |
|
163 | ||
|
164 | it "should report error if there is no problem template" do |
|
164 | it "should report error if there is no problem template" do |
|
165 | problem = stub(Problem, |
|
165 | problem = stub(Problem, |
|
166 | :id => 1, :name => 'nothing') |
|
166 | :id => 1, :name => 'nothing') |
|
167 | grader_should(:grade => 'test1_correct.c', |
|
167 | grader_should(:grade => 'test1_correct.c', |
|
168 | :on => problem, |
|
168 | :on => problem, |
|
169 | :with => 'in1.txt', |
|
169 | :with => 'in1.txt', |
|
170 | :and_report => { |
|
170 | :and_report => { |
|
171 | :graded_at= => nil, |
|
171 | :graded_at= => nil, |
|
172 | :compiler_message= => '', |
|
172 | :compiler_message= => '', |
|
173 | :grader_comment= => '', |
|
173 | :grader_comment= => '', |
|
174 | :running_stat= => /template not found/, |
|
174 | :running_stat= => /template not found/, |
|
175 | :save => nil}) |
|
175 | :save => nil}) |
|
176 | end |
|
176 | end |
|
177 |
|
177 | ||
|
178 | it "should run test request and produce output file" do |
|
178 | it "should run test request and produce output file" do |
|
179 | problem = stub(Problem, |
|
179 | problem = stub(Problem, |
|
180 | :id => 1, :name => 'test_normal') |
|
180 | :id => 1, :name => 'test_normal') |
|
181 | grader_should(:grade => 'test1_correct.c', |
|
181 | grader_should(:grade => 'test1_correct.c', |
|
182 | :on => problem, |
|
182 | :on => problem, |
|
183 | :with => 'in1.txt', |
|
183 | :with => 'in1.txt', |
|
184 | :and_report => { |
|
184 | :and_report => { |
|
185 | :graded_at= => nil, |
|
185 | :graded_at= => nil, |
|
186 | :compiler_message= => '', |
|
186 | :compiler_message= => '', |
|
187 | :grader_comment= => '', |
|
187 | :grader_comment= => '', |
|
188 | :running_stat= => /0.0 sec./, |
|
188 | :running_stat= => /0.0 sec./, |
|
189 | :output_file_name= => lambda { |fname| |
|
189 | :output_file_name= => lambda { |fname| |
|
190 | File.exists?(fname).should be_true |
|
190 | File.exists?(fname).should be_true |
|
191 | }, |
|
191 | }, |
|
192 | :save => nil}) |
|
192 | :save => nil}) |
|
193 | end |
|
193 | end |
|
194 |
|
194 | ||
|
195 | it "should clean up problem directory after running test request" do |
|
195 | it "should clean up problem directory after running test request" do |
|
196 | problem = stub(Problem, |
|
196 | problem = stub(Problem, |
|
197 | :id => 1, :name => 'test_normal') |
|
197 | :id => 1, :name => 'test_normal') |
|
198 | grader_should(:grade => 'test1_correct.c', |
|
198 | grader_should(:grade => 'test1_correct.c', |
|
199 | :on => problem, |
|
199 | :on => problem, |
|
200 | :with => 'in1.txt', |
|
200 | :with => 'in1.txt', |
|
201 | :and_report => { |
|
201 | :and_report => { |
|
202 | :graded_at= => nil, |
|
202 | :graded_at= => nil, |
|
203 | :compiler_message= => '', |
|
203 | :compiler_message= => '', |
|
204 | :grader_comment= => '', |
|
204 | :grader_comment= => '', |
|
205 | :running_stat= => nil, |
|
205 | :running_stat= => nil, |
|
206 | :output_file_name= => nil, |
|
206 | :output_file_name= => nil, |
|
207 | :save => nil}) |
|
207 | :save => nil}) |
|
208 | File.exists?(@config.user_result_dir + "/test_request/test_normal/test_cases/1/input-1.txt").should be_false |
|
208 | File.exists?(@config.user_result_dir + "/test_request/test_normal/test_cases/1/input-1.txt").should be_false |
|
209 | end |
|
209 | end |
|
210 |
|
210 | ||
|
211 | it "should compile test request with error and report compilation error" do |
|
211 | it "should compile test request with error and report compilation error" do |
|
212 | problem = stub(Problem, |
|
212 | problem = stub(Problem, |
|
213 | :id => 1, :name => 'test_normal') |
|
213 | :id => 1, :name => 'test_normal') |
|
214 | grader_should(:grade => 'test1_compile_error.c', |
|
214 | grader_should(:grade => 'test1_compile_error.c', |
|
215 | :on => problem, |
|
215 | :on => problem, |
|
216 | :with => 'in1.txt', |
|
216 | :with => 'in1.txt', |
|
217 | :and_report => { |
|
217 | :and_report => { |
|
218 | :graded_at= => nil, |
|
218 | :graded_at= => nil, |
|
219 | :compiler_message= => /.+/, |
|
219 | :compiler_message= => /.+/, |
|
220 | :grader_comment= => /[Cc]ompil.*error/, |
|
220 | :grader_comment= => /[Cc]ompil.*error/, |
|
221 | :running_stat= => '', |
|
221 | :running_stat= => '', |
|
222 | :save => nil}) |
|
222 | :save => nil}) |
|
223 | end |
|
223 | end |
|
224 |
|
224 | ||
|
225 | it "should report exit status" do |
|
225 | it "should report exit status" do |
|
226 | problem = stub(Problem, |
|
226 | problem = stub(Problem, |
|
227 | :id => 1, :name => 'test_normal') |
|
227 | :id => 1, :name => 'test_normal') |
|
228 | grader_should(:grade => 'add_nonzero_exit_status.c', |
|
228 | grader_should(:grade => 'add_nonzero_exit_status.c', |
|
229 | :on => problem, |
|
229 | :on => problem, |
|
230 | :with => 'in1.txt', |
|
230 | :with => 'in1.txt', |
|
231 | :and_report => { |
|
231 | :and_report => { |
|
232 | :graded_at= => nil, |
|
232 | :graded_at= => nil, |
|
233 | :compiler_message= => '', |
|
233 | :compiler_message= => '', |
|
234 | :grader_comment= => '', |
|
234 | :grader_comment= => '', |
|
235 |
- :running_stat= => /[Ee]xit.*status.*10.*0.0 sec |
|
235 | + :running_stat= => /[Ee]xit.*status.*10.*0\.0 sec/m, |
|
236 | :output_file_name= => lambda { |fname| |
|
236 | :output_file_name= => lambda { |fname| |
|
237 | File.exists?(fname).should be_true |
|
237 | File.exists?(fname).should be_true |
|
238 | }, |
|
238 | }, |
|
239 | :save => nil}) |
|
239 | :save => nil}) |
|
240 | end |
|
240 | end |
|
241 |
|
241 | ||
|
242 | protected |
|
242 | protected |
|
243 | def grader_should(args) |
|
243 | def grader_should(args) |
|
244 | @user1 = stub(User, |
|
244 | @user1 = stub(User, |
|
245 | :id => 1, :login => 'user1') |
|
245 | :id => 1, :login => 'user1') |
|
246 |
|
246 | ||
|
247 | problem = args[:on] |
|
247 | problem = args[:on] |
|
248 | input_file = @config.test_request_input_base_dir + "/" + args[:with] |
|
248 | input_file = @config.test_request_input_base_dir + "/" + args[:with] |
|
249 |
|
249 | ||
|
250 | submission = |
|
250 | submission = |
|
251 | create_submission_from_file(1, @user1, args[:on], args[:grade]) |
|
251 | create_submission_from_file(1, @user1, args[:on], args[:grade]) |
|
252 |
|
252 | ||
|
253 | test_request = stub(TestRequest, |
|
253 | test_request = stub(TestRequest, |
|
254 | :id => 1, |
|
254 | :id => 1, |
|
255 | :user => @user1, |
|
255 | :user => @user1, |
|
256 | :problem => problem, |
|
256 | :problem => problem, |
|
257 | :submission => submission, |
|
257 | :submission => submission, |
|
258 | :input_file_name => input_file, |
|
258 | :input_file_name => input_file, |
|
259 | :language => submission.language, |
|
259 | :language => submission.language, |
|
260 | :problem_name => problem.name) |
|
260 | :problem_name => problem.name) |
|
261 |
|
261 | ||
|
262 | expectations = args[:and_report] |
|
262 | expectations = args[:and_report] |
|
263 |
|
263 | ||
|
264 | expectations.each do |key,val| |
|
264 | expectations.each do |key,val| |
|
265 | if val==nil |
|
265 | if val==nil |
|
266 | test_request.should_receive(key) |
|
266 | test_request.should_receive(key) |
|
267 | elsif val.class == Proc |
|
267 | elsif val.class == Proc |
|
268 | test_request.should_receive(key) { |fname| |
|
268 | test_request.should_receive(key) { |fname| |
|
269 | val.call(fname) |
|
269 | val.call(fname) |
|
270 | } |
|
270 | } |
|
271 | else |
|
271 | else |
|
272 | test_request.should_receive(key).with(val) |
|
272 | test_request.should_receive(key).with(val) |
|
273 | end |
|
273 | end |
|
274 | end |
|
274 | end |
|
275 |
|
275 | ||
|
276 | @engine.grade(test_request) |
|
276 | @engine.grade(test_request) |
|
277 | end |
|
277 | end |
|
278 |
|
278 | ||
|
279 | end |
|
279 | end |
|
280 |
|
280 |
@@ -1,30 +1,30 | |||||
|
1 | module GraderEngineHelperMethods |
|
1 | module GraderEngineHelperMethods |
|
2 |
|
2 | ||
|
3 | def clear_sandbox |
|
3 | def clear_sandbox |
|
4 | config = Grader::Configuration.get_instance |
|
4 | config = Grader::Configuration.get_instance |
|
5 | clear_cmd = "rm -rf #{config.test_sandbox_dir}/*" |
|
5 | clear_cmd = "rm -rf #{config.test_sandbox_dir}/*" |
|
6 | system(clear_cmd) |
|
6 | system(clear_cmd) |
|
7 | end |
|
7 | end |
|
8 |
|
8 | ||
|
9 | def init_sandbox |
|
9 | def init_sandbox |
|
10 | config = Grader::Configuration.get_instance |
|
10 | config = Grader::Configuration.get_instance |
|
11 | clear_sandbox |
|
11 | clear_sandbox |
|
12 |
- |
|
12 | + FileUtils.mkdir_p config.user_result_dir |
|
13 | cp_cmd = "cp -R #{config.test_data_dir}/ev #{config.test_sandbox_dir}" |
|
13 | cp_cmd = "cp -R #{config.test_data_dir}/ev #{config.test_sandbox_dir}" |
|
14 | system(cp_cmd) |
|
14 | system(cp_cmd) |
|
15 | end |
|
15 | end |
|
16 |
|
16 | ||
|
17 | def create_submission_from_file(id, user, problem, |
|
17 | def create_submission_from_file(id, user, problem, |
|
18 | source_fname, language=nil) |
|
18 | source_fname, language=nil) |
|
19 |
|
19 | ||
|
20 | language = stub(Language, :name => 'c', :ext => 'c') if language==nil |
|
20 | language = stub(Language, :name => 'c', :ext => 'c') if language==nil |
|
21 |
|
21 | ||
|
22 | config = Grader::Configuration.get_instance |
|
22 | config = Grader::Configuration.get_instance |
|
23 | source = File.open(config.test_data_dir + "/" + source_fname).read |
|
23 | source = File.open(config.test_data_dir + "/" + source_fname).read |
|
24 | stub(Submission, |
|
24 | stub(Submission, |
|
25 | :id => id, :user => user, :problem => problem, |
|
25 | :id => id, :user => user, :problem => problem, |
|
26 | :source => source, :language => language) |
|
26 | :source => source, :language => language) |
|
27 | end |
|
27 | end |
|
28 |
|
28 | ||
|
29 | end |
|
29 | end |
|
30 |
|
30 |
You need to be logged in to leave comments.
Login now