Description:
[grader] test_request: fixed error when input file is not found, or input file remains in problem home
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@171 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
r45:dafc790ec9b7 - - 1 file changed: 17 inserted, 2 deleted
@@ -66,25 +66,35 | |||||
|
66 | problem_name = test_request.problem_name |
|
66 | problem_name = test_request.problem_name |
|
67 | user = test_request.user |
|
67 | user = test_request.user |
|
68 | "#{@config.user_result_dir}" + |
|
68 | "#{@config.user_result_dir}" + |
|
69 | "/#{user.login}/test_request/#{problem_name}" |
|
69 | "/#{user.login}/test_request/#{problem_name}" |
|
70 | end |
|
70 | end |
|
71 |
|
71 | ||
|
72 | def copy_problem_template(template_dir,problem_home) |
|
72 | def copy_problem_template(template_dir,problem_home) |
|
73 | cmd = "cp -R #{template_dir}/* #{problem_home}" |
|
73 | cmd = "cp -R #{template_dir}/* #{problem_home}" |
|
74 | system_and_raise_when_fail(cmd,"Test Request: cannot copy problem template") |
|
74 | system_and_raise_when_fail(cmd,"Test Request: cannot copy problem template") |
|
75 | end |
|
75 | end |
|
76 |
|
76 | ||
|
77 | def link_input_file(test_request,problem_home) |
|
77 | def link_input_file(test_request,problem_home) |
|
78 | - cmd = "ln -s #{test_request.input_file_name} #{problem_home}/test_cases/1/input-1.txt" |
|
78 | + input_fname = "#{test_request.input_file_name}" |
|
|
79 | + if !File.exists?(input_fname) | ||
|
|
80 | + raise "Test Request: input file not found." | ||
|
|
81 | + end | ||
|
|
82 | + | ||
|
|
83 | + input_fname_problem_home = "#{problem_home}/test_cases/1/input-1.txt" | ||
|
|
84 | + if File.exists?(input_fname_problem_home) | ||
|
|
85 | + FileUtils.rm([input_fname_problem_home], :force => true) | ||
|
|
86 | + end | ||
|
|
87 | + | ||
|
|
88 | + cmd = "ln -s #{input_fname} #{input_fname_problem_home}" | ||
|
79 | system_and_raise_when_fail(cmd,"Test Request: cannot link input file") |
|
89 | system_and_raise_when_fail(cmd,"Test Request: cannot link input file") |
|
80 | end |
|
90 | end |
|
81 |
|
91 | ||
|
82 | def remove_data_files(problem_home) |
|
92 | def remove_data_files(problem_home) |
|
83 | if File.exists?("#{problem_home}/test_cases/1/input-1.txt") |
|
93 | if File.exists?("#{problem_home}/test_cases/1/input-1.txt") |
|
84 | cmd = "rm #{problem_home}/test_cases/1/*" |
|
94 | cmd = "rm #{problem_home}/test_cases/1/*" |
|
85 | system_and_raise_when_fail(cmd,"Test Request: cannot remove data files") |
|
95 | system_and_raise_when_fail(cmd,"Test Request: cannot remove data files") |
|
86 | end |
|
96 | end |
|
87 | end |
|
97 | end |
|
88 |
|
98 | ||
|
89 | def system_and_raise_when_fail(cmd,msg) |
|
99 | def system_and_raise_when_fail(cmd,msg) |
|
90 | if !system(cmd) |
|
100 | if !system(cmd) |
@@ -95,25 +105,30 | |||||
|
95 | end |
|
105 | end |
|
96 |
|
106 | ||
|
97 | class TestRequestReporter |
|
107 | class TestRequestReporter |
|
98 | def initialize |
|
108 | def initialize |
|
99 | @config = Grader::Configuration.get_instance |
|
109 | @config = Grader::Configuration.get_instance |
|
100 | end |
|
110 | end |
|
101 |
|
111 | ||
|
102 | def report(test_request,test_result_dir) |
|
112 | def report(test_request,test_result_dir) |
|
103 | save_result(test_request,read_result(test_result_dir)) |
|
113 | save_result(test_request,read_result(test_result_dir)) |
|
104 | end |
|
114 | end |
|
105 |
|
115 | ||
|
106 | def report_error(test_request, msg) |
|
116 | def report_error(test_request, msg) |
|
107 |
- save_result(test_request, {:running_stat => { |
|
117 | + save_result(test_request, {:running_stat => { |
|
|
118 | + :msg => "#{msg}", | ||
|
|
119 | + :running_time => nil, | ||
|
|
120 | + :exit_status => "Some error occured. Program did not run", | ||
|
|
121 | + :memory_usage => nil | ||
|
|
122 | + }}) | ||
|
108 | end |
|
123 | end |
|
109 |
|
124 | ||
|
110 | protected |
|
125 | protected |
|
111 | def read_result(test_result_dir) |
|
126 | def read_result(test_result_dir) |
|
112 | # TODO: |
|
127 | # TODO: |
|
113 | cmp_msg_fname = "#{test_result_dir}/compiler_message" |
|
128 | cmp_msg_fname = "#{test_result_dir}/compiler_message" |
|
114 | cmp_file = File.open(cmp_msg_fname) |
|
129 | cmp_file = File.open(cmp_msg_fname) |
|
115 | cmp_msg = cmp_file.read |
|
130 | cmp_msg = cmp_file.read |
|
116 | cmp_file.close |
|
131 | cmp_file.close |
|
117 |
|
132 | ||
|
118 | result_file_name = "#{test_result_dir}/1/result" |
|
133 | result_file_name = "#{test_result_dir}/1/result" |
|
119 |
|
134 |
You need to be logged in to leave comments.
Login now