Description:
[grader] fixed: import_problem (error in erb calls), check_wrapper; better error handling -- will get 0 score for a particular test run that fails
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@118 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
r31:d810d6c2e99e - - 5 files changed: 28 inserted, 15 deleted
@@ -99,17 +99,17 | |||||
|
99 |
|
99 | ||
|
100 | # copy check script |
|
100 | # copy check script |
|
101 | if res = /^wrapper:(.*)$/.match(check_script) |
|
101 | if res = /^wrapper:(.*)$/.match(check_script) |
|
102 | # wrapper script |
|
102 | # wrapper script |
|
103 | check_script_fname = res[1] |
|
103 | check_script_fname = res[1] |
|
104 | script_name = File.basename(check_script_fname) |
|
104 | script_name = File.basename(check_script_fname) |
|
105 | - check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper") |
|
105 | + check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper").read |
|
106 | - check_wrapper = ERB.new(template) |
|
106 | + check_wrapper = ERB.new(check_wrapper_template) |
|
107 |
|
107 | ||
|
108 | check_file = File.open("#{problem}/script/check","w") |
|
108 | check_file = File.open("#{problem}/script/check","w") |
|
109 | - check_file.puts check_wrapper |
|
109 | + check_file.puts check_wrapper.result |
|
110 | check_file.close |
|
110 | check_file.close |
|
111 |
|
111 | ||
|
112 | File.chmod(0755,"#{problem}/script/check") |
|
112 | File.chmod(0755,"#{problem}/script/check") |
|
113 |
|
113 | ||
|
114 | system("cp #{check_script_fname} #{problem}/script/#{script_name}") |
|
114 | system("cp #{check_script_fname} #{problem}/script/#{script_name}") |
|
115 | else |
|
115 | else |
@@ -1,8 +1,13 | |||||
|
1 | #!/usr/bin/ruby |
|
1 | #!/usr/bin/ruby |
|
2 |
|
2 | ||
|
|
3 | + CORRECT_MARK = 'P' | ||
|
|
4 | + INCORRECT_MARK = '-' | ||
|
|
5 | + TIMEOUT_MARK = 'T' | ||
|
|
6 | + RUN_ERROR_MARK = 'x' | ||
|
|
7 | + | ||
|
3 | def log(str='') |
|
8 | def log(str='') |
|
4 | if ENV['TALKATIVE']!=nil |
|
9 | if ENV['TALKATIVE']!=nil |
|
5 | puts str |
|
10 | puts str |
|
6 | end |
|
11 | end |
|
7 | if ENV['GRADER_LOGGING']!=nil |
|
12 | if ENV['GRADER_LOGGING']!=nil |
|
8 | log_fname = ENV['GRADER_LOGGING'] |
|
13 | log_fname = ENV['GRADER_LOGGING'] |
@@ -11,19 +16,19 | |||||
|
11 | fp.close |
|
16 | fp.close |
|
12 | end |
|
17 | end |
|
13 | end |
|
18 | end |
|
14 |
|
19 | ||
|
15 | def char_comment(comment) |
|
20 | def char_comment(comment) |
|
16 | if comment =~ /[iI]ncorrect/ |
|
21 | if comment =~ /[iI]ncorrect/ |
|
17 | - '-' |
|
22 | + INCORRECT_MARK |
|
18 | elsif comment =~ /[Cc]orrect/ |
|
23 | elsif comment =~ /[Cc]orrect/ |
|
19 | - 'P' |
|
24 | + CORRECT_MARK |
|
20 | elsif comment =~ /[Tt]ime/ |
|
25 | elsif comment =~ /[Tt]ime/ |
|
21 | - 'T' |
|
26 | + TIMEOUT_MARK |
|
22 | else |
|
27 | else |
|
23 |
- |
|
28 | + RUN_ERROR_MARK # these are run time errors |
|
24 | end |
|
29 | end |
|
25 | end |
|
30 | end |
|
26 |
|
31 | ||
|
27 | problem_home = ENV['PROBLEM_HOME'] |
|
32 | problem_home = ENV['PROBLEM_HOME'] |
|
28 | require "#{problem_home}/script/test_dsl.rb" |
|
33 | require "#{problem_home}/script/test_dsl.rb" |
|
29 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
34 | load "#{problem_home}/test_cases/all_tests.cfg" |
@@ -43,13 +48,13 | |||||
|
43 | run_comment = '' |
|
48 | run_comment = '' |
|
44 | run_comment_short = '' |
|
49 | run_comment_short = '' |
|
45 | run.tests.each do |test_num| |
|
50 | run.tests.each do |test_num| |
|
46 | result_file_name = "#{test_num}/result" |
|
51 | result_file_name = "#{test_num}/result" |
|
47 | if not File.exists?(result_file_name) |
|
52 | if not File.exists?(result_file_name) |
|
48 | run_comment += "result file for test #{test_num} not found\n" |
|
53 | run_comment += "result file for test #{test_num} not found\n" |
|
49 |
- run_comment_short += |
|
54 | + run_comment_short += RUN_ERROR_MARK |
|
50 | log "Cannot find the file #{test_num}/result!" |
|
55 | log "Cannot find the file #{test_num}/result!" |
|
51 | else |
|
56 | else |
|
52 | result_file = File.new(result_file_name, "r") |
|
57 | result_file = File.new(result_file_name, "r") |
|
53 | result_file_lines = result_file.readlines |
|
58 | result_file_lines = result_file.readlines |
|
54 | run_score = run_score + result_file_lines[1].to_i |
|
59 | run_score = run_score + result_file_lines[1].to_i |
|
55 | run_comment += result_file_lines[0] |
|
60 | run_comment += result_file_lines[0] |
@@ -13,15 +13,15 | |||||
|
13 | end |
|
13 | end |
|
14 |
|
14 | ||
|
15 | problem_home = ENV['PROBLEM_HOME'] |
|
15 | problem_home = ENV['PROBLEM_HOME'] |
|
16 |
|
16 | ||
|
17 | def execute(command, error_message="") |
|
17 | def execute(command, error_message="") |
|
18 | if not system(command) |
|
18 | if not system(command) |
|
19 |
- |
|
19 | + msg = "ERROR: #{error_message}" |
|
20 | - puts "ERROR: #{error_message}" |
|
20 | + log msg |
|
21 | - exit(127) |
|
21 | + raise msg |
|
22 | end |
|
22 | end |
|
23 | end |
|
23 | end |
|
24 |
|
24 | ||
|
25 | # ARGV[0] --- language |
|
25 | # ARGV[0] --- language |
|
26 | # ARGV[1] --- program source file |
|
26 | # ARGV[1] --- program source file |
|
27 | # ARGV[2] --- test result directory |
|
27 | # ARGV[2] --- test result directory |
@@ -102,13 +102,17 | |||||
|
102 | end |
|
102 | end |
|
103 |
|
103 | ||
|
104 | # Doing the testing. |
|
104 | # Doing the testing. |
|
105 | (1..(problem.num_tests)).each do |test_num| |
|
105 | (1..(problem.num_tests)).each do |test_num| |
|
106 | log "Test number: #{test_num}" |
|
106 | log "Test number: #{test_num}" |
|
107 | execute("cp #{test_result_dir}/a.out #{sandbox_dir}", "Cannot copy the compiled program into #{sandbox_dir}") |
|
107 | execute("cp #{test_result_dir}/a.out #{sandbox_dir}", "Cannot copy the compiled program into #{sandbox_dir}") |
|
108 | - execute("#{problem_home}/script/run #{language} #{test_num}", "Error occured during execution of the run script") |
|
108 | + begin |
|
|
109 | + execute("#{problem_home}/script/run #{language} #{test_num}", "Error occured during execution of the run script") | ||
|
|
110 | + rescue | ||
|
|
111 | + # do nothing | ||
|
|
112 | + end | ||
|
109 | execute("mkdir #{test_result_dir}/#{test_num}", "Cannot create directory #{test_result_dir}/#{test_num}") |
|
113 | execute("mkdir #{test_result_dir}/#{test_num}", "Cannot create directory #{test_result_dir}/#{test_num}") |
|
110 | execute("mv #{sandbox_dir}/result #{test_result_dir}/#{test_num}", "Cannot copy the result file into #{test_result_dir}/#{test_num}") |
|
114 | execute("mv #{sandbox_dir}/result #{test_result_dir}/#{test_num}", "Cannot copy the result file into #{test_result_dir}/#{test_num}") |
|
111 | execute("mv #{sandbox_dir}/comment #{test_result_dir}/#{test_num}", "Cannot copy the comment file into #{test_result_dir}/#{test_num}") |
|
115 | execute("mv #{sandbox_dir}/comment #{test_result_dir}/#{test_num}", "Cannot copy the comment file into #{test_result_dir}/#{test_num}") |
|
112 | execute("mv #{sandbox_dir}/output.txt #{test_result_dir}/#{test_num}", "Cannot copy the output file into #{test_result_dir}/#{test_num}") |
|
116 | execute("mv #{sandbox_dir}/output.txt #{test_result_dir}/#{test_num}", "Cannot copy the output file into #{test_result_dir}/#{test_num}") |
|
113 | execute("rm -Rf #{sandbox_dir}/*", "Cannot clear #{sandbox_dir}") |
|
117 | execute("rm -Rf #{sandbox_dir}/*", "Cannot clear #{sandbox_dir}") |
|
114 | end |
|
118 | end |
@@ -130,12 +130,13 | |||||
|
130 | #puts "There was no runtime error. Proceed to checking the output." |
|
130 | #puts "There was no runtime error. Proceed to checking the output." |
|
131 | check_command = "#{problem_home}/script/check #{language} #{test_num}" |
|
131 | check_command = "#{problem_home}/script/check #{language} #{test_num}" |
|
132 | log "Checking the output..." |
|
132 | log "Checking the output..." |
|
133 | log check_command |
|
133 | log check_command |
|
134 | if not system(check_command) |
|
134 | if not system(check_command) |
|
135 | log "Problem with check script" |
|
135 | log "Problem with check script" |
|
|
136 | + report.call("Incorrect",0,"Check script error.\n") | ||
|
136 | exit(127) |
|
137 | exit(127) |
|
137 | end |
|
138 | end |
|
138 |
|
139 | ||
|
139 | check_file = File.new("check_result", "r") |
|
140 | check_file = File.new("check_result", "r") |
|
140 | check_file_lines = check_file.readlines |
|
141 | check_file_lines = check_file.readlines |
|
141 |
|
142 |
@@ -31,15 +31,18 | |||||
|
31 | output_file_name = "output.txt" |
|
31 | output_file_name = "output.txt" |
|
32 | end |
|
32 | end |
|
33 |
|
33 | ||
|
34 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
34 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
35 | problem = Problem.get_instance |
|
35 | problem = Problem.get_instance |
|
36 |
|
36 | ||
|
37 |
- answer_file_name = |
|
37 | + answer_file_name = "#{problem_home}/test_cases/#{test_num}/answer-#{test_num}.txt" |
|
38 |
- input_file_name = |
|
38 | + input_file_name = "#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt" |
|
39 |
|
39 | ||
|
40 |
- score = |
|
40 | + score = problem.get_score(test_num) |
|
41 |
|
41 | ||
|
42 | cmd = "#{problem_home}/script/#{REAL_CHECK_SCRIPT} " + |
|
42 | cmd = "#{problem_home}/script/#{REAL_CHECK_SCRIPT} " + |
|
43 | "#{language} #{test_num} #{input_file_name} #{output_file_name} " + |
|
43 | "#{language} #{test_num} #{input_file_name} #{output_file_name} " + |
|
44 | "#{answer_file_name} #{score} > check_result" |
|
44 | "#{answer_file_name} #{score} > check_result" |
|
45 |
|
45 | ||
|
|
46 | + #puts "wrapper-CMD: #{cmd}" | ||
|
|
47 | + | ||
|
|
48 | + system(cmd) |
You need to be logged in to leave comments.
Login now