Description:
[grader] small tweak on one test case
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@168 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
r44:a07593cb07c4 - - 1 file changed: 1 inserted, 1 deleted
@@ -95,193 +95,193 | |||
|
95 | 95 | :and_report => { |
|
96 | 96 | :score => 0, |
|
97 | 97 | :comment => /^FAILED:/}) |
|
98 | 98 | end |
|
99 | 99 | |
|
100 | 100 | it "should not allow malicious submission to see PROBLEM_HOME" do |
|
101 | 101 | problem_test_yesno = stub(Problem, |
|
102 | 102 | :id => 1, :name => 'test_yesno', |
|
103 | 103 | :full_score => 10) |
|
104 | 104 | grader_should(:grade => "yesno_access_problem_home.c", |
|
105 | 105 | :on => problem_test_yesno, |
|
106 | 106 | :and_report => { |
|
107 | 107 | :score => 0, |
|
108 | 108 | :comment => /^FAILED:/}) |
|
109 | 109 | end |
|
110 | 110 | |
|
111 | 111 | it "should not allow malicious submission to open files" do |
|
112 | 112 | problem_test_yesno = stub(Problem, |
|
113 | 113 | :id => 1, :name => 'test_yesno', |
|
114 | 114 | :full_score => 10) |
|
115 | 115 | grader_should(:grade => "yesno_open_file.c", |
|
116 | 116 | :on => problem_test_yesno, |
|
117 | 117 | :and_report => { |
|
118 | 118 | :score => 0, |
|
119 | 119 | :comment => /^FAILED:/}) |
|
120 | 120 | end |
|
121 | 121 | |
|
122 | 122 | def grader_should(args) |
|
123 | 123 | @user1 = stub(User, |
|
124 | 124 | :id => 1, :login => 'user1') |
|
125 | 125 | submission = |
|
126 | 126 | create_submission_from_file(1, @user1, args[:on], args[:grade]) |
|
127 | 127 | submission.should_receive(:graded_at=) |
|
128 | 128 | |
|
129 | 129 | expected_score = args[:and_report][:score] |
|
130 | 130 | expected_comment = args[:and_report][:comment] |
|
131 | 131 | if args[:and_report][:compiler_message]!=nil |
|
132 | 132 | expected_compiler_message = args[:and_report][:compiler_message] |
|
133 | 133 | else |
|
134 | 134 | expected_compiler_message = '' |
|
135 | 135 | end |
|
136 | 136 | |
|
137 | 137 | submission.should_receive(:points=).with(expected_score) |
|
138 | 138 | submission.should_receive(:grader_comment=).with(expected_comment) |
|
139 | 139 | submission.should_receive(:compiler_message=).with(expected_compiler_message) |
|
140 | 140 | submission.should_receive(:save) |
|
141 | 141 | |
|
142 | 142 | @engine.grade(submission) |
|
143 | 143 | end |
|
144 | 144 | |
|
145 | 145 | protected |
|
146 | 146 | |
|
147 | 147 | def create_normal_submission_mock_from_file(source_fname) |
|
148 | 148 | create_submission_from_file(1, @user_user1, @problem_test_normal, source_fname) |
|
149 | 149 | end |
|
150 | 150 | |
|
151 | 151 | end |
|
152 | 152 | |
|
153 | 153 | describe "A grader engine, when grading test requests" do |
|
154 | 154 | |
|
155 | 155 | include GraderEngineHelperMethods |
|
156 | 156 | |
|
157 | 157 | before(:each) do |
|
158 | 158 | @config = Grader::Configuration.get_instance |
|
159 | 159 | @engine = Grader::Engine.new(Grader::TestRequestRoomMaker.new, |
|
160 | 160 | Grader::TestRequestReporter.new) |
|
161 | 161 | init_sandbox |
|
162 | 162 | end |
|
163 | 163 | |
|
164 | 164 | it "should report error if there is no problem template" do |
|
165 | 165 | problem = stub(Problem, |
|
166 | 166 | :id => 1, :name => 'nothing') |
|
167 | 167 | grader_should(:grade => 'test1_correct.c', |
|
168 | 168 | :on => problem, |
|
169 | 169 | :with => 'in1.txt', |
|
170 | 170 | :and_report => { |
|
171 | 171 | :graded_at= => nil, |
|
172 | 172 | :compiler_message= => '', |
|
173 | 173 | :grader_comment= => '', |
|
174 | 174 | :running_stat= => /template not found/, |
|
175 | 175 | :running_time= => nil, |
|
176 | 176 | :exit_status= => nil, |
|
177 | 177 | :memory_usage= => nil, |
|
178 | 178 | :save => nil}) |
|
179 | 179 | end |
|
180 | 180 | |
|
181 | 181 | it "should run test request and produce output file" do |
|
182 | 182 | problem = stub(Problem, |
|
183 | 183 | :id => 1, :name => 'test_normal') |
|
184 | 184 | grader_should(:grade => 'test1_correct.c', |
|
185 | 185 | :on => problem, |
|
186 | 186 | :with => 'in1.txt', |
|
187 | 187 | :and_report => { |
|
188 | 188 | :graded_at= => nil, |
|
189 | 189 | :compiler_message= => '', |
|
190 | 190 | :grader_comment= => '', |
|
191 | - :running_stat= => /0.0 sec./, | |
|
191 | + :running_stat= => /0.0\d* sec./, | |
|
192 | 192 | :output_file_name= => lambda { |fname| |
|
193 | 193 | File.exists?(fname).should be_true |
|
194 | 194 | }, |
|
195 | 195 | :running_time= => nil, |
|
196 | 196 | :exit_status= => nil, |
|
197 | 197 | :memory_usage= => nil, |
|
198 | 198 | :save => nil}) |
|
199 | 199 | end |
|
200 | 200 | |
|
201 | 201 | it "should clean up problem directory after running test request" do |
|
202 | 202 | problem = stub(Problem, |
|
203 | 203 | :id => 1, :name => 'test_normal') |
|
204 | 204 | grader_should(:grade => 'test1_correct.c', |
|
205 | 205 | :on => problem, |
|
206 | 206 | :with => 'in1.txt', |
|
207 | 207 | :and_report => { |
|
208 | 208 | :graded_at= => nil, |
|
209 | 209 | :compiler_message= => '', |
|
210 | 210 | :grader_comment= => '', |
|
211 | 211 | :running_stat= => nil, |
|
212 | 212 | :output_file_name= => nil, |
|
213 | 213 | :running_time= => nil, |
|
214 | 214 | :exit_status= => nil, |
|
215 | 215 | :memory_usage= => nil, |
|
216 | 216 | :save => nil}) |
|
217 | 217 | File.exists?(@config.user_result_dir + "/test_request/test_normal/test_cases/1/input-1.txt").should be_false |
|
218 | 218 | end |
|
219 | 219 | |
|
220 | 220 | it "should compile test request with error and report compilation error" do |
|
221 | 221 | problem = stub(Problem, |
|
222 | 222 | :id => 1, :name => 'test_normal') |
|
223 | 223 | grader_should(:grade => 'test1_compile_error.c', |
|
224 | 224 | :on => problem, |
|
225 | 225 | :with => 'in1.txt', |
|
226 | 226 | :and_report => { |
|
227 | 227 | :graded_at= => nil, |
|
228 | 228 | :compiler_message= => /.+/, |
|
229 | 229 | :grader_comment= => /[Cc]ompil.*error/, |
|
230 | 230 | :running_stat= => '', |
|
231 | 231 | :save => nil}) |
|
232 | 232 | end |
|
233 | 233 | |
|
234 | 234 | it "should report exit status" do |
|
235 | 235 | problem = stub(Problem, |
|
236 | 236 | :id => 1, :name => 'test_normal') |
|
237 | 237 | grader_should(:grade => 'add_nonzero_exit_status.c', |
|
238 | 238 | :on => problem, |
|
239 | 239 | :with => 'in1.txt', |
|
240 | 240 | :and_report => { |
|
241 | 241 | :graded_at= => nil, |
|
242 | 242 | :compiler_message= => '', |
|
243 | 243 | :grader_comment= => '', |
|
244 | 244 | :running_stat= => /[Ee]xit.*status.*10.*0\.0 sec/m, |
|
245 | 245 | :output_file_name= => lambda { |fname| |
|
246 | 246 | File.exists?(fname).should be_true |
|
247 | 247 | }, |
|
248 | 248 | :running_time= => nil, |
|
249 | 249 | :exit_status= => /10/, |
|
250 | 250 | :memory_usage= => nil, |
|
251 | 251 | :save => nil}) |
|
252 | 252 | end |
|
253 | 253 | |
|
254 | 254 | it "should produce running statistics for normal submission" do |
|
255 | 255 | problem = stub(Problem, |
|
256 | 256 | :id => 1, :name => 'test_normal') |
|
257 | 257 | grader_should(:grade => 'test_run_stat.c', |
|
258 | 258 | :on => problem, |
|
259 | 259 | :with => 'in1.txt', |
|
260 | 260 | :and_report => { |
|
261 | 261 | :graded_at= => nil, |
|
262 | 262 | :compiler_message= => '', |
|
263 | 263 | :grader_comment= => '', |
|
264 | 264 | :running_stat= => nil, |
|
265 | 265 | :output_file_name= => lambda { |fname| |
|
266 | 266 | File.exists?(fname).should be_true |
|
267 | 267 | }, |
|
268 | 268 | :running_time= => lambda { |t| |
|
269 | 269 | (t>=0.14) and (t<=0.16) |
|
270 | 270 | }, |
|
271 | 271 | :exit_status= => nil, |
|
272 | 272 | :memory_usage= => lambda { |s| |
|
273 | 273 | (s>=500) and (s<=1000) |
|
274 | 274 | }, |
|
275 | 275 | :save => nil}) |
|
276 | 276 | end |
|
277 | 277 | |
|
278 | 278 | protected |
|
279 | 279 | def grader_should(args) |
|
280 | 280 | @user1 = stub(User, |
|
281 | 281 | :id => 1, :login => 'user1') |
|
282 | 282 | |
|
283 | 283 | problem = args[:on] |
|
284 | 284 | input_file = @config.test_request_input_base_dir + "/" + args[:with] |
|
285 | 285 | |
|
286 | 286 | submission = |
|
287 | 287 | create_submission_from_file(1, @user1, args[:on], args[:grade]) |
You need to be logged in to leave comments.
Login now