Description:
Merge branch 'master' of gitorious.org:cafe-grader/cafe-grader-judge-scripts into win-local
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r113:c3fb576034e2 - - 1 file changed: 4 inserted, 1 deleted
@@ -113,97 +113,100 | |||||
|
113 | input_fname_problem_home = "#{problem_home}/test_cases/1/input-1.txt" |
|
113 | input_fname_problem_home = "#{problem_home}/test_cases/1/input-1.txt" |
|
114 | if File.exists?(input_fname_problem_home) |
|
114 | if File.exists?(input_fname_problem_home) |
|
115 | FileUtils.rm([input_fname_problem_home], :force => true) |
|
115 | FileUtils.rm([input_fname_problem_home], :force => true) |
|
116 | end |
|
116 | end |
|
117 |
|
117 | ||
|
118 | Grader::link_or_copy("#{input_fname}", "#{input_fname_problem_home}") |
|
118 | Grader::link_or_copy("#{input_fname}", "#{input_fname_problem_home}") |
|
119 | end |
|
119 | end |
|
120 |
|
120 | ||
|
121 | def remove_data_files(problem_home) |
|
121 | def remove_data_files(problem_home) |
|
122 | if File.exists?("#{problem_home}/test_cases/1/input-1.txt") |
|
122 | if File.exists?("#{problem_home}/test_cases/1/input-1.txt") |
|
123 | Grader::call_and_log("Test Request: cannot remove data files") { |
|
123 | Grader::call_and_log("Test Request: cannot remove data files") { |
|
124 | FileUtils.rm Dir.glob("#{problem_home}/test_cases/1/*") |
|
124 | FileUtils.rm Dir.glob("#{problem_home}/test_cases/1/*") |
|
125 | } |
|
125 | } |
|
126 | end |
|
126 | end |
|
127 | end |
|
127 | end |
|
128 |
|
128 | ||
|
129 | end |
|
129 | end |
|
130 |
|
130 | ||
|
131 | class TestRequestReporter |
|
131 | class TestRequestReporter |
|
132 | def initialize |
|
132 | def initialize |
|
133 | @config = Grader::Configuration.get_instance |
|
133 | @config = Grader::Configuration.get_instance |
|
134 | end |
|
134 | end |
|
135 |
|
135 | ||
|
136 | def report(test_request,test_result_dir) |
|
136 | def report(test_request,test_result_dir) |
|
137 | save_result(test_request,read_result(test_result_dir)) |
|
137 | save_result(test_request,read_result(test_result_dir)) |
|
138 | end |
|
138 | end |
|
139 |
|
139 | ||
|
140 | def report_error(test_request, msg) |
|
140 | def report_error(test_request, msg) |
|
141 | save_result(test_request, {:running_stat => { |
|
141 | save_result(test_request, {:running_stat => { |
|
142 | :msg => "#{msg}", |
|
142 | :msg => "#{msg}", |
|
143 | :running_time => nil, |
|
143 | :running_time => nil, |
|
144 | :exit_status => "Some error occured. Program did not run", |
|
144 | :exit_status => "Some error occured. Program did not run", |
|
145 | :memory_usage => nil |
|
145 | :memory_usage => nil |
|
146 | }}) |
|
146 | }}) |
|
147 | end |
|
147 | end |
|
148 |
|
148 | ||
|
149 | protected |
|
149 | protected |
|
150 | def read_result(test_result_dir) |
|
150 | def read_result(test_result_dir) |
|
151 | # TODO: |
|
151 | # TODO: |
|
152 | cmp_msg_fname = "#{test_result_dir}/compiler_message" |
|
152 | cmp_msg_fname = "#{test_result_dir}/compiler_message" |
|
153 | cmp_file = File.open(cmp_msg_fname) |
|
153 | cmp_file = File.open(cmp_msg_fname) |
|
154 | cmp_msg = cmp_file.read |
|
154 | cmp_msg = cmp_file.read |
|
155 | cmp_file.close |
|
155 | cmp_file.close |
|
156 |
|
156 | ||
|
157 | result_file_name = "#{test_result_dir}/1/result" |
|
157 | result_file_name = "#{test_result_dir}/1/result" |
|
158 |
|
158 | ||
|
159 | if File.exists?(result_file_name) |
|
159 | if File.exists?(result_file_name) |
|
160 | output_file_name = "#{test_result_dir}/1/output.txt" |
|
160 | output_file_name = "#{test_result_dir}/1/output.txt" |
|
161 | - results = File.open("#{test_result_dir}/1/result").readlines |
|
161 | + results = [] |
|
|
162 | + File.open("#{test_result_dir}/1/result") do |f| | ||
|
|
163 | + results = f.readlines | ||
|
|
164 | + end | ||
|
162 | stat = extract_running_stat(results) |
|
165 | stat = extract_running_stat(results) |
|
163 |
|
166 | ||
|
164 | return { |
|
167 | return { |
|
165 | :output_file_name => output_file_name, |
|
168 | :output_file_name => output_file_name, |
|
166 | :running_stat => stat, |
|
169 | :running_stat => stat, |
|
167 | :comment => "", |
|
170 | :comment => "", |
|
168 | :cmp_msg => cmp_msg} |
|
171 | :cmp_msg => cmp_msg} |
|
169 | else |
|
172 | else |
|
170 | return { |
|
173 | return { |
|
171 | :running_stat => nil, |
|
174 | :running_stat => nil, |
|
172 | :comment => "Compilation error", |
|
175 | :comment => "Compilation error", |
|
173 | :cmp_msg => cmp_msg} |
|
176 | :cmp_msg => cmp_msg} |
|
174 | end |
|
177 | end |
|
175 | end |
|
178 | end |
|
176 |
|
179 | ||
|
177 | def extract_running_stat(results) |
|
180 | def extract_running_stat(results) |
|
178 | running_stat_line = results[-1] |
|
181 | running_stat_line = results[-1] |
|
179 |
|
182 | ||
|
180 | # extract exit status line |
|
183 | # extract exit status line |
|
181 | run_stat = "" |
|
184 | run_stat = "" |
|
182 | if !(/[Cc]orrect/.match(results[0])) |
|
185 | if !(/[Cc]orrect/.match(results[0])) |
|
183 | run_stat = results[0].chomp |
|
186 | run_stat = results[0].chomp |
|
184 | else |
|
187 | else |
|
185 | run_stat = 'Program exited normally' |
|
188 | run_stat = 'Program exited normally' |
|
186 | end |
|
189 | end |
|
187 |
|
190 | ||
|
188 | # extract running time |
|
191 | # extract running time |
|
189 | if res = /r(.*)u(.*)s/.match(running_stat_line) |
|
192 | if res = /r(.*)u(.*)s/.match(running_stat_line) |
|
190 | seconds = (res[1].to_f + res[2].to_f) |
|
193 | seconds = (res[1].to_f + res[2].to_f) |
|
191 | time_stat = "Time used: #{seconds} sec." |
|
194 | time_stat = "Time used: #{seconds} sec." |
|
192 | else |
|
195 | else |
|
193 | seconds = nil |
|
196 | seconds = nil |
|
194 | time_stat = "Time used: n/a sec." |
|
197 | time_stat = "Time used: n/a sec." |
|
195 | end |
|
198 | end |
|
196 |
|
199 | ||
|
197 | # extract memory usage |
|
200 | # extract memory usage |
|
198 | if res = /s(.*)m/.match(running_stat_line) |
|
201 | if res = /s(.*)m/.match(running_stat_line) |
|
199 | memory_used = res[1].to_i |
|
202 | memory_used = res[1].to_i |
|
200 | else |
|
203 | else |
|
201 | memory_used = -1 |
|
204 | memory_used = -1 |
|
202 | end |
|
205 | end |
|
203 |
|
206 | ||
|
204 | return { |
|
207 | return { |
|
205 | :msg => "#{run_stat}\n#{time_stat}", |
|
208 | :msg => "#{run_stat}\n#{time_stat}", |
|
206 | :running_time => seconds, |
|
209 | :running_time => seconds, |
|
207 | :exit_status => run_stat, |
|
210 | :exit_status => run_stat, |
|
208 | :memory_usage => memory_used |
|
211 | :memory_usage => memory_used |
|
209 | } |
|
212 | } |
You need to be logged in to leave comments.
Login now