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