Description:
added quick hack on running scripts, and compiler calls
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r111:06c23d391544 - - 4 files changed: 13 inserted, 11 deleted
@@ -108,25 +108,25 | |||||
|
108 | if @config.talkative |
|
108 | if @config.talkative |
|
109 | puts str |
|
109 | puts str |
|
110 | end |
|
110 | end |
|
111 | end |
|
111 | end |
|
112 |
|
112 | ||
|
113 | def call_judge(problem_home,language,grading_dir,fname) |
|
113 | def call_judge(problem_home,language,grading_dir,fname) |
|
114 | ENV['PROBLEM_HOME'] = problem_home |
|
114 | ENV['PROBLEM_HOME'] = problem_home |
|
115 |
|
115 | ||
|
116 | talk grading_dir |
|
116 | talk grading_dir |
|
117 | Dir.chdir grading_dir |
|
117 | Dir.chdir grading_dir |
|
118 | cmd = "#{problem_home}/script/judge #{language} #{fname}" |
|
118 | cmd = "#{problem_home}/script/judge #{language} #{fname}" |
|
119 | talk "CMD: #{cmd}" |
|
119 | talk "CMD: #{cmd}" |
|
120 | - system(cmd) |
|
120 | + system("ruby " + cmd) |
|
121 | end |
|
121 | end |
|
122 |
|
122 | ||
|
123 | def get_std_script_dir |
|
123 | def get_std_script_dir |
|
124 | GRADER_ROOT + '/std-script' |
|
124 | GRADER_ROOT + '/std-script' |
|
125 | end |
|
125 | end |
|
126 |
|
126 | ||
|
127 | def copy_script(problem_home) |
|
127 | def copy_script(problem_home) |
|
128 | script_dir = "#{problem_home}/script" |
|
128 | script_dir = "#{problem_home}/script" |
|
129 | std_script_dir = get_std_script_dir |
|
129 | std_script_dir = get_std_script_dir |
|
130 |
|
130 | ||
|
131 | raise "std-script directory not found" if !FileTest.exist?(std_script_dir) |
|
131 | raise "std-script directory not found" if !FileTest.exist?(std_script_dir) |
|
132 |
|
132 |
@@ -14,27 +14,27 | |||||
|
14 | def talk(msg) |
|
14 | def talk(msg) |
|
15 | if ENV['TALKATIVE']!=nil |
|
15 | if ENV['TALKATIVE']!=nil |
|
16 | puts str |
|
16 | puts str |
|
17 | end |
|
17 | end |
|
18 | if ENV['GRADER_LOGGING']!=nil |
|
18 | if ENV['GRADER_LOGGING']!=nil |
|
19 | log_fname = ENV['GRADER_LOGGING'] |
|
19 | log_fname = ENV['GRADER_LOGGING'] |
|
20 | fp = File.open(log_fname,"a") |
|
20 | fp = File.open(log_fname,"a") |
|
21 | fp.puts("run: #{Time.new.strftime("%H:%M")} #{str}") |
|
21 | fp.puts("run: #{Time.new.strftime("%H:%M")} #{str}") |
|
22 | fp.close |
|
22 | fp.close |
|
23 | end |
|
23 | end |
|
24 | end |
|
24 | end |
|
25 |
|
25 | ||
|
26 |
- C_COMPILER = " |
|
26 | + C_COMPILER = "gcc" |
|
27 |
- CPLUSPLUS_COMPILER = " |
|
27 | + CPLUSPLUS_COMPILER = "g++" |
|
28 |
- PASCAL_COMPILER = " |
|
28 | + PASCAL_COMPILER = "fpc" |
|
29 |
|
29 | ||
|
30 | C_OPTIONS = "-O2 -s -static -std=c99 -DCONTEST -lm -Wall" |
|
30 | C_OPTIONS = "-O2 -s -static -std=c99 -DCONTEST -lm -Wall" |
|
31 | CPLUSPLUS_OPTIONS = "-O2 -s -static -DCONTEST -lm -Wall" |
|
31 | CPLUSPLUS_OPTIONS = "-O2 -s -static -DCONTEST -lm -Wall" |
|
32 | PASCAL_OPTIONS = "-O1 -XS -dCONTEST" |
|
32 | PASCAL_OPTIONS = "-O1 -XS -dCONTEST" |
|
33 |
|
33 | ||
|
34 | # Check for the correct number of arguments. Otherwise, print usage. |
|
34 | # Check for the correct number of arguments. Otherwise, print usage. |
|
35 | if ARGV.length == 0 or ARGV.length > 4 |
|
35 | if ARGV.length == 0 or ARGV.length > 4 |
|
36 | puts "Usage: compile <language> [<source-file>] [<output-file>] [<message-file>]" |
|
36 | puts "Usage: compile <language> [<source-file>] [<output-file>] [<message-file>]" |
|
37 | puts |
|
37 | puts |
|
38 | puts "<source-file> is defaulted to \"source\"." |
|
38 | puts "<source-file> is defaulted to \"source\"." |
|
39 | puts "<output-file> is defaulted to \"a.out\"." |
|
39 | puts "<output-file> is defaulted to \"a.out\"." |
|
40 | puts "<message-file> is defaulted to \"compiler_message\"." |
|
40 | puts "<message-file> is defaulted to \"compiler_message\"." |
@@ -89,27 +89,29 | |||||
|
89 | # Compile |
|
89 | # Compile |
|
90 | log |
|
90 | log |
|
91 | log "Compiling..." |
|
91 | log "Compiling..." |
|
92 | call_and_log("Cannot copy the source file to #{sandbox_dir}") { |
|
92 | call_and_log("Cannot copy the source file to #{sandbox_dir}") { |
|
93 | FileUtils.cp(source_file, sandbox_dir) |
|
93 | FileUtils.cp(source_file, sandbox_dir) |
|
94 | } |
|
94 | } |
|
95 | begin |
|
95 | begin |
|
96 | Dir.chdir sandbox_dir |
|
96 | Dir.chdir sandbox_dir |
|
97 | rescue |
|
97 | rescue |
|
98 | log "ERROR: Cannot change directory to #{sandbox_dir}." |
|
98 | log "ERROR: Cannot change directory to #{sandbox_dir}." |
|
99 | exit(127) |
|
99 | exit(127) |
|
100 | end |
|
100 | end |
|
101 | - execute("#{problem_home}/script/compile #{language} #{source_file}", "Compilation error!") |
|
101 | + execute("ruby #{problem_home}/script/compile #{language} #{source_file}", "Compilation error!") |
|
102 |
- |
|
102 | + open("compiler_message") do |f| |
|
103 |
- compile_message |
|
103 | + compile_message = f.read |
|
|
104 | + compile_message.strip! | ||
|
|
105 | + end | ||
|
104 | call_and_log("Cannot move the compiler message to #{test_result_dir}.") { |
|
106 | call_and_log("Cannot move the compiler message to #{test_result_dir}.") { |
|
105 | FileUtils.mv("compiler_message", test_result_dir) |
|
107 | FileUtils.mv("compiler_message", test_result_dir) |
|
106 | } |
|
108 | } |
|
107 | if !FileTest.exist?("a.out") |
|
109 | if !FileTest.exist?("a.out") |
|
108 | log "Cannot compile the source code. See message in #{test_result_dir}/compile_message" |
|
110 | log "Cannot compile the source code. See message in #{test_result_dir}/compile_message" |
|
109 | exit(127) |
|
111 | exit(127) |
|
110 | else |
|
112 | else |
|
111 | call_and_log("Cannot move the compiled program to #{test_result_dir}") { |
|
113 | call_and_log("Cannot move the compiled program to #{test_result_dir}") { |
|
112 | FileUtils.mv("a.out",test_result_dir) |
|
114 | FileUtils.mv("a.out",test_result_dir) |
|
113 | } |
|
115 | } |
|
114 | FileUtils.rm_rf("#{sandbox_dir}/.") |
|
116 | FileUtils.rm_rf("#{sandbox_dir}/.") |
|
115 | end |
|
117 | end |
@@ -125,25 +127,25 | |||||
|
125 |
|
127 | ||
|
126 | # Doing the testing. |
|
128 | # Doing the testing. |
|
127 | (1..(problem.num_tests)).each do |test_num| |
|
129 | (1..(problem.num_tests)).each do |test_num| |
|
128 |
|
130 | ||
|
129 | $stdout.print "[#{test_num}]" |
|
131 | $stdout.print "[#{test_num}]" |
|
130 | $stdout.flush |
|
132 | $stdout.flush |
|
131 |
|
133 | ||
|
132 | log "Test number: #{test_num}" |
|
134 | log "Test number: #{test_num}" |
|
133 | call_and_log("Cannot copy the compiled program into #{sandbox_dir}") { |
|
135 | call_and_log("Cannot copy the compiled program into #{sandbox_dir}") { |
|
134 | FileUtils.cp("#{test_result_dir}/a.out", sandbox_dir) |
|
136 | FileUtils.cp("#{test_result_dir}/a.out", sandbox_dir) |
|
135 | } |
|
137 | } |
|
136 | begin |
|
138 | begin |
|
137 | - execute("#{problem_home}/script/run #{language} #{test_num}", "Error occured during execution of the run script") |
|
139 | + execute("ruby #{problem_home}/script/run #{language} #{test_num}", "Error occured during execution of the run script") |
|
138 | rescue |
|
140 | rescue |
|
139 | # do nothing |
|
141 | # do nothing |
|
140 | end |
|
142 | end |
|
141 | call_and_log("Cannot create directory #{test_result_dir}/#{test_num}") { |
|
143 | call_and_log("Cannot create directory #{test_result_dir}/#{test_num}") { |
|
142 | FileUtils.mkdir "#{test_result_dir}/#{test_num}" |
|
144 | FileUtils.mkdir "#{test_result_dir}/#{test_num}" |
|
143 | } |
|
145 | } |
|
144 | call_and_log("Cannot copy the result file into #{test_result_dir}/#{test_num}") { |
|
146 | call_and_log("Cannot copy the result file into #{test_result_dir}/#{test_num}") { |
|
145 | FileUtils.mv "#{sandbox_dir}/result", "#{test_result_dir}/#{test_num}" |
|
147 | FileUtils.mv "#{sandbox_dir}/result", "#{test_result_dir}/#{test_num}" |
|
146 | } |
|
148 | } |
|
147 | call_and_log("Cannot copy the comment file into #{test_result_dir}/#{test_num}") { |
|
149 | call_and_log("Cannot copy the comment file into #{test_result_dir}/#{test_num}") { |
|
148 | FileUtils.mv "#{sandbox_dir}/comment", "#{test_result_dir}/#{test_num}" |
|
150 | FileUtils.mv "#{sandbox_dir}/comment", "#{test_result_dir}/#{test_num}" |
|
149 | } |
|
151 | } |
@@ -157,16 +159,16 | |||||
|
157 |
|
159 | ||
|
158 | $stdout.print "[done]\n" |
|
160 | $stdout.print "[done]\n" |
|
159 |
|
161 | ||
|
160 | # Grade |
|
162 | # Grade |
|
161 | log |
|
163 | log |
|
162 | log "Grading..." |
|
164 | log "Grading..." |
|
163 | begin |
|
165 | begin |
|
164 | Dir.chdir test_result_dir |
|
166 | Dir.chdir test_result_dir |
|
165 | rescue |
|
167 | rescue |
|
166 | log "ERROR: Cannot change directory to #{test_result_dir}." |
|
168 | log "ERROR: Cannot change directory to #{test_result_dir}." |
|
167 | exit(127) |
|
169 | exit(127) |
|
168 | end |
|
170 | end |
|
169 | - execute("#{problem_home}/script/grade", "An error occured during grading!") |
|
171 | + execute("ruby #{problem_home}/script/grade", "An error occured during grading!") |
|
170 |
|
172 | ||
|
171 | log |
|
173 | log |
|
172 | log "All done!" |
|
174 | log "All done!" |
@@ -64,25 +64,25 | |||||
|
64 |
|
64 | ||
|
65 | input_file_name = "#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt" |
|
65 | input_file_name = "#{problem_home}/test_cases/#{test_num}/input-#{test_num}.txt" |
|
66 |
|
66 | ||
|
67 | ##################################### |
|
67 | ##################################### |
|
68 |
|
68 | ||
|
69 | time_limit = problem.get_time_limit test_num |
|
69 | time_limit = problem.get_time_limit test_num |
|
70 | mem_limit = problem.get_mem_limit(test_num) * 1024 |
|
70 | mem_limit = problem.get_mem_limit(test_num) * 1024 |
|
71 |
|
71 | ||
|
72 | # Copy the input file. |
|
72 | # Copy the input file. |
|
73 | #`cp #{problem_home}/test_cases/#{test_num}/#{input_file_name} .` |
|
73 | #`cp #{problem_home}/test_cases/#{test_num}/#{input_file_name} .` |
|
74 |
|
74 | ||
|
75 | # check if box is there, if not, compile it! |
|
75 | # check if box is there, if not, compile it! |
|
76 | - if !File.exists?("#{problem_home}/script/box") |
|
76 | + if !File.exists?("#{problem_home}/script/box") and !File.exists?("#{problem_home}/script/box.exe") |
|
77 | log "WARNING: Compiling box: to increase efficiency, it should be compile manually" |
|
77 | log "WARNING: Compiling box: to increase efficiency, it should be compile manually" |
|
78 | compile_box("#{problem_home}/script/box.cc", |
|
78 | compile_box("#{problem_home}/script/box.cc", |
|
79 | "#{problem_home}/script/box") |
|
79 | "#{problem_home}/script/box") |
|
80 | end |
|
80 | end |
|
81 |
|
81 | ||
|
82 | # Hide PROBLEM_HOME |
|
82 | # Hide PROBLEM_HOME |
|
83 | ENV['PROBLEM_HOME'] = nil |
|
83 | ENV['PROBLEM_HOME'] = nil |
|
84 |
|
84 | ||
|
85 | # Run the program. |
|
85 | # Run the program. |
|
86 | #run_command = "/usr/bin/time -f \"#{time_output_format}\" 2>run_result #{problem_home}/script/box_new -a 2 -f -t #{time_limit} -m #{mem_limit} -i #{input_file_name} -o output.txt #{program_name}" |
|
86 | #run_command = "/usr/bin/time -f \"#{time_output_format}\" 2>run_result #{problem_home}/script/box_new -a 2 -f -t #{time_limit} -m #{mem_limit} -i #{input_file_name} -o output.txt #{program_name}" |
|
87 | run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit} -m #{mem_limit} -i #{input_file_name} -o output.txt #{program_name} 2>run_result" |
|
87 | run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit} -m #{mem_limit} -i #{input_file_name} -o output.txt #{program_name} 2>run_result" |
|
88 | log "Running test #{test_num}..." |
|
88 | log "Running test #{test_num}..." |
@@ -136,22 +136,22 | |||||
|
136 | end |
|
136 | end |
|
137 |
|
137 | ||
|
138 | if running_time[:user].to_f + running_time[:sys].to_f > time_limit |
|
138 | if running_time[:user].to_f + running_time[:sys].to_f > time_limit |
|
139 | log "Time limit exceeded." |
|
139 | log "Time limit exceeded." |
|
140 | report.call("Time limit exceeded", 0, "No comment.\n") |
|
140 | report.call("Time limit exceeded", 0, "No comment.\n") |
|
141 | end |
|
141 | end |
|
142 |
|
142 | ||
|
143 | # Run 'check' to evaluate the output. |
|
143 | # Run 'check' to evaluate the output. |
|
144 | #puts "There was no runtime error. Proceed to checking the output." |
|
144 | #puts "There was no runtime error. Proceed to checking the output." |
|
145 | check_command = "#{problem_home}/script/check #{language} #{test_num}" |
|
145 | check_command = "#{problem_home}/script/check #{language} #{test_num}" |
|
146 | log "Checking the output..." |
|
146 | log "Checking the output..." |
|
147 | log check_command |
|
147 | log check_command |
|
148 | - if not system(check_command) |
|
148 | + if not system("ruby " + check_command) |
|
149 | log "Problem with check script" |
|
149 | log "Problem with check script" |
|
150 | report.call("Incorrect",0,"Check script error.\n") |
|
150 | report.call("Incorrect",0,"Check script error.\n") |
|
151 | exit(127) |
|
151 | exit(127) |
|
152 | end |
|
152 | end |
|
153 |
|
153 | ||
|
154 | check_file = File.new("check_result", "r") |
|
154 | check_file = File.new("check_result", "r") |
|
155 | check_file_lines = check_file.readlines |
|
155 | check_file_lines = check_file.readlines |
|
156 |
|
156 | ||
|
157 | report.call(check_file_lines[0], check_file_lines[1], "No comment.\n") |
|
157 | report.call(check_file_lines[0], check_file_lines[1], "No comment.\n") |
You need to be logged in to leave comments.
Login now